Skip to content

Commit 09ddc70

Browse files
authored
Move update and keep alive features to build_loop.yml
- Checks for updates nightly - Ensures repository activity - Launches Build job if new commits are found, or if run manually - Workflow file cleanup
1 parent a4cad5b commit 09ddc70

File tree

1 file changed

+83
-15
lines changed

1 file changed

+83
-15
lines changed

.github/workflows/build_loop.yml

Lines changed: 83 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,107 @@ name: 4. Build Loop
22
run-name: Build Loop (${{ github.ref_name }})
33
on:
44
workflow_dispatch:
5-
workflow_call:
65

76
## Remove the "#" sign from the beginning of the line below to get automated builds on push (code changes in your repository)
87
#push:
98

109
schedule:
11-
- cron: '30 04 1 * *' # Runs at 04:30 UTC on the 1st every month
10+
- cron: '0 04 * * *' # Checks for updates at 04:00 UTC every day
11+
- cron: '0 04 1 * *' # Builds the app on the 1th every month
1212

1313
env:
14-
BUILD_BRANCH: ${{ github.ref_name }} # branch on fork to build from (relpace with specific branch name if needed)
14+
UPSTREAM_REPO: LoopKit/LoopWorkspace
15+
UPSTREAM_BRANCH: ${{ github.ref_name }} # branch on upstream repository to sync from (relpace with specific branch name if needed)
16+
TARGET_BRANCH: ${{ github.ref_name }} # target branch on fork to be kept in sync, and target branch on upstream to be kept alive (relpace with specific branch name if needed)
17+
ALIVE_BRANCH: alive
18+
SYNC_UPSTREAM: 'true' # set to 'false' or 'true' to disable / enable syncing of fork with upstream repository
1519

1620
jobs:
17-
secrets:
18-
name: Secrets
19-
uses: ./.github/workflows/validate_secrets.yml
20-
secrets: inherit
21+
check_latest_from_upstream:
22+
runs-on: ubuntu-latest
23+
name: Check upstream and keep alive
24+
outputs:
25+
NEW_COMMITS: ${{ steps.sync.outputs.has_new_commits }}
2126

27+
steps:
28+
- name: Checkout target repo
29+
uses: actions/checkout@v3
30+
with:
31+
token: ${{ secrets.GH_PAT }}
32+
ref: alive
33+
34+
- name: Sync upstream changes
35+
if: ${{ env.SYNC_UPSTREAM == 'true' }} && github.repository_owner != 'LoopKit' # do not run the upstream sync action on the upstream repository
36+
id: sync
37+
uses: aormsby/[email protected]
38+
with:
39+
target_sync_branch: ${{ env.ALIVE_BRANCH }}
40+
shallow_since: 6 months ago
41+
target_repo_token: ${{ secrets.GH_PAT }}
42+
upstream_sync_branch: ${{ env.UPSTREAM_BRANCH }}
43+
upstream_sync_repo: ${{ env.UPSTREAM_REPO }}
44+
45+
# Display a sample message based on the sync output var 'has_new_commits'
46+
- name: New commits found
47+
if: steps.sync.outputs.has_new_commits == 'true'
48+
run: echo "New commits were found to sync."
49+
50+
- name: No new commits
51+
if: steps.sync.outputs.has_new_commits == 'false'
52+
run: echo "There were no new commits."
53+
54+
- name: Show value of 'has_new_commits'
55+
run: |
56+
echo ${{ steps.sync.outputs.has_new_commits }}
57+
echo "NEW_COMMITS=${{ steps.sync.outputs.has_new_commits }}" >> $GITHUB_OUTPUT
58+
59+
# Keep repository "alive": add empty commits to ALIVE_BRANCH after "time_elapsed" days of inactivity to avoid inactivation of scheduled workflows
60+
- name: Keep alive
61+
uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow with default settings
62+
with:
63+
time_elapsed: 20 # Time elapsed from the previous commit to trigger a new automated commit (in days)
64+
2265
build:
2366
name: Build
24-
needs: secrets
25-
runs-on: macos-12
67+
needs: check_latest_from_upstream
68+
runs-on: macos-13
69+
if: ${{ github.event_name == 'workflow_dispatch' || github.event.schedule == '0 04 1 * *' || needs.check_latest_from_upstream.outputs.NEW_COMMITS == 'true' }} # runs if started manually, or if scheduled on the first each month, or if new commits were found
2670
steps:
27-
# Uncomment to manually select latest Xcode if needed
28-
- name: Select Latest Xcode
29-
run: "sudo xcode-select --switch /Applications/Xcode_14.1.app/Contents/Developer"
71+
- name: Select Xcode version
72+
run: "sudo xcode-select --switch /Applications/Xcode_14.3.1.app/Contents/Developer"
3073

31-
# Checks-out the repo
3274
- name: Checkout Repo
3375
uses: actions/checkout@v3
3476
with:
77+
token: ${{ secrets.GH_PAT }}
3578
submodules: recursive
36-
ref: ${{ env.BUILD_BRANCH }}
37-
79+
ref: ${{ env.TARGET_BRANCH }}
80+
81+
- name: Sync upstream changes
82+
if: ${{ env.SYNC_UPSTREAM == 'true' }} && github.repository_owner != 'LoopKit' # do not run the upstream sync action on the upstream repository
83+
id: sync
84+
uses: aormsby/[email protected]
85+
with:
86+
target_sync_branch: ${{ env.TARGET_BRANCH }}
87+
shallow_since: 6 months ago
88+
target_repo_token: ${{ secrets.GH_PAT }}
89+
upstream_sync_branch: ${{ env.UPSTREAM_BRANCH }}
90+
upstream_sync_repo: ${{ env.UPSTREAM_REPO }}
91+
92+
# Display a sample message based on the sync output var 'has_new_commits'
93+
- name: New commits found
94+
if: steps.sync.outputs.has_new_commits == 'true'
95+
run: echo "New commits were found to sync."
96+
97+
- name: No new commits
98+
if: steps.sync.outputs.has_new_commits == 'false'
99+
run: echo "There were no new commits."
100+
101+
- name: Show value of 'has_new_commits'
102+
run: |
103+
echo ${{ steps.sync.outputs.has_new_commits }}
104+
echo "NEW_COMMITS=${{ steps.sync.outputs.has_new_commits }}" >> $GITHUB_OUTPUT
105+
38106
# Customize Loop: Download and apply patches
39107
- name: Customize Loop
40108
run: |

0 commit comments

Comments
 (0)