-
Notifications
You must be signed in to change notification settings - Fork 61
47 lines (46 loc) · 2.85 KB
/
check-func.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
name: check-func
on:
schedule:
- cron: "0 8 * * *"
workflow_dispatch:
jobs:
check-func-repo:
runs-on: ubuntu-latest
env:
TOOL_REPO: knative/func
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Check Out Code
uses: actions/checkout@v4
- name: Get latest FUNC version
run: |
echo "REPO_FUNC_VERSION=$(cat src/tools.json | jq -r .func.version)" >> $GITHUB_ENV
LATEST_TOOL_RELEASE_RESP=$(gh release --repo ${{ env.TOOL_REPO }} view --json tagName,url)
echo "LATEST_TOOL_RELEASE=$(echo ${LATEST_TOOL_RELEASE_RESP} | jq -r .tagName | sed 's|knative-v||')" >> $GITHUB_ENV
echo "LATEST_TOOL_URL=$(echo ${LATEST_TOOL_RELEASE_RESP} | jq -r .url)" >> $GITHUB_ENV
- name: Find existing PR for FUNC version
run: |
echo PR_EXISTS=$(gh pr --repo ${{ github.repository }} list --state all --search "update func ${{env.LATEST_TOOL_RELEASE}} in:title" --json url | jq length) >> $GITHUB_ENV
- name: Update src/tools.json with latest func version
if: ${{ (env.LATEST_TOOL_RELEASE != env.REPO_FUNC_VERSION) && (env.PR_EXISTS == 0) }}
run: |
jq --indent 4 '.func.version = "${{ env.LATEST_TOOL_RELEASE }}"' src/tools.json | jq --indent 4 '.func.versionRange = "^${{ env.LATEST_TOOL_RELEASE }}"' | jq --indent 4 '.func.versionRangeLabel = "version >= ${{ env.LATEST_TOOL_RELEASE }}"' > src/tools.json.new
mv src/tools.json.new src/tools.json
for platform in win32 darwin darwin-arm64 linux linux-arm64; do
old_url=`jq -r ".func.platform[\"${platform}\"].url" src/tools.json`
dlFileName=`jq -r ".func.platform[\"${platform}\"].dlFileName" src/tools.json`
new_url=`echo ${old_url} | sed "s|${{ env.REPO_FUNC_VERSION }}|${{ env.LATEST_TOOL_RELEASE }}|"`
checksum_url=`echo ${new_url} | sed "s|${dlFileName}|checksums.txt|"`
checksum=`curl -s -L ${checksum_url} | grep "${dlFileName}" | sed "s|${dlFileName}||" | sed "s| ||g"`
jq --indent 4 ".func.platform[\"${platform}\"].url = \"${new_url}\"" src/tools.json | jq --indent 4 ".func.platform[\"${platform}\"].sha256sum = \"${checksum}\"" > src/tools.json.new
mv src/tools.json.new src/tools.json
done
- name: Create pull request
if: ${{ (env.LATEST_TOOL_RELEASE != env.REPO_FUNC_VERSION) && (env.PR_EXISTS == 0) }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "openshifttools-bot"
git checkout -b "func-${{ env.LATEST_TOOL_RELEASE }}"
git commit -am "Update func to ${{ env.LATEST_TOOL_RELEASE }}"
git push origin "func-${{ env.LATEST_TOOL_RELEASE }}"
gh pr create --title "Update func to ${{ env.LATEST_TOOL_RELEASE }}" --body "See ${{ env.LATEST_TOOL_URL }}"