Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow for Automating PR Creation for Release Updates #112

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/website-release-update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Check and Update Release Version

on:
nicolastakashi marked this conversation as resolved.
Show resolved Hide resolved
schedule:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would enable to trigger the workflow manually (and not wait for the cronjob).

Suggested change
schedule:
workflow_dispatch:
schedule:

- cron: '0 12 * * *' #Every day 12:00

jobs:
check-and-update-release-version:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Get latest release tag from prometheus-operator repository
id: get_latest_release
run: |
LATEST_RELEASE=$(curl --fail --silent "https://api.github.com/repos/prometheus-operator/prometheus-operator/releases/latest" | jq -r '.tag_name')
if ["$LATEST_RELEASE" == "" ]; then
echo "latest-release is invalid" >> "$GITHUB_OUTPUT"
exit 1
fi
echo "latest-release = $LATEST_RELEASE" >> "$GITHUB_OUTPUT"
- name: Check version in website repository
run: |
JSON_FILE="data/prometheusOperator.json"
CURRENT_VERSION=$(jq -r '.version' $JSON_FILE)
echo "Current version: $CURRENT_VERSION"

if ["$CURRENT_VERSION" == "${{ steps.get_latest_release.outputs.latest_release }}"]; then
echo "Latest version. No updates needed"
echo "update_needed=false" >> "$GITHUB_ENV"
else
echo "Versions do not match. An update is required."
echo "update_needed=true" >> "$GITHUB_ENV"
fi
- name: Update version
if: env.update_needed == 'true'
run: |
JSON_FILE="data/prometheusOperator.json"
NEW_VERSION="${{steps.get_latest_release.outputs.latest_release}}"

jq -i --arg version "$NEW_VERSION" '.version = $version' $JSON_FILE

git config --global user.name 'github-actions[bot]''
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

git checkout -b update-version
git add $JSON_FILE
git commit -m "chore: bump to $JSON_FILE"
git push origin update-version
- name: Create Pull Request
if: env.update_needed == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: main
head: update-version
title: "chore: bump to ${{ steps.get_latest_release.outputs.latest_release }}"
body: "This PR updates the release version in prometheusOperator.json file to the latest version: ${{ steps.get_latest_release.outputs.latest_release }}"rhobs/create-pull-request@v3