Skip to content

Commit c747821

Browse files
committed
ci(gh-actions): setup ci for auto update
1 parent e1d7435 commit c747821

File tree

2 files changed

+169
-0
lines changed

2 files changed

+169
-0
lines changed

.github/workflows/build.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ on:
1414
pull_request:
1515
branches: [master]
1616
workflow_dispatch:
17+
inputs:
18+
make_release:
19+
default: false
20+
description: Make a forced release
21+
required: false
22+
type: boolean
23+
workflow_call:
1724

1825
jobs:
1926
build:
@@ -25,13 +32,26 @@ jobs:
2532
- name: Check out
2633
uses: actions/checkout@v4
2734
with:
35+
fetch-depth: 0
2836
submodules: "recursive"
2937

3038
- name: Setup environment
3139
uses: ./.github/actions/setup
3240
with:
3341
is-asset-build: true
3442

43+
- name: Setup keystores
44+
run: |
45+
cat > config.prop<< EOF
46+
keyStore=key.jks
47+
keyStorePass=${{ secrets.KEYSTORE_ALIAS_PASSWORD }}
48+
keyAlias=${{ secrets.KEYSTORE_ALIAS_NAME }}
49+
keyPass=${{ secrets.KEYSTORE_PASSWORD }}
50+
EOF
51+
52+
echo '${{ secrets.KEYSTORE_FILE }}' > keystore.jks.asc
53+
gpg -d --passphrase '${{ secrets.KEYSTORE_PASSWORD_GPG }}' --batch keystore.jks.asc > key.jks
54+
3555
- name: Build release
3656
run: ./build.py -vr all
3757

@@ -48,6 +68,88 @@ jobs:
4868
path: out
4969
compression-level: 9
5070

71+
- name: Check for Release
72+
id: check_release
73+
run: |
74+
# fetch all once
75+
git fetch --all
76+
77+
# Set a value for force_release if not set already
78+
force_release=${{ inputs.make_release }}
79+
if [ -z "$force_release" ]; then
80+
force_release="false"
81+
fi
82+
83+
NUM_RELEASES=$(git log -10 --oneline | grep 'Release new canary build' | wc -l)
84+
RELEASE_COMMIT=$(( NUM_RELEASES + RELEASE_COMMIT ))
85+
echo "RELEASE_COMMIT=$RELEASE_COMMIT" >> $GITHUB_ENV
86+
87+
if [[ "${force_release}" == "true" ]]; then
88+
(( RELEASE_COMMIT += 1 ))
89+
echo "RELEASE_COMMIT=$RELEASE_COMMIT" >> $GITHUB_ENV
90+
fi
91+
92+
if [[ $RELEASE_COMMIT -gt 0 ]]; then
93+
echo "Found recent canary build releases."
94+
else
95+
echo "No recent canary build releases found."
96+
fi
97+
98+
- name: Setup Git
99+
if: ${{ env.RELEASE_COMMIT > 0 }}
100+
run: git config --global user.email ${{ secrets.EMAIL }} && git config --global user.name PiX
101+
102+
- name: Fetch commit hash and Magisk version
103+
if: ${{ env.RELEASE_COMMIT > 0 }}
104+
run: |
105+
git fetch origin
106+
echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
107+
108+
echo "MAGISK_VERSION=$(grep 'magisk.versionCode=' gradle.properties | awk -F= '{print $2}')" >> $GITHUB_ENV
109+
110+
- name: Update configs
111+
if: ${{ env.RELEASE_COMMIT > 0 }}
112+
run: |
113+
git checkout magisk-files
114+
echo "Updating Configs for the new release"
115+
116+
jq --arg version "${COMMIT_HASH}" \
117+
--arg versionCode "${MAGISK_VERSION}" \
118+
'.magisk.version = $version |
119+
.magisk.versionCode = $versionCode |
120+
.magisk.link |= sub("canary-[0-9]{5}"; "canary-" + $versionCode) |
121+
.magisk.note |= sub("canary-[0-9]{5}"; "canary-" + $versionCode)' canary.json > canary.json.tmp
122+
mv canary.json.tmp canary.json
123+
124+
jq --arg version "${COMMIT_HASH}" \
125+
--arg versionCode "${MAGISK_VERSION}" \
126+
'.magisk.version = $version |
127+
.magisk.versionCode = $versionCode |
128+
.magisk.link |= sub("canary-[0-9]{5}"; "canary-" + $versionCode) |
129+
.magisk.note |= sub("canary-[0-9]{5}"; "canary-" + $versionCode)' debug.json > debug.json.tmp
130+
mv debug.json.tmp debug.json
131+
132+
git add canary.json debug.json
133+
git commit -m "release: new canary build ${COMMIT_HASH}"
134+
git push origin magisk-files
135+
git checkout master
136+
137+
wget -qO- "https://github.com/topjohnwu/Magisk/releases/download/canary-${MAGISK_VERSION}/notes.md" >> notes.md
138+
echo -e '\n## Diffs to Official Magisk\n\nAdded support for GrapheneOS for personal use' >> notes.md
139+
140+
- name: Release APK
141+
if: ${{ env.RELEASE_COMMIT > 0 }}
142+
uses: "dciborow/[email protected]"
143+
with:
144+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
145+
automatic_release_tag: "canary-${{ env.MAGISK_VERSION }}"
146+
prerelease: true
147+
title: "Magisk (${{ env.COMMIT_HASH }}) (${{ env.MAGISK_VERSION }})"
148+
files: |
149+
out/app-release.apk
150+
out/app-debug.apk
151+
notes.md
152+
51153
- name: Upload mapping and native debug symbols
52154
uses: actions/upload-artifact@v4
53155
with:

