-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (46 loc) · 2.01 KB
/
update-cli.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
48
49
50
51
52
53
54
55
56
57
on:
schedule:
- cron: '0 0 * * *' # every day at midnight
workflow_dispatch:
name: Check for FOSSA CLI updates
jobs:
update-cli:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -x
# get version currently installed
current="$(yq '.inputs.version.default' install/action.yml)"
IFS=. read -r cmajor cminor cpatch <<< "$current"
# get latest version from GitHub
latest_obj="$(curl -s https://api.github.com/repos/fossas/fossa-cli/releases/latest)"
latest="$(jq -r '.tag_name' <<< "${latest_obj}" | sed 's/v//g')"
IFS=. read -r lmajor lminor lpatch <<< "$latest"
# update if necessary
if [[ "$lmajor" -gt "$cmajor" || "$lminor" -gt "$cminor" || "$lpatch" -gt "$cpatch" ]]; then
# check for an existing branch
if git fetch origin "fossa-${latest}"; then
echo "Branch already exists"
exit 0
fi
git checkout -b "fossa-${latest}"
# update install version
yq -i '.inputs.version.default = "'"${latest}"'"' install/action.yml
# update checksum
sha256sum="$(jq -r '.assets[] | select(.name | contains("linux_amd64.tar.gz.sha256")) | .browser_download_url' <<< "${latest_obj}" | xargs curl -sSL | awk '{print $1}')"
yq -i '.inputs.sha256sum.default = "'"${sha256sum}"'"' install/action.yml
# setup git
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# commit and push
git add install/action.yml
git commit -m "Update FOSSA CLI to ${latest}"
git push origin "fossa-${latest}"
# open PR
hub pull-request -m "Update FOSSA CLI to ${latest}" -b main
else
echo "Already up to date"
fi