Skip to content

Commit

Permalink
add automatic updating pipeline
Browse files Browse the repository at this point in the history
* force clean exit when nothing changed in update.sh
* fix pushing from subbranch
* force populate GITHUB_TOKEN environment variable
  • Loading branch information
programminghoch10 committed Aug 26, 2023
1 parent 4a1c980 commit cb21576
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/autoupdate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Automatic Update

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

concurrency:
group: update
cancel-in-progress: false

jobs:
update:
name: Update Hosts
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup git
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Run update.sh
run: ./update.sh
build:
name: Build
needs: update
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run compile.sh
run: ./compile.sh
- name: Upload Build Result
uses: actions/upload-artifact@v3
with:
name: MagicalProtection.zip
path: |
MagicalProtection-*.zip
if-no-files-found: error
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup git
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Download Build Result
uses: actions/download-artifact@v3
with:
name: MagicalProtection.zip
- name: Run deploy.sh
run: ./deploy.sh
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup git
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Compile
run: ./compile.sh
- name: Upload Result
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Magisk-only completely systemless adblocking.
[![GitHub Global Download Counter](https://img.shields.io/github/downloads/programminghoch10/MagicalProtection/total?logo=github)](https://github.com/programminghoch10/MagicalProtection/releases)
[![GitHub Latest Download Counter](https://img.shields.io/github/downloads/programminghoch10/MagicalProtection/latest/total?logo=github)](https://github.com/programminghoch10/MagicalProtection/releases/latest) \
[![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)
[![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)
[![GitHub last commit](https://img.shields.io/github/last-commit/programminghoch10/MagicalProtection?logo=git&logoColor=white)](https://github.com/programminghoch10/MagicalProtection/commits/main) \
[![GitHub Repo stars](https://img.shields.io/github/stars/programminghoch10/MagicalProtection?style=social)](https://github.com/programminghoch10/MagicalProtection/stargazers) \
[![GitHub followers](https://img.shields.io/github/followers/programminghoch10?style=social)](https://github.com/programminghoch10)
Expand Down
2 changes: 1 addition & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ IFS=$'\n'
cd "$(dirname "$(readlink -f "$0")")"

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

for cmd in git curl jq; do
[ -z "$(command -v "$cmd")" ] && echo "missing $cmd" && exit 1
Expand Down
3 changes: 2 additions & 1 deletion update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function checkOutBranch() {
mkdir "$folder"
git clone -q $(pwd) "$folder"
cd "$folder"
git config --local push.autoSetupRemote true
git fetch -q origin "$branch":"$branch"
git checkout -q "$branch"
cd ..
Expand Down Expand Up @@ -87,7 +88,7 @@ done < lists.txt
(
cd hosts
git add .
git commit -m "Update lists"
git commit -m "Update lists" || true
git push -q
)

Expand Down

0 comments on commit cb21576

Please sign in to comment.