-
Notifications
You must be signed in to change notification settings - Fork 24
157 lines (146 loc) · 7.15 KB
/
update.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Check and Update Tailscale Binary
on:
schedule:
- cron: '0 0 * * *' # Runs every day at midnight
workflow_dispatch:
inputs:
force:
type: boolean
description: 'Force update'
required: false
default: false
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get latest release from tailscale
id: get_latest_release
uses: octokit/request-action@v2.x
with:
route: GET /repos/tailscale/tailscale/releases/latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check current version is up to date
id: check_version
run: |
NEW_TAG="${{ fromJSON(steps.get_latest_release.outputs.data).tag_name }}"
VERSION="${{ fromJSON(steps.get_latest_release.outputs.data).name }}"
CURRENT_TAG=$(curl -s https://raw.githubusercontent.com/anasfanani/Magisk-Tailscaled/master/files/VERSION.txt)
if [[ "$NEW_TAG" == "$CURRENT_TAG" && "${{ github.event.inputs.force }}" != 'true' ]]; then
echo "Current version is up to date"
echo "exit=true" >> $GITHUB_OUTPUT
else
echo "Current version is $CURRENT_TAG, latest version is $NEW_TAG"
echo "Updating to latest version"
echo "exit=false" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Checkout code
if: steps.check_version.outputs.exit != 'true'
uses: actions/checkout@v3
- name: Download and unzip latest tailscale binaries
if: steps.check_version.outputs.exit != 'true'
run: |
PREFIX=${{ steps.check_version.outputs.version }}
PREFIX=${PREFIX#v}
ARCHS=("arm" "arm64")
mkdir -p files
cd files
for ARCH in ${ARCHS[@]}; do
URL="https://pkgs.tailscale.com/stable/tailscale_${PREFIX}_${ARCH}.tgz"
curl -LO $URL
tar -xzf "tailscale_${PREFIX}_${ARCH}.tgz" "tailscale_${PREFIX}_${ARCH}/tailscaled" "tailscale_${PREFIX}_${ARCH}/tailscale"
mv "tailscale_${PREFIX}_${ARCH}/tailscaled" "tailscaled-${ARCH}"
mv "tailscale_${PREFIX}_${ARCH}/tailscale" "tailscale-${ARCH}"
rm -r "tailscale_${PREFIX}_${ARCH}"
rm "tailscale_${PREFIX}_${ARCH}.tgz"
done
cd ..
ls -la files
- name: Update VERSION.txt
if: steps.check_version.outputs.exit != 'true'
run: |
echo ${{ steps.check_version.outputs.new_tag }} > files/VERSION.txt
- name: Update update.json and module.prop
if: steps.check_version.outputs.exit != 'true'
run: |
versionString="${{ steps.check_version.outputs.version }}.0"
versionString=${versionString//[^0-9.]/}
new_tag="${{ steps.check_version.outputs.new_tag }}.0"
zipUrl="https://github.com/anasfanani/Magisk-Tailscaled/releases/download/$new_tag/Magisk-Tailscaled-$new_tag.zip"
IFS='.' read -ra VERSION_PARTS <<< "$versionString"
newVersionCode=$(printf "%02d%02d%02d%02d" "${VERSION_PARTS[0]}" "${VERSION_PARTS[1]}" "${VERSION_PARTS[2]}" "${VERSION_PARTS[3]}")
jq '.version = $newVersion | .versionCode = $newVersionCode | .zipUrl = $newZipUrl | .changelog = $newChangelog' \
--arg newVersion "$new_tag" \
--arg newVersionCode "$newVersionCode" \
--arg newZipUrl "$zipUrl" \
--arg newChangelog "https://raw.githubusercontent.com/anasfanani/Magisk-Tailscaled/master/CHANGELOG.txt" \
update.json > temp.json && mv temp.json update.json
sed -i "s/^version=.*/version=$versionString/" module.prop
sed -i "s/^versionCode=.*/versionCode=$newVersionCode/" module.prop
- name: Commit and push
if: steps.check_version.outputs.exit != 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
VERSION=${{ steps.check_version.outputs.version }}
ARCHS=("arm" "arm64")
for ARCH in ${ARCHS[@]}; do
if [[ -f files/tailscaled-${ARCH} && -f files/tailscale-${ARCH} ]]; then
git add files/tailscaled-${ARCH} files/tailscale-${ARCH}
if git diff --staged --quiet; then
echo "No changes to commit update ${{ steps.check_version.outputs.current_tag }}"
else
git commit -m "Updated from ${{ steps.check_version.outputs.current_tag }} to ${{ steps.check_version.outputs.new_tag }} for $ARCH"
fi
else
echo "Files for architecture $ARCH do not exist"
exit 1;
fi
done
git add .
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Updated version from ${{ steps.check_version.outputs.current_tag }} to ${{ steps.check_version.outputs.new_tag }}"
git tag ${{ steps.check_version.outputs.new_tag }}.0
git push origin ${{ steps.check_version.outputs.new_tag }}.0
git push
fi
- name: Create zip file
if: steps.check_version.outputs.exit != 'true'
run: |
# zip all files
zip -9 -r "Magisk-Tailscaled-${{ steps.check_version.outputs.new_tag }}.0.zip" . -x "*.git*"
# doing job for arm64
sed -i 's/arm) F_ARCH=$ARCH;;/#arm) F_ARCH=$ARCH;;/g' customize.sh # disable arm
zip -9 -r "Magisk-Tailscaled-arm64-${{ steps.check_version.outputs.new_tag }}.0.zip" . -x "*.git*" "files/tailscale-arm" "files/tailscaled-arm" "*.zip"
# doing job for arm
sed -i 's/#arm) F_ARCH=$ARCH;;/arm) F_ARCH=$ARCH;;/g' customize.sh # enable arm
sed -i 's/arm64) F_ARCH=$ARCH;;/#arm64) F_ARCH=$ARCH;;/g' customize.sh # disable arm64
zip -9 -r "Magisk-Tailscaled-arm-${{ steps.check_version.outputs.new_tag }}.0.zip" . -x "*.git*" "files/tailscale-arm64" "files/tailscaled-arm64" "*.zip"
- name: Create Release
if: steps.check_version.outputs.exit != 'true'
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
generate_release_notes: true
files: |
Magisk-Tailscaled-${{ steps.check_version.outputs.new_tag }}.0.zip
Magisk-Tailscaled-arm64-${{ steps.check_version.outputs.new_tag }}.0.zip
Magisk-Tailscaled-arm-${{ steps.check_version.outputs.new_tag }}.0.zip
name: Magisk Tailscaled ${{ steps.check_version.outputs.new_tag }}.0
tag_name: ${{ steps.check_version.outputs.new_tag }}.0
- name: Show output
run: |
echo "URL: ${{ steps.create_release.outputs.url }}"
echo "ID: ${{ steps.create_release.outputs.id }}"
echo "Upload URL: ${{ steps.create_release.outputs.upload_url }}"
echo "Assets: ${{ steps.create_release.outputs.assets }}"