Skip to content

Commit 43a1192

Browse files
committed
Create update.yml
- runs on a frequent schedule - checks out LoopWorkspace `main` - compares and syncs with LoopKit/LoopWorkspace (unless owner = LoopKit) - keepalive action adds empty commits to LoopKit/LoopWorkspace `main` after `time_elapsed` days to to avoid inactivation of scheduled workflows, when these updates are passed on to forks (only if owner = LoopKit) - launches build_loop.yml workflow on forks to sync and build if new commits are found (unless owner = LoopKit)
1 parent b21bada commit 43a1192

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

.github/workflows/update.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: 'Auto-update'
2+
3+
on:
4+
schedule:
5+
- cron: '0 7 * * 1,4'
6+
# scheduled at 07:00 every Monday and Thursday
7+
8+
workflow_dispatch: # click the button on Github repo!
9+
10+
env:
11+
UPSTREAM_REPO: LoopKit/LoopWorkspace
12+
UPSTREAM_BRANCH: main
13+
TARGET_BRANCH: main
14+
15+
jobs:
16+
check_latest_from_upstream:
17+
runs-on: ubuntu-latest
18+
name: Check latest commits from upstream repo
19+
outputs:
20+
NEW_COMMITS: ${{ steps.sync.outputs.has_new_commits }}
21+
22+
steps:
23+
# REQUIRED step
24+
# Step 1: run a standard checkout action, provided by github
25+
- name: Checkout target repo
26+
uses: actions/checkout@v3
27+
with:
28+
# optional: set the branch to checkout,
29+
# sync action checks out your 'target_sync_branch' anyway
30+
#submodules: recursive
31+
ref: ${{ env.TARGET_BRANCH }}
32+
33+
# REQUIRED step
34+
# Step 2: run the sync action
35+
- name: Sync upstream changes
36+
if: (github.repository_owner != 'LoopKit')
37+
id: sync
38+
uses: aormsby/[email protected]
39+
with:
40+
target_sync_branch: ${{ env.TARGET_BRANCH }}
41+
#target_branch_checkout_args: --recurse-submodules
42+
shallow_since: 6 months ago
43+
# REQUIRED 'target_repo_token' exactly like this!
44+
target_repo_token: ${{ secrets.GH_PAT }}
45+
upstream_sync_branch: ${{ env.UPSTREAM_BRANCH }}
46+
upstream_sync_repo: ${{ env.UPSTREAM_REPO }}
47+
48+
# Step 3: Display a sample message based on the sync output var 'has_new_commits'
49+
- name: New commits found
50+
if: steps.sync.outputs.has_new_commits == 'true'
51+
run: echo "New commits were found to sync."
52+
53+
- name: No new commits
54+
if: steps.sync.outputs.has_new_commits == 'false'
55+
run: echo echo "There were no new commits."
56+
57+
- name: Show value of 'has_new_commits'
58+
run: |
59+
echo ${{ steps.sync.outputs.has_new_commits }}
60+
echo "NEW_COMMITS=${{ steps.sync.outputs.has_new_commits }}" >> $GITHUB_OUTPUT
61+
62+
# Keep upstream repository "alive": add empty commits after "time_elapsed" days to avoid inactivation of scheduled workflows
63+
- name: Keep alive
64+
if: (github.ref == 'refs/heads/main' && github.repository_owner == 'LoopKit')
65+
uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow with default settings
66+
with:
67+
time_elapsed: 27 # Time elapsed from the previous commit to trigger a new automated commit (in days)
68+
69+
# Launch build workflow if new commits are found
70+
launch_build_workflow:
71+
if: needs.check_latest_from_upstream.outputs.NEW_COMMITS == 'true' && (github.repository_owner != 'LoopKit')
72+
needs: check_latest_from_upstream
73+
name: Launch build workflow
74+
uses: ./.github/workflows/build_loop.yml
75+
secrets: inherit

0 commit comments

Comments
 (0)