forked from armbian/build
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create wokflow to update ORAS_VERSION via auto-PR
- Loading branch information
1 parent
c84703d
commit 19fdf0e
Showing
1 changed file
with
84 additions
and
0 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,84 @@ | ||
name: Update Tools in Scripts | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
push: | ||
branches: | ||
- 'test-workflow-update-oras' | ||
|
||
schedule: | ||
- cron: '42 3 16 * *' # Run monthly on the 16th day of the month at 03:42 AM (random value as to not overload GitHub) | ||
|
||
jobs: | ||
update-version-oras: | ||
name: Update ORAS version | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
tool: | ||
- 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) | ||
VAR_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 ${{ matrix.tool.PROJECT_NAME }} version | ||
id: get-version-current | ||
run: | | ||
version_current=$(grep -Po '(?<=${{ matrix.tool.VERSION_VAR}}=\${${{ matrix.tool.VERSION_VAR}}:-)[0-9.]+(?=})' ${{ matrix.tool.VAR_FILE }}) | ||
echo "version_current=$version_current" >> $GITHUB_OUTPUT | ||
- name: Get latest ${{ matrix.tool.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/${{ matrix.tool.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<<EOFFEOFFF42" # Has to be a unique delimiter that doesn't appear in the changelog itself | ||
curl --silent "https://api.github.com/repos/${{ matrix.tool.PROJECT_NAME }}/releases/latest" | jq -r .body \ | ||
| sed -E -e 's/(#([0-9]+))/${{ matrix.tool.USER_NAME }}\/${{ matrix.tool.REPO_NAME }}\1/g' \ | ||
-e 's/github\.com/redirect.github.com/g' | ||
echo "EOFFEOFFF42" | ||
} >> "$GITHUB_ENV" | ||
- name: Update ${{ matrix.tool.VERSION_VAR}} in script | ||
run: | | ||
version_latest=${{ steps.get-version-latest.outputs.version_latest }} | ||
sed -i "s/${{ matrix.tool.VERSION_VAR}}=\${${{ matrix.tool.VERSION_VAR}}:-[0-9.]*}/${{ matrix.tool.VERSION_VAR}}=\${${{ matrix.tool.VERSION_VAR}}:-$version_latest}/g" ${{ matrix.tool.VAR_FILE }} | ||
- name: Create Pull Request to update ${{ matrix.tool.VERSION_VAR}} for ${{ matrix.tool.PROJECT_NAME }} | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: "tools: Bump `${{ matrix.tool.VERSION_VAR}}` from ${{ steps.get-version-current.outputs.version_current }} to ${{ steps.get-version-latest.outputs.version_latest }}" | ||
branch: update-version-${{ matrix.tool.PROJECT_NAME }}-${{ steps.get-version-latest.outputs.version_latest }} | ||
title: "Bump `${{ matrix.tool.VERSION_VAR}}` from ${{ steps.get-version-current.outputs.version_current }} to ${{ steps.get-version-latest.outputs.version_latest }}" | ||
body: | | ||
Bumps `${{ matrix.tool.VERSION_VAR}}` from ${{ steps.get-version-current.outputs.version_current }} to ${{ steps.get-version-latest.outputs.version_latest }}. | ||
<details><summary><b>Release notes</b></summary> | ||
<p><em>Sourced from <a href="https://github.com/${{ matrix.tool.PROJECT_NAME }}/releases">${{ matrix.tool.PROJECT_NAME }}'s releases</a>. | ||
<br>Please note that this only shows the release notes for the latest release.</em></p> | ||
<blockquote> | ||
${{ env.CHANGE_LOG }} | ||
</blockquote> | ||
</details> | ||
labels: update, automated pr |