diff --git a/.github/workflows/website-release-update.yaml b/.github/workflows/website-release-update.yaml new file mode 100644 index 0000000..d11c2b4 --- /dev/null +++ b/.github/workflows/website-release-update.yaml @@ -0,0 +1,59 @@ +name: Check and Update Release Version + +on: + 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 \ No newline at end of file