-
Notifications
You must be signed in to change notification settings - Fork 41
66 lines (54 loc) · 2.11 KB
/
autoupdate.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
name: Autoupdate
on:
schedule:
- cron: "0 * * * *"
workflow_dispatch:
jobs:
autoupdate:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo pip3 install setuptools wheel
sudo pip3 install yq
pip3 install -r scripts/requirements.txt
- name: Run autoupdate
run: |
git config user.email "[email protected]"
git config user.name "Github Actions"
git fetch origin
for file in manifests/*
do
git reset --hard origin/master
old_version=$(cat "$file" | yq -r ".version") # "1.5.2"
./scripts/autoupdate.py "$file"
if git status --porcelain | grep -q "."; then
echo "Things have changed, attempting to create a PR"
version=$(cat "$file" | yq -r ".version") # "1.5.3"
filename="${file##*/}" # "Plugin Name.yml"
name="${filename%.*}" # "Plugin Name"
branchname=$(echo "auto/$name/$version" | sed 's/[^A-Za-z0-9\/]/_/g') # "auto/Plugin_Name/1_5_3"
url=$(cat "$file" | yq -r ".autoupdate.update_url")
if [ "$url" = "null" ]; then
url=$(cat "$file" | yq -r ".homepage")
fi
diff_url="$url/compare/$old_version...$version"
if git branch -al | grep "remotes/origin/$branchname$" | grep -Fq "remotes/origin/$branchname"; then
echo "Branch $branchname already exists, discarding changes"
git restore manifests/
else
git checkout -B "$branchname"
git add manifests/
git commit -m "Update $name to $version"
git push --set-upstream origin "$branchname"
# the poor man's "does this PR exist?"
if ! gh pr ready "$branchname"; then
gh pr create --fill --label Autoupdate --body "[See the full diff]($diff_url)"
fi
fi
git checkout master
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}