|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +# Prevent overlapping releases from racing each other. |
| 9 | +concurrency: |
| 10 | + group: release |
| 11 | + cancel-in-progress: false |
| 12 | + |
| 13 | +env: |
| 14 | + REGISTRY: ghcr.io |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: write # create tags, releases, push changelog commit |
| 21 | + issues: write # comment on released issues |
| 22 | + pull-requests: write # comment on released PRs |
| 23 | + packages: write # push the container image to GHCR |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + persist-credentials: true |
| 30 | + |
| 31 | + - name: Setup Node |
| 32 | + uses: actions/setup-node@v4 |
| 33 | + with: |
| 34 | + node-version: 22 |
| 35 | + cache: npm |
| 36 | + |
| 37 | + - name: Install dependencies |
| 38 | + run: npm ci |
| 39 | + |
| 40 | + # Determines the next version from conventional commits, updates the |
| 41 | + # changelog + package.json, creates the git tag and GitHub release, and |
| 42 | + # exports the version via @semantic-release/exec -> $GITHUB_OUTPUT. |
| 43 | + - name: Semantic release |
| 44 | + id: semrel |
| 45 | + run: npx semantic-release |
| 46 | + env: |
| 47 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + |
| 49 | + # Everything below only runs when a new version was actually published. |
| 50 | + - name: Compute image name & tags |
| 51 | + if: steps.semrel.outputs.version != '' |
| 52 | + run: | |
| 53 | + echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV" |
| 54 | + VER='${{ steps.semrel.outputs.version }}' |
| 55 | + { |
| 56 | + echo "TAG_VERSION=$VER" |
| 57 | + echo "TAG_MAJOR_MINOR=${VER%.*}" |
| 58 | + } >> "$GITHUB_ENV" |
| 59 | +
|
| 60 | + - name: Set up Docker Buildx |
| 61 | + if: steps.semrel.outputs.version != '' |
| 62 | + uses: docker/setup-buildx-action@v3 |
| 63 | + |
| 64 | + - name: Log in to GHCR |
| 65 | + if: steps.semrel.outputs.version != '' |
| 66 | + uses: docker/login-action@v3 |
| 67 | + with: |
| 68 | + registry: ${{ env.REGISTRY }} |
| 69 | + username: ${{ github.actor }} |
| 70 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + |
| 72 | + - name: Build & push release image |
| 73 | + if: steps.semrel.outputs.version != '' |
| 74 | + uses: docker/build-push-action@v6 |
| 75 | + with: |
| 76 | + context: . |
| 77 | + push: true |
| 78 | + tags: | |
| 79 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_VERSION }} |
| 80 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_MAJOR_MINOR }} |
| 81 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest |
| 82 | + labels: | |
| 83 | + org.opencontainers.image.version=${{ env.TAG_VERSION }} |
| 84 | + org.opencontainers.image.revision=${{ github.sha }} |
| 85 | + org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} |
| 86 | + cache-from: type=gha |
| 87 | + cache-to: type=gha,mode=max |
0 commit comments