Skip to content

Commit 887cfcb

Browse files
committed
Create wokflow to update ORAS_VERSION via auto-PR
1 parent c84703d commit 887cfcb

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

.github/workflows/update-tools.yml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Update Tools in Scripts
2+
3+
permissions:
4+
contents: write
5+
pull-requests: write
6+
7+
on:
8+
workflow_dispatch:
9+
10+
push:
11+
branches:
12+
- 'test-workflow-update-oras'
13+
14+
schedule:
15+
- cron: '0 3 16 * *' # Run monthly at 03:00 AM, on the 16th day of the month
16+
17+
jobs:
18+
update-version-oras:
19+
name: Update ORAS version
20+
runs-on: ubuntu-latest
21+
22+
env:
23+
USER_NAME: "oras-project" # GitHub user name
24+
REPO_NAME: "oras" # GitHub repo name
25+
PROJECT_NAME: "oras-project/oras" # This is always USER_NAME/REPO_NAME (like in the GitHub URL)
26+
FILE: "lib/functions/general/oci-oras.sh" # Where the version variable of the tool is saved
27+
VERSION_VAR: "ORAS_VERSION" # Version variable how it appears in the script
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
33+
- name: Get current ${{ env.PROJECT_NAME }} version
34+
id: get-version-current
35+
run: |
36+
version_current=$(grep -Po '(?<=${{ env.VERSION_VAR}}=\${${{ env.VERSION_VAR}}:-)[0-9.]+(?=})' ${{ env.FILE }})
37+
echo "version_current=$version_current" >> $GITHUB_OUTPUT
38+
39+
- name: Get latest ${{ env.PROJECT_NAME }} version
40+
id: get-version-latest
41+
# Multi-line string for CHANGE_LOG env, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
42+
# Further exmplanation for the CHANGE_LOG env:
43+
# The first 'sed' expression replaces "#123" with "username/repo#123" to prevent auto-linking to own repo
44+
# The second 'sed' expression adds redirect.github.com to prevent "This was referenced" in the external repo's PRs/issues
45+
run: |
46+
version_latest=$(curl --silent "https://api.github.com/repos/${{ env.PROJECT_NAME }}/releases/latest" | jq -r .tag_name)
47+
version_latest=${version_latest#v} # Removing the 'v' prefix since the script uses only plain numbers
48+
echo "version_latest=$version_latest" >> $GITHUB_OUTPUT
49+
{
50+
echo "CHANGE_LOG<<EOFFEOFFF42" # Has to be a unique delimiter that doesn't appear in the changelog itself
51+
curl --silent "https://api.github.com/repos/${{ env.PROJECT_NAME }}/releases/latest" | jq -r .body \
52+
| sed -E -e 's/(#([0-9]+))/${{ env.USER_NAME }}\/${{ env.REPO_NAME }}\1/g' \
53+
-e 's/github\.com/redirect.github.com/g'
54+
echo "EOFFEOFFF42"
55+
} >> "$GITHUB_ENV"
56+
57+
- name: Update ${{ env.VERSION_VAR}} in script
58+
run: |
59+
version_latest=${{ steps.get-version-latest.outputs.version_latest }}
60+
sed -i "s/${{ env.VERSION_VAR}}=\${${{ env.VERSION_VAR}}:-[0-9.]*}/${{ env.VERSION_VAR}}=\${${{ env.VERSION_VAR}}:-$version_latest}/g" ${{ env.FILE }}
61+
62+
- name: Create Pull Request to update ${{ env.VERSION_VAR}} for ${{ env.PROJECT_NAME }}
63+
uses: peter-evans/create-pull-request@v6
64+
with:
65+
token: ${{ secrets.GITHUB_TOKEN }}
66+
commit-message: "Bump `${{ env.VERSION_VAR}}` from ${{ steps.get-version-current.outputs.version_current }} to ${{ steps.get-version-latest.outputs.version_latest }}"
67+
branch: update-version-${{ env.PROJECT_NAME }}-${{ steps.get-version-latest.outputs.version_latest }}
68+
title: "Bump `${{ env.VERSION_VAR}}` from ${{ steps.get-version-current.outputs.version_current }} to ${{ steps.get-version-latest.outputs.version_latest }}"
69+
body: |
70+
Bumps `${{ env.VERSION_VAR}}` from ${{ steps.get-version-current.outputs.version_current }} to ${{ steps.get-version-latest.outputs.version_latest }}.
71+
72+
<details><summary><b>Release notes</b></summary>
73+
<p><em>Sourced from <a href="https://github.com/${{ env.PROJECT_NAME }}/releases">${{ env.PROJECT_NAME }}'s releases</a>.
74+
<br>Please note that this only shows the release notes for the latest release.</em></p>
75+
<blockquote>
76+
77+
${{ env.CHANGE_LOG }}
78+
79+
</blockquote>
80+
</details>
81+
labels: update, automated pr

0 commit comments

Comments
 (0)