From 887cfcb86e13158a2b161441128392102b2b4251 Mon Sep 17 00:00:00 2001 From: ColorfulRhino <131405023+ColorfulRhino@users.noreply.github.com> Date: Mon, 8 Jul 2024 22:40:37 +0200 Subject: [PATCH] Create wokflow to update ORAS_VERSION via auto-PR --- .github/workflows/update-tools.yml | 81 ++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/update-tools.yml diff --git a/.github/workflows/update-tools.yml b/.github/workflows/update-tools.yml new file mode 100644 index 000000000000..d7058bec48b0 --- /dev/null +++ b/.github/workflows/update-tools.yml @@ -0,0 +1,81 @@ +name: Update Tools in Scripts + +permissions: + contents: write + pull-requests: write + +on: + workflow_dispatch: + + push: + branches: + - 'test-workflow-update-oras' + + schedule: + - cron: '0 3 16 * *' # Run monthly at 03:00 AM, on the 16th day of the month + +jobs: + update-version-oras: + name: Update ORAS version + runs-on: ubuntu-latest + + env: + USER_NAME: "oras-project" # GitHub user name + REPO_NAME: "oras" # GitHub repo name + PROJECT_NAME: "oras-project/oras" # This is always USER_NAME/REPO_NAME (like in the GitHub URL) + FILE: "lib/functions/general/oci-oras.sh" # Where the version variable of the tool is saved + VERSION_VAR: "ORAS_VERSION" # Version variable how it appears in the script + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Get current ${{ env.PROJECT_NAME }} version + id: get-version-current + run: | + version_current=$(grep -Po '(?<=${{ env.VERSION_VAR}}=\${${{ env.VERSION_VAR}}:-)[0-9.]+(?=})' ${{ env.FILE }}) + echo "version_current=$version_current" >> $GITHUB_OUTPUT + + - name: Get latest ${{ env.PROJECT_NAME }} version + id: get-version-latest + # Multi-line string for CHANGE_LOG env, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings + # Further exmplanation for the CHANGE_LOG env: + # The first 'sed' expression replaces "#123" with "username/repo#123" to prevent auto-linking to own repo + # The second 'sed' expression adds redirect.github.com to prevent "This was referenced" in the external repo's PRs/issues + run: | + version_latest=$(curl --silent "https://api.github.com/repos/${{ env.PROJECT_NAME }}/releases/latest" | jq -r .tag_name) + version_latest=${version_latest#v} # Removing the 'v' prefix since the script uses only plain numbers + echo "version_latest=$version_latest" >> $GITHUB_OUTPUT + { + echo "CHANGE_LOG<> "$GITHUB_ENV" + + - name: Update ${{ env.VERSION_VAR}} in script + run: | + version_latest=${{ steps.get-version-latest.outputs.version_latest }} + sed -i "s/${{ env.VERSION_VAR}}=\${${{ env.VERSION_VAR}}:-[0-9.]*}/${{ env.VERSION_VAR}}=\${${{ env.VERSION_VAR}}:-$version_latest}/g" ${{ env.FILE }} + + - name: Create Pull Request to update ${{ env.VERSION_VAR}} for ${{ env.PROJECT_NAME }} + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "Bump `${{ env.VERSION_VAR}}` from ${{ steps.get-version-current.outputs.version_current }} to ${{ steps.get-version-latest.outputs.version_latest }}" + branch: update-version-${{ env.PROJECT_NAME }}-${{ steps.get-version-latest.outputs.version_latest }} + title: "Bump `${{ env.VERSION_VAR}}` from ${{ steps.get-version-current.outputs.version_current }} to ${{ steps.get-version-latest.outputs.version_latest }}" + body: | + Bumps `${{ env.VERSION_VAR}}` from ${{ steps.get-version-current.outputs.version_current }} to ${{ steps.get-version-latest.outputs.version_latest }}. + +
Release notes +

Sourced from ${{ env.PROJECT_NAME }}'s releases. +
Please note that this only shows the release notes for the latest release.

+
+ + ${{ env.CHANGE_LOG }} + +
+
+ labels: update, automated pr