-
Notifications
You must be signed in to change notification settings - Fork 149
79 lines (68 loc) · 2.67 KB
/
version-scan.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: Scan Frp Version
on:
schedule:
- cron: "0 1 * * *" # every day at UTC 1:00AM
workflow_dispatch:
jobs:
check:
name: Check Version
runs-on: ubuntu-latest
if: ${{ github.repository_owner }} == "kuoruan"
steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
token: ${{ secrets.PAT }}
- name: Get Latest Version
id: get_version
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const { data } = await github.repos.getLatestRelease({
owner: "fatedier",
repo: "frp"
});
if (data && data.tag_name) {
return data.tag_name.replace(/^v/, "")
}
return "";
- name: Compare Version
id: compare_version
if: steps.get_version.outputs.result != ''
run: |
latest_version="${{ steps.get_version.outputs.result }}"
current_version="$(grep '^PKG_VERSION:' Makefile 2>/dev/null | cut -d'=' -f2)"
if [ -n "$current_version" ] && \
[ "$current_version" != "$latest_version" ] ; then
source_hash="$(curl -sL \
"https://codeload.github.com/fatedier/frp/tar.gz/v$latest_version" | \
sha256sum | cut -d' ' -f1)"
echo "::set-output name=version::$latest_version"
echo "::set-output name=source_hash::$source_hash"
else
echo "::set-output name=version::"
echo "::set-output name=source_hash::"
fi
- name: Commit New Version
if: steps.compare_version.outputs.version != '' && steps.compare_version.outputs.source_hash != ''
run: |
version="${{ steps.compare_version.outputs.version }}"
source_hash="${{ steps.compare_version.outputs.source_hash }}"
release_branch="releases/v${version}-1"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if [ "$(git ls-remote origin "$release_branch" | wc -l)" -gt "0" ] ; then
# delete existing release branch
git push origin :$release_branch 2>/dev/null || true
fi
git checkout -b "$release_branch"
sed -i \
-e "s/^PKG_VERSION.*/PKG_VERSION:=${version}/" \
-e "s/^PKG_RELEASE.*/PKG_RELEASE:=1/" \
-e "s/^PKG_HASH.*/PKG_HASH:=${source_hash}/" \
Makefile
git add -f Makefile
git commit -m "chore: bump to v${version}-1"
git push -u origin "$release_branch"