Skip to content

Commit

Permalink
ci(gh-actions): setup ci for auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
pixincreate committed Dec 2, 2024
1 parent 542ed78 commit 0aae03c
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ on:
pull_request:
branches: [master]
workflow_dispatch:
inputs:
make_release:
default: false
description: Make a forced release
required: false
type: boolean
workflow_call:

jobs:
build:
Expand All @@ -24,13 +31,26 @@ jobs:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: "recursive"

- name: Setup environment
uses: ./.github/actions/setup
with:
is-asset-build: true

- name: Setup keystores
run: |
cat > config.prop<< EOF
keyStore=key.jks
keyStorePass=${{ secrets.KEYSTORE_ALIAS_PASSWORD }}
keyAlias=${{ secrets.KEYSTORE_ALIAS_NAME }}
keyPass=${{ secrets.KEYSTORE_PASSWORD }}
EOF
echo '${{ secrets.KEYSTORE_FILE }}' > keystore.jks.asc
gpg -d --passphrase '${{ secrets.KEYSTORE_PASSWORD_GPG }}' --batch keystore.jks.asc > key.jks
- name: Build release
run: ./build.py -vr all

Expand All @@ -47,6 +67,85 @@ jobs:
path: out
compression-level: 9

- name: Check for Release
id: check_release
run: |
# Set default value for force_release if not set
force_release=${{ inputs.make_release }}
if [ -z "$force_release" ]; then
force_release="false"
fi
NUM_RELEASES=$(git log -10 --oneline | grep 'Release new canary build' | wc -l)
RELEASE_COMMIT=$(( NUM_RELEASES + RELEASE_COMMIT ))
echo "RELEASE_COMMIT=$RELEASE_COMMIT" >> $GITHUB_ENV
if [[ "${force_release}" == "true" ]]; then
(( RELEASE_COMMIT += 1 ))
echo "RELEASE_COMMIT=$RELEASE_COMMIT" >> $GITHUB_ENV
fi
if [[ $RELEASE_COMMIT -gt 0 ]]; then
echo "Found recent canary build releases."
else
echo "No recent canary build releases found."
fi
- name: Setup Git
if: ${{ env.RELEASE_COMMIT > 0 }}
run: git config --global user.email ${{ secrets.EMAIL }} && git config --global user.name PiX

- name: Fetch commit hash and Magisk version
if: ${{ env.RELEASE_COMMIT > 0 }}
run: |
git fetch origin
echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "MAGISK_VERSION=$(grep 'magisk.versionCode=' gradle.properties | awk -F= '{print $2}')" >> $GITHUB_ENV
- name: Update configs
if: ${{ env.RELEASE_COMMIT > 0 }}
run: |
git checkout magisk-files
echo "Updating Configs for the new release"
jq --arg version "${COMMIT_HASH}" \
--arg versionCode "${MAGISK_VERSION}" \
'.magisk.version = $version |
.magisk.versionCode = $versionCode |
.magisk.link |= sub("canary-[0-9]{5}"; "canary-" + $versionCode) |
.magisk.note |= sub("canary-[0-9]{5}"; "canary-" + $versionCode)' canary.json > canary.json.tmp
mv canary.json.tmp canary.json
jq --arg version "${COMMIT_HASH}" \
--arg versionCode "${MAGISK_VERSION}" \
'.magisk.version = $version |
.magisk.versionCode = $versionCode |
.magisk.link |= sub("canary-[0-9]{5}"; "canary-" + $versionCode) |
.magisk.note |= sub("canary-[0-9]{5}"; "canary-" + $versionCode)' debug.json > debug.json.tmp
mv debug.json.tmp debug.json
git add canary.json debug.json
git commit -m "release: new canary build ${COMMIT_HASH}"
git push origin magisk-files
git checkout master
wget -qO- "https://github.com/topjohnwu/Magisk/releases/download/canary-${MAGISK_VERSION}/notes.md" >> notes.md
echo -e '\n## Diffs to Official Magisk\n\nAdded support for GrapheneOS for personal use' >> notes.md
- name: Release APK
if: ${{ env.RELEASE_COMMIT > 0 }}
uses: "dciborow/[email protected]"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "canary-${{ env.MAGISK_VERSION }}"
prerelease: true
title: "Magisk (${{ env.COMMIT_HASH }}) (${{ env.MAGISK_VERSION }})"
files: |
out/app-release.apk
out/app-debug.apk
notes.md
- name: Upload mapping and native debug symbols
uses: actions/upload-artifact@v4
with:
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/update_fork.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Update Fork

on:
workflow_dispatch:
schedule:
- cron: "30 5 * * *" # runs everyday at 05:30 UTC

permissions:
contents: write
actions: write

jobs:
update_fork:
runs-on: ubuntu-latest

steps:
- name: Checkout Forked Repo
uses: actions/checkout@v4
with:
repository: pixincreate/Magisk
submodules: "recursive"
fetch-depth: 0

- name: Setup Git
run: git config --global user.email ${{ secrets.EMAIL }} && git config --global user.name PiX

- name: Fetch from Upstream
run: |
git remote add upstream https://github.com/topjohnwu/Magisk.git
git fetch upstream master
upstream_commit="$(git rev-parse upstream/master)"
echo "Upstream latest commit: ${upstream_commit}"
for forked_commit in $(git rev-list -n 20 master); do
if [ $upstream_commit != $forked_commit ]; then
has_new_commits=true
continue
else
has_new_commits=false
break
fi
done
if [ $has_new_commits == "true" ]; then
git checkout master
if ! git rebase upstream/master; then
git diff
echo "ERROR: Merge conflict encountered during rebase!"
git rebase --abort
exit 1
fi
git submodule update --init --recursive # Update the submodule
git push -f origin master
echo "Rebase successful!"
else
echo "ERROR: No commits to be synced!"
exit 1
fi
build_app:
needs: update_fork
uses: ./.github/workflows/build.yml
secrets: inherit

# References:
# https://stackoverflow.com/questions/75192546/is-it-possible-to-call-another-workflow-file-from-another-workflow-files-condit/75225285#75225285
# https://stackoverflow.com/questions/75191443/how-to-check-if-upstreams-head-latest-commit-is-present-in-forked-repo
# https://stackoverflow.com/questions/75191328/why-does-git-rebase-upstream-main-behaves-differently-when-used-github-actions
# https://stackoverflow.com/questions/62750603/github-actions-trigger-another-action-after-one-action-is-completed

0 comments on commit 0aae03c

Please sign in to comment.