Trigger release on new Helm version #587
This file contains 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: Trigger release on new Helm version | |
on: | |
schedule: | |
- cron: '30 4 * * *' | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
release_suffix: | |
description: 'Suffix of release, git and docker tag (only next number, without dash). e.g. "2" -> "4.3.22-2"' | |
required: true | |
type: string | |
pull_request: | |
push: | |
jobs: | |
check_for_new_helm_version_and_push_image: | |
name: Update on new release | |
runs-on: ubuntu-22.04 | |
steps: | |
- run: sudo apt-get install -y jq | |
- uses: actions/checkout@v3 | |
- name: Compare releases | |
id: compare_releases | |
run: | | |
eval $(scripts/updateVersionsInDockerfile.sh) | |
echo "triggerNewRelease=${triggerNewRelease}" | tee -a $GITHUB_OUTPUT | |
echo "helmRelease=${helmRelease}" | tee -a $GITHUB_OUTPUT | |
echo "docker_and_git_tag=${helmRelease}-${{ inputs.release_suffix || 1 }}" | tee -a $GITHUB_OUTPUT | |
- name: Commit changes | |
id: auto-commit-action | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
if: (steps.compare_releases.outputs.triggerNewRelease == 'true' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' | |
with: | |
commit_message: Updated to latest Helm version v${{ steps.compare_releases.outputs.helmRelease }} | |
- name: Prepare | |
id: prep | |
run: | | |
GHCR_IMAGE=ghcr.io/${{ github.repository_owner }}/jenkins-helm | |
VERSION=${{ steps.compare_releases.outputs.docker_and_git_tag }} | |
TAGS="${GHCR_IMAGE}:latest,${GHCR_IMAGE}:${VERSION},${GHCR_IMAGE}:$(echo $VERSION | sed 's/-\([0-9]*\)$//')" | |
COMMIT="${{ steps.auto-commit-action.outputs.commit_hash }}" | |
if [[ -z "${COMMIT}" ]]; then | |
COMMIT="$(echo ${{ github.sha }})" | |
fi | |
echo "VERSION=${VERSION}" | tee -a $GITHUB_ENV | |
echo "GHCR_IMAGE=${GHCR_IMAGE}" | tee -a $GITHUB_ENV | |
echo "TAGS=${TAGS}" | tee -a $GITHUB_ENV | |
echo "IMAGE=ghcr.io/$GITHUB_REPOSITORY" | tee -a $GITHUB_ENV | |
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" | tee -a $GITHUB_ENV | |
echo "GIT_SHA=$COMMIT" | tee -a $GITHUB_ENV | |
echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" | tee -a $GITHUB_ENV | |
- name: Login to GitHub Container Registry | |
if: (steps.compare_releases.outputs.triggerNewRelease == 'true' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v4 | |
with: | |
push: "${{ (steps.compare_releases.outputs.triggerNewRelease == 'true' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' }}" | |
# As we might have committed some changes above, we need to tell buildKit to check this commit out, | |
# instead of the commit that this build was triggered with ( github.sha ) | |
# See https://github.com/docker/build-push-action/tree/817ed59#git-context | |
context: https://github.com/${{ github.repository }}.git#${{ env.GIT_SHA }} | |
labels: | | |
org.opencontainers.image.authors=${{ github.repository_owner }} | |
org.opencontainers.image.created=${{ env.BUILD_DATE }} | |
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} | |
org.opencontainers.image.ref.name=${{ env.GIT_REF }} | |
org.opencontainers.image.revision=${{ env.GIT_SHA }} | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA}} and ref ${{ env.GIT_REF }} | |
tags: ${{ env.TAGS }} | |
- name: Check manifest | |
if: (steps.compare_releases.outputs.triggerNewRelease == 'true' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' | |
run: docker buildx imagetools inspect ${{ env.GHCR_IMAGE }}:${{ env.VERSION }} | |
- name: Create release on new Helm version | |
if: (steps.compare_releases.outputs.triggerNewRelease == 'true' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: "${{ steps.compare_releases.outputs.docker_and_git_tag }}" | |
release_name: "${{ steps.compare_releases.outputs.docker_and_git_tag }}" | |
body: | | |
The image can be pulled with `$ docker pull ghcr.io/cloudogu/jenkins-helm:${{ steps.compare_releases.outputs.docker_and_git_tag }}` | |
draft: false | |
prerelease: false | |
commitish: ${{ steps.auto-commit-action.outputs.commit_hash }} # Ignored if empty, i.e. no commit because of no change |