.github/workflows/update_fork.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Update Fork
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "30 5 * * *" # runs everyday at 05:30 UTC
7+
8+
permissions:
9+
contents: write
10+
actions: write
11+
12+
jobs:
13+
update_fork:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout Forked Repo
18+
uses: actions/checkout@v4
19+
with:
20+
repository: pixincreate/Magisk
21+
submodules: "recursive"
22+
fetch-depth: 0
23+
24+
- name: Setup Git
25+
run: git config --global user.email ${{ secrets.EMAIL }} && git config --global user.name PiX
26+
27+
- name: Fetch from Upstream
28+
run: |
29+
git remote add upstream https://github.com/topjohnwu/Magisk.git
30+
git fetch upstream master
31+
upstream_commit="$(git rev-parse upstream/master)"
32+
echo "Upstream latest commit: ${upstream_commit}"
33+
for forked_commit in $(git rev-list -n 20 master); do
34+
if [ $upstream_commit != $forked_commit ]; then
35+
has_new_commits=true
36+
continue
37+
else
38+
has_new_commits=false
39+
break
40+
fi
41+
done
42+
if [ $has_new_commits == "true" ]; then
43+
git checkout master
44+
if ! git rebase upstream/master; then
45+
git diff
46+
echo "ERROR: Merge conflict encountered during rebase!"
47+
git rebase --abort
48+
exit 1
49+
fi
50+
git submodule update --init --recursive # Update the submodule
51+
git push -f origin master
52+
echo "Rebase successful!"
53+
else
54+
echo "ERROR: No commits to be synced!"
55+
exit 1
56+
fi
57+
58+
build_app:
59+
needs: update_fork
60+
uses: ./.github/workflows/build.yml
61+
secrets: inherit
62+
63+
# References:
64+
# https://stackoverflow.com/questions/75192546/is-it-possible-to-call-another-workflow-file-from-another-workflow-files-condit/75225285#75225285
65+
# https://stackoverflow.com/questions/75191443/how-to-check-if-upstreams-head-latest-commit-is-present-in-forked-repo
66+
# https://stackoverflow.com/questions/75191328/why-does-git-rebase-upstream-main-behaves-differently-when-used-github-actions
67+
# https://stackoverflow.com/questions/62750603/github-actions-trigger-another-action-after-one-action-is-completed

0 commit comments

Comments
 (0)