-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add cron action to create release PR (#15)
- Loading branch information
Showing
5 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |