Skip to content

Commit cb21576

Browse files
add automatic updating pipeline
* force clean exit when nothing changed in update.sh * fix pushing from subbranch * force populate GITHUB_TOKEN environment variable
1 parent 4a1c980 commit cb21576

File tree

5 files changed

+70
-6
lines changed

5 files changed

+70
-6
lines changed

.github/workflows/autoupdate.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Automatic Update
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
8+
env:
9+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10+
11+
concurrency:
12+
group: update
13+
cancel-in-progress: false
14+
15+
jobs:
16+
update:
17+
name: Update Hosts
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
- name: Setup git
25+
run: |
26+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
27+
git config --global user.name "github-actions[bot]"
28+
- name: Run update.sh
29+
run: ./update.sh
30+
build:
31+
name: Build
32+
needs: update
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v3
37+
with:
38+
fetch-depth: 0
39+
- name: Run compile.sh
40+
run: ./compile.sh
41+
- name: Upload Build Result
42+
uses: actions/upload-artifact@v3
43+
with:
44+
name: MagicalProtection.zip
45+
path: |
46+
MagicalProtection-*.zip
47+
if-no-files-found: error
48+
deploy:
49+
name: Deploy
50+
needs: build
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v3
55+
with:
56+
fetch-depth: 0
57+
- name: Setup git
58+
run: |
59+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
60+
git config --global user.name "github-actions[bot]"
61+
- name: Download Build Result
62+
uses: actions/download-artifact@v3
63+
with:
64+
name: MagicalProtection.zip
65+
- name: Run deploy.sh
66+
run: ./deploy.sh

.github/workflows/build.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ jobs:
1111
uses: actions/checkout@v3
1212
with:
1313
fetch-depth: 0
14-
- name: Setup git
15-
run: |
16-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
17-
git config --global user.name "github-actions[bot]"
1814
- name: Compile
1915
run: ./compile.sh
2016
- name: Upload Result

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Magisk-only completely systemless adblocking.
66
[![GitHub Global Download Counter](https://img.shields.io/github/downloads/programminghoch10/MagicalProtection/total?logo=github)](https://github.com/programminghoch10/MagicalProtection/releases)
77
[![GitHub Latest Download Counter](https://img.shields.io/github/downloads/programminghoch10/MagicalProtection/latest/total?logo=github)](https://github.com/programminghoch10/MagicalProtection/releases/latest) \
88
[![GitHub Build Workflow Status](https://img.shields.io/github/actions/workflow/status/programminghoch10/MagicalProtection/build.yml?logo=github%20actions&logoColor=white)](https://github.com/programminghoch10/MagicalProtection/actions/workflows/build.yml)
9+
[![GitHub Automatic Update Workflow Status](https://img.shields.io/github/actions/workflow/status/programminghoch10/MagicalProtection/autoupdate.yml?logo=github%20actions&logoColor=white)](https://github.com/programminghoch10/MagicalProtection/actions/workflows/autoupdate.yml)
910
[![GitHub last commit](https://img.shields.io/github/last-commit/programminghoch10/MagicalProtection?logo=git&logoColor=white)](https://github.com/programminghoch10/MagicalProtection/commits/main) \
1011
[![GitHub Repo stars](https://img.shields.io/github/stars/programminghoch10/MagicalProtection?style=social)](https://github.com/programminghoch10/MagicalProtection/stargazers) \
1112
[![GitHub followers](https://img.shields.io/github/followers/programminghoch10?style=social)](https://github.com/programminghoch10)

deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ IFS=$'\n'
66
cd "$(dirname "$(readlink -f "$0")")"
77

88
[ -f .gitauth ] && source .gitauth
9-
[ -z "$GITHUB_TOKEN" ] && echo "missing GITHUB_TOKEN" && exit 1
9+
[ -z "${GITHUB_TOKEN-}" ] && echo "missing GITHUB_TOKEN" && exit 1
1010

1111
for cmd in git curl jq; do
1212
[ -z "$(command -v "$cmd")" ] && echo "missing $cmd" && exit 1

update.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function checkOutBranch() {
1818
mkdir "$folder"
1919
git clone -q $(pwd) "$folder"
2020
cd "$folder"
21+
git config --local push.autoSetupRemote true
2122
git fetch -q origin "$branch":"$branch"
2223
git checkout -q "$branch"
2324
cd ..
@@ -87,7 +88,7 @@ done < lists.txt
8788
(
8889
cd hosts
8990
git add .
90-
git commit -m "Update lists"
91+
git commit -m "Update lists" || true
9192
git push -q
9293
)
9394

0 commit comments

Comments
 (0)