@@ -2,17 +2,10 @@ name: 4. Build Loop
22run-name : Build Loop (${{ github.ref_name }})
33on :
44 workflow_dispatch :
5-
6- # # Remove the "#" sign from the beginning of the line below to get automated builds on push (code changes in your repository)
7- # push:
8-
9- # Automated builds now include automatic certificate update - the nuke certs part of that process could
10- # affect other OS apps if run simultaneously.
11- # Each OS needs a time of day distinct from other apps, LoopWorkspace uses 9 every Wed and 7 every 1st of month
125 schedule :
13- # avoid starting an action at hh:00 when GitHub resources are impacted
14- - cron : " 33 9 * * 3 " # Checks for updates at 09:33 UTC every Wednesday
15- - cron : " 33 7 1 * *" # Builds the app on the 1st of every month at 07 :33 UTC
6+ # Check for updates every Sunday
7+ # Later logic builds if there are updates or if it is the 2nd Sunday of the month
8+ - cron : " 33 7 * * 0 " # Sunday at UTC 7 :33
169
1710env :
1811 UPSTREAM_REPO : LoopKit/LoopWorkspace
2215 ALIVE_BRANCH_DEV : alive-dev
2316
2417jobs :
18+
19+ # Set a logic flag if this is the second instance of this day-of-week in this month
20+ day_in_month :
21+ runs-on : ubuntu-latest
22+ name : Check day in month
23+ outputs :
24+ IS_SECOND_IN_MONTH : ${{ steps.date-check.outputs.is_second_instance }}
25+
26+ steps :
27+ - id : date-check
28+ name : Check if this is the second time this day-of-week happens this month
29+ run : |
30+ DAY_OF_MONTH=$(date +%-d)
31+ WEEK_OF_MONTH=$(( ($(date +%-d) - 1) / 7 + 1 ))
32+ if [[ $WEEK_OF_MONTH -eq 2 ]]; then
33+ echo "is_second_instance=true" >> "$GITHUB_OUTPUT"
34+ else
35+ echo "is_second_instance=false" >> "$GITHUB_OUTPUT"
36+ fi
37+
2538 # Checks if Distribution certificate is present and valid, optionally nukes and
2639 # creates new certs if the repository variable ENABLE_NUKE_CERTS == 'true'
2740 check_certs :
@@ -193,15 +206,15 @@ jobs:
193206 # Builds Loop
194207 build :
195208 name : Build
196- needs : [check_certs, check_alive_and_permissions, check_latest_from_upstream]
209+ needs : [check_certs, check_alive_and_permissions, check_latest_from_upstream, day_in_month ]
197210 runs-on : macos-15
198211 permissions :
199212 contents : write
200213 if :
201- | # runs if started manually, or if sync schedule is set and enabled and scheduled on the first Saturday each month, or if sync schedule is set and enabled and new commits were found
214+ | # builds with manual start; if automatic: once a month or when new commits are found
202215 github.event_name == 'workflow_dispatch' ||
203216 (needs.check_alive_and_permissions.outputs.WORKFLOW_PERMISSION == 'true' &&
204- (vars.SCHEDULED_BUILD != 'false' && github.event.schedule == '33 7 1 * * ') ||
217+ (vars.SCHEDULED_BUILD != 'false' && needs.day_in_month.outputs.IS_SECOND_IN_MONTH == 'true ') ||
205218 (vars.SCHEDULED_SYNC != 'false' && needs.check_latest_from_upstream.outputs.NEW_COMMITS == 'true' )
206219 )
207220 steps :
@@ -334,4 +347,4 @@ jobs:
334347 name : build-artifacts
335348 path : |
336349 artifacts
337- buildlog
350+ buildlog
0 commit comments