Multi-Platform Build and Release #87
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Multi-Platform Build and Release | |
| on: | |
| release: | |
| types: [published] | |
| # push: | |
| # tags: | |
| # - "v*" | |
| # branches: | |
| # - "master" | |
| # paths-ignore: | |
| # - "docs/**" | |
| # - '.github/**' | |
| workflow_call: | |
| inputs: | |
| release-channel: | |
| description: "Release channel (stable or edge)" | |
| required: true | |
| type: string | |
| default: "stable" | |
| release-ver: | |
| description: "Stable Release Version" | |
| required: true | |
| default: "v" | |
| type: string | |
| workflow_dispatch: | |
| inputs: | |
| release-channel: | |
| description: "Release channel (stable or edge)" | |
| required: true | |
| type: string | |
| default: "stable" | |
| release-ver: | |
| description: "Stable Release Version" | |
| required: true | |
| default: "v" | |
| type: string | |
| env: | |
| GIT_VERSION: ${{github.event.inputs.release-ver}} | |
| RELEASE_CHANNEL: ${{github.event.inputs.release-channel || inputs.release-channel }} | |
| jobs: | |
| print-inputs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - run: | | |
| echo "Env RELEASE_CHANNEL: ${{env.RELEASE_CHANNEL}}" | |
| echo "Env GIT_VERSION: ${{env.GIT_VERSION}}" | |
| docker-build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Identify Release Values | |
| run: | | |
| # LATEST_VERSION=$(git ls-remote --tags | tail -1 | cut -f2 | sed 's/refs\/tags\///g') | |
| # GIT_VERSION=$(git ls-remote --tags | tail -1 | cut -f2 | sed 's/refs\/tags\///g') | |
| # GIT_VERSION=$(git describe --tags `git rev-list --tags --max-count=1` --always) | |
| GIT_STRIPPED_VERSION=$(echo $GIT_VERSION | cut -c2-) | |
| # echo "GIT_LATEST=$LATEST_VERSION" >> $GITHUB_ENV | |
| echo "GIT_VERSION=$GIT_VERSION" >> $GITHUB_ENV | |
| echo "GIT_STRIPPED_VERSION=$GIT_STRIPPED_VERSION" >> $GITHUB_ENV | |
| shell: bash | |
| - name: Generate release notes | |
| id: release_notes | |
| run: | | |
| RELEASE_NOTES=$(gh release create ${{ github.ref_name }} --generate-notes --repo ${{ github.repository }} | tail -n +2) # Get generated release notes, excluding the first line | |
| RELEASE_NOTES="$RELEASE_NOTES\nSee https://docs.layer5.io/kanvas/reference/releases/$GIT_VERSION" | |
| echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV | |
| echo "$RELEASE_NOTES" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Docker Meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: layer5/kanvas-docker-extension | |
| flavor: | | |
| latest=false | |
| tags: | | |
| type=raw,value=${{env.RELEASE_CHANNEL}}-{{sha}} | |
| type=semver,pattern={{version}},value=${{env.GIT_STRIPPED_VERSION}} | |
| type=raw,pattern={{version}},value=${{env.RELEASE_CHANNEL}}-${{env.GIT_VERSION}} | |
| type=raw,value=${{env.RELEASE_CHANNEL}}-{{tag}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} | |
| type=raw,value=${{env.RELEASE_CHANNEL}}-latest | |
| type=raw,pattern={{version}},value=${{env.RELEASE_CHANNEL}}-${{env.GIT_VERSION}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and Push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: "{{defaultContext}}" | |
| push: true | |
| build-args: | | |
| GIT_STRIPPED_VERSION=${{env.GIT_STRIPPED_VERSION}} | |
| GIT_VERSION=${{env.GIT_VERSION}} | |
| RELEASE_CHANNEL=${{env.RELEASE_CHANNEL}} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| platforms: linux/amd64,linux/arm64 | |
| - name: Docker Hub Description | |
| uses: peter-evans/dockerhub-description@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| repository: layer5/kanvas-docker-extension | |
| readme-filepath: README.md | |
| email-on-failure: | |
| needs: [docker-build] | |
| if: ${{ failure() }} | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Find failed jobs. | |
| run: | | |
| curl "https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs" | jq -r '.jobs[] | select(.conclusion == "failure") | "\(.name): \(.steps[] | select(.conclusion == "failure") | .name)\n\(.html_url)\n"' >> output.txt | |
| # Save multi-line environment variables by using the delimiters syntex. | |
| echo "EMAIL_BODY<<EOF" >> $GITHUB_ENV | |
| echo "$(cat ./output.txt)" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| - name: Failed jobs summary | |
| run: | | |
| echo "${{ env.EMAIL_BODY }}" | |
| - name: Send Email Notification | |
| if: env.EMAIL_BODY != '' | |
| uses: dawidd6/action-send-mail@v6 | |
| with: | |
| server_address: smtp.gmail.com | |
| server_port: 465 | |
| username: ${{ secrets.MAIL_USERNAME }} | |
| password: ${{ secrets.MAIL_PASSWORD }} | |
| subject: Job(s) failure in the build-and-release-stable workflow | |
| to: support@layer5.io | |
| from: Docker Kanvas Extension Releaser | |
| body: | | |
| The workflow failed. Here are the details: | |
| ${{ env.EMAIL_BODY }} | |
| Workflow run log URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |