diff --git a/.github/workflows/draft-release.yaml b/.github/workflows/draft-release.yaml new file mode 100644 index 0000000..349a2b8 --- /dev/null +++ b/.github/workflows/draft-release.yaml @@ -0,0 +1,66 @@ +name: Draft Release PR + +# Description: +# This workflow will draft a new release PR for the helm chart if there is a new runner image/appVersion . +# A release PR will be created in these cases. +# - When a user kicks offs this workflow manually. A user can specify the CHART_VERSION and APP_VERSION used for the new release. +# - When the cron schedule kicks off the job and there is a new runner image tag available. + +on: + schedule: + # Run every 12 hours at 55 minutes past the hour. + - cron: "55 */12 * * *" + workflow_dispatch: + inputs: + CHART_VERSION: + description: 'Optionally overrides the chart version in Chart.yaml.' + required: false + default: '' + APP_VERSION: + description: 'Optionally overrides the app version in Chart.yaml.' + required: false + default: '' + +jobs: + draft-release: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + env: + CHART_VERSION: ${{ github.event.inputs.CHART_VERSION }} + APP_VERSION: ${{ github.event.inputs.APP_VERSION }} + steps: + - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + + - name: Prepare Release + run: | + make CHART_VERSION=$CHART_VERSION APP_VERSION=$APP_VERSION prepare-release + make docker-docs + + - name: Check if PR is needed + run: | + echo "NEEDS_PR=1" >> "$GITHUB_OUTPUT" + git fetch origin + # Directly check if the branch exists and has the same changes in the remote repository + if git ls-remote --heads origin new-version-release > /dev/null; then + if git diff --no-ext-diff --quiet origin/new-version-release -- charts; then + echo "NEEDS_PR=0" >> "$GITHUB_OUTPUT" + fi + fi + + - name: Open PR for Version Update + id: open_pr + if: ${{ steps.prepare_release.outputs.NEEDS_UPDATE == 1 && steps.check_if_pr_open.outputs.NEEDS_PR == 1 }} + uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5 + with: + commit-message: Prepare release v${{ steps.prepare_release.outputs.NEW_CHART_VERSION }} + title: "chore: Prepare release v${{ steps.prepare_release.outputs.NEW_CHART_VERSION }}" + body: | + Description + - Release chart version ${{ steps.prepare_release.outputs.NEW_CHART_VERSION }} + - Update runner app version ${{ steps.prepare_release.outputs.NEW_APP_VERSION }} + branch: new-version-release + base: main + delete-branch: true + draft: always-true diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 805edf2..25ff01f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,6 +4,11 @@ on: pull_request: branches-ignore: - gh-pages + types: + - opened + - synchronize + - reopened + - ready_for_review # for draft-release.yaml's PR push: branches: [ main ] diff --git a/Makefile b/Makefile index e29e320..ef8b4fd 100644 --- a/Makefile +++ b/Makefile @@ -36,3 +36,8 @@ docs: ## Update chart docs .PHONY: install-tools install-tools: ## Install tools (macOS) LOCALBIN=$(LOCALBIN) scripts/install-tools.sh || exit 1 + +.PHONY: prepare-release +prepare-release: ## Prepare new release if needed + @echo "Preparing release..." + ./scripts/prepare-release.sh || exit 1 diff --git a/scripts/install-tools.sh b/scripts/install-tools.sh index 24edbc2..939b63c 100755 --- a/scripts/install-tools.sh +++ b/scripts/install-tools.sh @@ -3,7 +3,6 @@ # Notes: # - Should be executed via the `make install-tools` command. # - Supports macOS for installations via `brew install` -# Include the base utility functions for setting and debugging variables SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Function to install a tool @@ -68,7 +67,7 @@ install_helm_plugin() { } # install brew-based tools -for tool in yamllint chart-testing helm kubectl pre-commit norwoodj/tap/helm-docs; do +for tool in yq jq yamllint chart-testing helm kubectl pre-commit norwoodj/tap/helm-docs; do install "$tool" brew done diff --git a/scripts/prepare-release.sh b/scripts/prepare-release.sh new file mode 100755 index 0000000..85d7387 --- /dev/null +++ b/scripts/prepare-release.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Description: Checks if new runner image tag is available and +# updates the appVersion and version in the Chart.yaml file if necessary. +# User can override the new appVersion and chart version by setting the +# APP_VERSION and CHART_VERSION environment variables respectively. + +# Requires yq and jq to be installed. + +set -euo pipefail +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +CHART_YAML_PATH="${SCRIPT_DIR}/../charts/splunk-synthetics-runner/Chart.yaml" + +CURRENT_APP_VERSION=$(yq eval '.appVersion' ${CHART_YAML_PATH}) +CURRENT_CHART_VERSION=$(yq eval '.version' ${CHART_YAML_PATH}) +NEW_APP_VERSION="" + +# Fetch the latest runner image tag from Quay.io +LATEST_RUNNER_TAG=$(curl -s "https://quay.io/api/v1/repository/signalfx/splunk-synthetics-runner/tag/?onlyActiveTags=true" \ +-H "Accept: application/json" | \ +jq -r '. as $orig | +.tags[] | select (.name == "latest") | +.manifest_digest as $latest | $orig.tags[] | +select(.manifest_digest == $latest and .name != "latest") | .name') +echo "The latest runner image tag available in quay.io is $LATEST_RUNNER_TAG" + +NEW_APP_VERSION=${APP_VERSION:-$LATEST_RUNNER_TAG} + +# Exit if current and new app versions are the same +if [ "$CURRENT_APP_VERSION" == "$NEW_APP_VERSION" ]; then + echo "Runner image tag is already up to date (appVersion $CURRENT_APP_VERSION)." + if [[ -n "${GITHUB_ACTIONS-}" ]]; then + echo "NEEDS_UPDATE=0" >> "$GITHUB_ENV" + fi + exit 0 +else + echo "Runner image tag is not up to date. Current appVersion is $CURRENT_APP_VERSION and the new appVersion is $NEW_APP_VERSION." + if [[ -n "${GITHUB_ACTIONS-}" ]]; then + echo "NEEDS_UPDATE=1" >> "$GITHUB_ENV" + echo "NEW_APP_VERSION=$NEW_APP_VERSION" >> "$GITHUB_ENV" + fi +fi + +# Update the appVersion +NEW_APP_VERSION=${NEW_APP_VERSION} yq eval -i '.appVersion = strenv(NEW_APP_VERSION)' ${CHART_YAML_PATH} + +# Update the chart version by bumping up the patch version +BUMPED_PATCH_VERSION=$(echo ${CURRENT_CHART_VERSION} | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') +NEW_CHART_VERSION=${CHART_VERSION:-$BUMPED_PATCH_VERSION} + +echo "Updating the chart version to $NEW_CHART_VERSION" +NEW_CHART_VERSION=${NEW_CHART_VERSION} yq eval -i '.version = strenv(NEW_CHART_VERSION)' ${CHART_YAML_PATH} + +if [[ -n "${GITHUB_ACTIONS-}" ]]; then + echo "NEW_CHART_VERSION=$NEW_CHART_VERSION" >> "$GITHUB_ENV" +fi