Skip to content

Commit 9ab588c

Browse files
committed
[proj] use ci to auto-sync upstream changes
1 parent 18d5cc3 commit 9ab588c

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed

.github/workflows/build.yml

+92-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,76 @@ name: Build AltServer
22

33
on:
44
push:
5+
workflow_dispatch:
6+
inputs:
7+
sync_upstream:
8+
required: false
9+
default: false
10+
debug_enabled:
11+
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
12+
required: false
13+
default: false
14+
repository_dispatch:
15+
16+
schedule:
17+
- cron: "0 */4 * * *" # min hour day week year
18+
519

620
env:
721
REGISTRY: ghcr.io
822

923
jobs:
24+
check:
25+
runs-on: ubuntu-latest
26+
name: "Check Upstream Updates"
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
with:
31+
fetch-depth: 0
32+
submodules: recursive
33+
34+
- name: Check If Need Checking
35+
id: needCheck
36+
if: ${{ github.event_name == 'schedule' || ( github.event_name == 'workflow_dispatch' && github.event.inputs.sync_upstream ) }}
37+
run: |
38+
echo "needCheck=1" >> $GITHUB_ENV
39+
40+
- name: Check Upstream Version
41+
id: check
42+
run: |
43+
if [[ "$needCheck" == 1 ]]; then
44+
echo "Checking changes in upstream_repo..."
45+
46+
current_upstream=$(git ls-tree HEAD upstream_repo | awk '{ print $3 }')
47+
echo "Current Upstream Commit: $current_upstream"
48+
49+
git submodule update --remote -- upstream_repo
50+
new_upstream=$( cd upstream_repo; git show -s --format=%H )
51+
echo "New Upstream Commit: $new_upstream"
52+
53+
git reset --hard
54+
git submodule update --init
55+
if [[ "$current_upstream" != "$new_upstream" ]]; then
56+
echo "Upstream got new commits, go updating!"
57+
echo "::set-output name=updated::1"
58+
else
59+
echo "Upstream no change~"
60+
echo "::set-output name=updated::0"
61+
fi
62+
else
63+
echo "Needn't to check changes, directly return~"
64+
echo "::set-output name=updated::0"
65+
fi
66+
67+
- uses: gautamkrishnar/keepalive-workflow@master
68+
with:
69+
commit_message: "[proj] keepalive-workflow auto commit"
70+
outputs:
71+
updated: ${{ steps.check.outputs.updated }}
72+
1073
build:
74+
needs: [check]
1175
strategy:
1276
matrix:
1377
builder: [ghcr.io/nyamisty/altserver_builder_alpine_armv7, ghcr.io/nyamisty/altserver_builder_alpine_aarch64, ghcr.io/nyamisty/altserver_builder_alpine_amd64, ghcr.io/nyamisty/altserver_builder_alpine_i386]
@@ -18,6 +82,10 @@ jobs:
1882
with:
1983
fetch-depth: 0
2084
submodules: recursive
85+
- name: Do Submodule Update
86+
if: ${{ needs.check.outputs.updated == '1' }}
87+
run:
88+
git submodule update --remote -- upstream_repo
2189
-
2290
name: Set up QEMU
2391
uses: docker/setup-qemu-action@v1
@@ -44,6 +112,7 @@ jobs:
44112

45113
release:
46114
runs-on: ubuntu-latest
115+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
47116
needs: [build]
48117
name: "release"
49118
steps:
@@ -63,9 +132,30 @@ jobs:
63132
if [ "$(ls -A build_release)" ]; then exit 0; else exit 1; fi
64133
- name: Release
65134
uses: softprops/action-gh-release@v1
66-
if: ${{ startsWith(github.ref, 'refs/tags/') }}
67135
with:
68136
files: build_release/*
69137
env:
70138
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
139+
140+
update_submodule:
141+
runs-on: ubuntu-latest
142+
needs: [check, build]
143+
if: ${{ needs.check.outputs.updated == '1' }}
144+
steps:
145+
- name: Checkout
146+
uses: actions/checkout@v2
147+
with:
148+
fetch-depth: 0
149+
submodules: recursive
150+
- name: Commit Submodule Update
151+
run: |
152+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
153+
git config --local user.name "github-actions[bot]"
154+
git submodule update --remote -- upstream_repo
155+
git commit -m "[server] Sync Upstream Repo commit" upstream_repo
156+
- name: Push changes
157+
uses: ad-m/github-push-action@master
158+
with:
159+
github_token: ${{ secrets.GITHUB_TOKEN }}
160+
branch: ${{ github.ref }}
161+

0 commit comments

Comments
 (0)