|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + issues: write |
| 12 | + pull-requests: write |
| 13 | + packages: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + name: Semantic Release |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + new_release_published: ${{ steps.semantic.outputs.new_release_published }} |
| 21 | + new_release_version: ${{ steps.semantic.outputs.new_release_version }} |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + persist-credentials: false |
| 28 | + |
| 29 | + - name: Setup Node.js |
| 30 | + uses: actions/setup-node@v4 |
| 31 | + with: |
| 32 | + node-version: 20 |
| 33 | + |
| 34 | + - name: Install dependencies |
| 35 | + run: | |
| 36 | + npm install -g semantic-release@latest |
| 37 | + npm install -g @semantic-release/git |
| 38 | + npm install -g @semantic-release/changelog |
| 39 | + npm install -g @semantic-release/github |
| 40 | + npm install -g @semantic-release/npm |
| 41 | +
|
| 42 | + - name: Semantic Release |
| 43 | + id: semantic |
| 44 | + env: |
| 45 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + run: | |
| 47 | + npx semantic-release > semantic-release-output.log 2>&1 || true |
| 48 | + cat semantic-release-output.log |
| 49 | +
|
| 50 | + if grep -q "Published release" semantic-release-output.log; then |
| 51 | + echo "new_release_published=true" >> $GITHUB_OUTPUT |
| 52 | + VERSION=$(grep "Published release" semantic-release-output.log | sed -n 's/.*Published release \([0-9.]*\).*/\1/p') |
| 53 | + echo "new_release_version=$VERSION" >> $GITHUB_OUTPUT |
| 54 | + else |
| 55 | + echo "new_release_published=false" >> $GITHUB_OUTPUT |
| 56 | + fi |
| 57 | +
|
| 58 | + docker: |
| 59 | + name: Build and Push Docker Image |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: release |
| 62 | + if: needs.release.outputs.new_release_published == 'true' |
| 63 | + steps: |
| 64 | + - name: Checkout |
| 65 | + uses: actions/checkout@v4 |
| 66 | + |
| 67 | + - name: Set up Docker Buildx |
| 68 | + uses: docker/setup-buildx-action@v3 |
| 69 | + |
| 70 | + - name: Login to GitHub Container Registry |
| 71 | + uses: docker/login-action@v3 |
| 72 | + with: |
| 73 | + registry: ghcr.io |
| 74 | + username: ${{ github.actor }} |
| 75 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + |
| 77 | + - name: Extract metadata |
| 78 | + id: meta |
| 79 | + uses: docker/metadata-action@v5 |
| 80 | + with: |
| 81 | + images: ghcr.io/${{ github.repository }}/lighthouse |
| 82 | + tags: | |
| 83 | + type=semver,pattern={{version}},value=${{ needs.release.outputs.new_release_version }} |
| 84 | + type=semver,pattern={{major}}.{{minor}},value=${{ needs.release.outputs.new_release_version }} |
| 85 | + type=semver,pattern={{major}},value=${{ needs.release.outputs.new_release_version }} |
| 86 | + type=raw,value=latest |
| 87 | +
|
| 88 | + - name: Build and push |
| 89 | + uses: docker/build-push-action@v5 |
| 90 | + with: |
| 91 | + context: ./lighthouse |
| 92 | + file: ./lighthouse/Dockerfile |
| 93 | + push: true |
| 94 | + tags: ${{ steps.meta.outputs.tags }} |
| 95 | + labels: ${{ steps.meta.outputs.labels }} |
| 96 | + cache-from: type=gha |
| 97 | + cache-to: type=gha,mode=max |
0 commit comments