|
| 1 | +# Release workflow for Library Management System |
| 2 | +# Creates releases and publishes Docker images when tags are pushed |
| 3 | + |
| 4 | +name: Release |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - "v*" |
| 10 | + |
| 11 | +jobs: |
| 12 | + release: |
| 13 | + name: Create Release |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v5 |
| 24 | + with: |
| 25 | + python-version: "3.11" |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: | |
| 29 | + python -m pip install --upgrade pip |
| 30 | + pip install -r requirements.txt |
| 31 | +
|
| 32 | + - name: Run tests |
| 33 | + run: pytest -v |
| 34 | + |
| 35 | + - name: Extract version from tag |
| 36 | + id: get_version |
| 37 | + run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 38 | + |
| 39 | + - name: Create GitHub Release |
| 40 | + uses: softprops/action-gh-release@v1 |
| 41 | + with: |
| 42 | + generate_release_notes: true |
| 43 | + body: | |
| 44 | + ## Library Management System v${{ steps.get_version.outputs.VERSION }} |
| 45 | +
|
| 46 | + ### Installation |
| 47 | +
|
| 48 | + **Using pip:** |
| 49 | + ```bash |
| 50 | + pip install -r requirements.txt |
| 51 | + ``` |
| 52 | +
|
| 53 | + **Using Docker:** |
| 54 | + ```bash |
| 55 | + docker pull ghcr.io/${{ github.repository }}:${{ steps.get_version.outputs.VERSION }} |
| 56 | + docker run -p 8000:8000 ghcr.io/${{ github.repository }}:${{ steps.get_version.outputs.VERSION }} |
| 57 | + ``` |
| 58 | +
|
| 59 | + See [CHANGELOG.md](CHANGELOG.md) for detailed changes. |
| 60 | +
|
| 61 | + docker-publish: |
| 62 | + name: Publish Docker Image |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: release |
| 65 | + permissions: |
| 66 | + contents: read |
| 67 | + packages: write |
| 68 | + |
| 69 | + steps: |
| 70 | + - name: Checkout code |
| 71 | + uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Set up Docker Buildx |
| 74 | + uses: docker/setup-buildx-action@v3 |
| 75 | + |
| 76 | + - name: Log in to GitHub Container Registry |
| 77 | + uses: docker/login-action@v3 |
| 78 | + with: |
| 79 | + registry: ghcr.io |
| 80 | + username: ${{ github.actor }} |
| 81 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + |
| 83 | + - name: Extract metadata |
| 84 | + id: meta |
| 85 | + uses: docker/metadata-action@v5 |
| 86 | + with: |
| 87 | + images: ghcr.io/${{ github.repository }} |
| 88 | + tags: | |
| 89 | + type=semver,pattern={{version}} |
| 90 | + type=semver,pattern={{major}}.{{minor}} |
| 91 | + type=semver,pattern={{major}} |
| 92 | + type=raw,value=latest |
| 93 | +
|
| 94 | + - name: Build and push Docker image |
| 95 | + uses: docker/build-push-action@v5 |
| 96 | + with: |
| 97 | + context: . |
| 98 | + push: true |
| 99 | + tags: ${{ steps.meta.outputs.tags }} |
| 100 | + labels: ${{ steps.meta.outputs.labels }} |
| 101 | + cache-from: type=gha |
| 102 | + cache-to: type=gha,mode=max |
0 commit comments