|
| 1 | +name: Build & Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths-ignore: |
| 6 | + - '.gitignore' |
| 7 | + - '.mergify.yml' |
| 8 | + - 'CHANGELOG.md' |
| 9 | + - 'LICENSE' |
| 10 | + - 'README.md' |
| 11 | + - 'renovate.json' |
| 12 | + pull_request: |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + concurrency: |
| 16 | + # Allow only one release at a time. |
| 17 | + group: release-${{ github.event.number || github.ref }} |
| 18 | + needs: |
| 19 | + - build |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + release-status: ${{ env.release_status }} |
| 23 | + release-version: ${{ env.release_version }} |
| 24 | + # Release only where secrets are available. |
| 25 | + if: >- |
| 26 | + !github.event.repository.fork |
| 27 | + && ( |
| 28 | + github.event_name != 'pull_request' |
| 29 | + || github.event.pull_request.head.repo.full_name == github.repository |
| 30 | + ) |
| 31 | + steps: |
| 32 | + - name: Checkout the repository |
| 33 | + uses: actions/checkout@v3 |
| 34 | + with: |
| 35 | + submodules: recursive |
| 36 | + fetch-depth: 0 |
| 37 | + - name: Setup Node.js |
| 38 | + uses: actions/setup-node@v3 |
| 39 | + with: |
| 40 | + node-version: "lts/*" |
| 41 | + - name: Release |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + run: | |
| 45 | + npm install |
| 46 | + npx semantic-release |
| 47 | + docker-image-delivery: |
| 48 | + needs: |
| 49 | + - release |
| 50 | + runs-on: ubuntu-latest |
| 51 | + if: needs.release.outputs.release-status == 'released' |
| 52 | + env: |
| 53 | + REGISTRY: ghcr.io |
| 54 | + IMAGE_NAME: ${{ github.repository }} |
| 55 | + steps: |
| 56 | + - name: Checkout the repository |
| 57 | + uses: actions/checkout@v3 |
| 58 | + with: |
| 59 | + submodules: recursive |
| 60 | + fetch-depth: 0 |
| 61 | + - name: Login to GitHub Container registry |
| 62 | + uses: docker/login-action@v2.1.0 |
| 63 | + with: |
| 64 | + registry: ${{ env.REGISTRY }} |
| 65 | + username: ${{ github.actor }} |
| 66 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + - id: full-image-name |
| 68 | + run: echo "image-name=${{env.REGISTRY}}/${{env.IMAGE_NAME}}" | tr '[:upper:]' '[:lower:]' >> $GITHUB_OUTPUT |
| 69 | + - name: Build and push the image to GitHub Container registry |
| 70 | + uses: docker/build-push-action@v4.0.0 |
| 71 | + with: |
| 72 | + context: . |
| 73 | + push: true |
| 74 | + tags: ${{ steps.full-image-name.outputs.image-name }}:latest, ${{ steps.full-image-name.outputs.image-name }}:${{ needs.release.outputs.release-version }} |
| 75 | + success: |
| 76 | + runs-on: ubuntu-22.04 |
| 77 | + needs: |
| 78 | + - release |
| 79 | + - docker-image-delivery |
| 80 | + if: >- |
| 81 | + always() && ( |
| 82 | + contains(join(needs.*.result, ','), 'failure') |
| 83 | + || !contains(join(needs.*.result, ','), 'cancelled') |
| 84 | + ) |
| 85 | + steps: |
| 86 | + - name: Verify that there were no failures |
| 87 | + run: ${{ !contains(join(needs.*.result, ','), 'failure') }} |
| 88 | + |
0 commit comments