|
| 1 | +name: Release Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '[0-9]+.[0-9]+.[0-9]+' # Push events to any matching semantic tag. For example, 1.10.1 or 2.0.0. |
| 7 | + |
| 8 | +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. |
| 9 | +env: |
| 10 | + REGISTRY: ghcr.io |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
| 12 | + |
| 13 | +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. |
| 14 | +jobs: |
| 15 | + build-and-push-image: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + packages: write |
| 21 | + attestations: write |
| 22 | + id-token: write |
| 23 | + # |
| 24 | + steps: |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + - name: Update container in operator JSON |
| 28 | + run: | |
| 29 | + jq --arg variable "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/}" '.container = $variable' operator.json |
| 30 | + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. |
| 31 | + - name: Log in to the Container registry |
| 32 | + uses: docker/login-action@v3.3.0 |
| 33 | + with: |
| 34 | + registry: ${{ env.REGISTRY }} |
| 35 | + username: ${{ github.actor }} |
| 36 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. |
| 38 | + - name: Extract metadata (tags, labels) for Docker |
| 39 | + id: meta |
| 40 | + uses: docker/metadata-action@v5.5.1 |
| 41 | + with: |
| 42 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 43 | + tags: | |
| 44 | + # minimal |
| 45 | + type=pep440,pattern={{version}} |
| 46 | + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. |
| 47 | + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. |
| 48 | + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
| 49 | + - name: Build and push Docker image |
| 50 | + id: push |
| 51 | + uses: docker/build-push-action@v6.7.0 |
| 52 | + with: |
| 53 | + context: . |
| 54 | + push: true |
| 55 | + tags: ${{ steps.meta.outputs.tags }} |
| 56 | + labels: ${{ steps.meta.outputs.labels }} |
| 57 | + # A PAT is needed for this action, GITHUB_TOKEN cannot get relevant permission |
| 58 | + # secrets: | |
| 59 | + # github_pat=${{ secrets.GH_PAT }} |
| 60 | + - name: Create required package.json |
| 61 | + run: echo '{}' > package.json |
| 62 | + - name: Build changelog |
| 63 | + id: Changelog |
| 64 | + uses: tercen/generate-changelog-action@master |
| 65 | + - name: Create release |
| 66 | + id: create_release |
| 67 | + uses: actions/create-release@latest |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
| 70 | + with: |
| 71 | + tag_name: ${{ github.ref }} |
| 72 | + release_name: Release ${{ github.ref }} |
| 73 | + body: ${{steps.Changelog.outputs.changelog}} |
| 74 | + draft: false |
| 75 | + prerelease: false |
0 commit comments