|
| 1 | +# When a PR is merged, or when run manually, this workflow will create a |
| 2 | +# release and publish the container image to the GitHub Container Registry. Both |
| 3 | +# will be labeled with the version specified in the manifest file. |
| 4 | +name: Continuous Delivery |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + types: |
| 9 | + - closed |
| 10 | + branches: |
| 11 | + - main |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +env: |
| 15 | + CONTAINER_REGISTRY: ghcr.io |
| 16 | + CONTAINER_REGISTRY_USERNAME: ${{ github.actor }} |
| 17 | + CONTAINER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} |
| 18 | + MANIFEST_PATH: action.yml |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: write |
| 22 | + packages: write |
| 23 | + |
| 24 | +jobs: |
| 25 | + publish: |
| 26 | + name: Publish Container Image |
| 27 | + runs-on: ubuntu-latest |
| 28 | + |
| 29 | + # Ignore Dependabot pull requests. |
| 30 | + if: | |
| 31 | + github.event_name == 'workflow_dispatch' || |
| 32 | + (github.event.pull_request.merged == true && |
| 33 | + startsWith(github.head_ref, 'dependabot/') == false) |
| 34 | +
|
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + id: checkout |
| 38 | + uses: actions/checkout@v6 |
| 39 | + with: |
| 40 | + fetch-tags: true |
| 41 | + ref: main |
| 42 | + |
| 43 | + - name: Check Version |
| 44 | + id: version |
| 45 | + uses: issue-ops/semver@v3 |
| 46 | + with: |
| 47 | + check-only: true |
| 48 | + manifest-path: ${{ env.MANIFEST_PATH }} |
| 49 | + ref: main |
| 50 | + workspace: ${{ github.workspace }} |
| 51 | + |
| 52 | + # Create the list of image tags that will be published. If a prerelease is |
| 53 | + # being published (e.g. `1.2.3-alpha.4`), only the prerelease tag will be |
| 54 | + # published (`v1.2.3-alpha.4`). Otherwise, the following tags will be |
| 55 | + # published: |
| 56 | + # - `latest` |
| 57 | + # - `v1.2.3` |
| 58 | + # - `v1.2` |
| 59 | + # - `v1` |
| 60 | + - name: Set Image Tags |
| 61 | + id: tags |
| 62 | + uses: actions/github-script@v8 |
| 63 | + with: |
| 64 | + script: | |
| 65 | + const version = '${{ steps.version.outputs.version }}' |
| 66 | +
|
| 67 | + // Check if prerelease (e.g. 1.2.3-alpha.4) |
| 68 | + if (version.includes('-')) { |
| 69 | + // Only output the prerelease tag |
| 70 | + core.setOutput('tags', `type=raw,value=v${version}`) |
| 71 | + } else { |
| 72 | + // Output all the tags |
| 73 | + let tags = [ |
| 74 | + 'type=raw,value=latest', |
| 75 | + `type=raw,value=v${version}`, |
| 76 | + `type=raw,value=v${version.split('.').slice(0, 2).join('.')}`, |
| 77 | + `type=raw,value=v${version.split('.')[0]}` |
| 78 | + ] |
| 79 | + core.setOutput('tags', tags.join('\n')) |
| 80 | + } |
| 81 | +
|
| 82 | + # Get metadata to apply to image |
| 83 | + - name: Extract Metadata |
| 84 | + id: meta |
| 85 | + uses: docker/metadata-action@v5 |
| 86 | + with: |
| 87 | + images: ${{ env.CONTAINER_REGISTRY }}/${{ github.repository }} |
| 88 | + tags: ${{ steps.tags.outputs.tags }} |
| 89 | + |
| 90 | + # Authenticate to the container registry |
| 91 | + - name: Authenticate to Container Registry |
| 92 | + id: login |
| 93 | + uses: docker/login-action@v3 |
| 94 | + with: |
| 95 | + registry: ${{ env.CONTAINER_REGISTRY }} |
| 96 | + username: ${{ env.CONTAINER_REGISTRY_USERNAME }} |
| 97 | + password: ${{ env.CONTAINER_REGISTRY_PASSWORD }} |
| 98 | + |
| 99 | + # Publish the container image |
| 100 | + - name: Publish Container Image |
| 101 | + id: publish |
| 102 | + uses: docker/build-push-action@v6 |
| 103 | + env: |
| 104 | + LABELS: ${{ steps.meta.outputs.labels }} |
| 105 | + TAGS: ${{ steps.meta.outputs.tags }} |
| 106 | + with: |
| 107 | + labels: ${{ env.LABELS }} |
| 108 | + push: true |
| 109 | + tags: ${{ env.TAGS }} |
| 110 | + |
| 111 | + - name: Create Release |
| 112 | + id: release |
| 113 | + uses: issue-ops/releaser@v3 |
| 114 | + with: |
| 115 | + tag: v${{ steps.version.outputs.version }} |
0 commit comments