Skip to content
Merged
40 changes: 28 additions & 12 deletions .github/workflows/build_LoopFollow.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
name: 4. Build Loop Follow
run-name: Build Loop Follow (${{ github.ref_name }})
name: 4. Build LoopFollow
run-name: Build LoopFollow (${{ github.ref_name }})
on:
workflow_dispatch:

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

schedule:
# avoid starting an action at times when GitHub resources are impacted
- cron: "17 12 * * 0" # Checks for updates at 12:17 UTC every Sunday
- cron: "17 10 8-14 * 6" # Builds the app on the second Saturday of each month 10:17 UTC
# Check for updates every Sunday
# Later logic builds if there are updates or if it is the 2nd Sunday of the month
- cron: "17 10 * * 0" # Sunday at UTC 10:17

env:
UPSTREAM_REPO: loopandlearn/LoopFollow
Expand All @@ -19,6 +15,26 @@ env:
ALIVE_BRANCH_DEV: alive-dev

jobs:

# Set a logic flag if this is the second instance of this day-of-week in this month
day_in_month:
runs-on: ubuntu-latest
name: Check day in month
outputs:
IS_SECOND_IN_MONTH: ${{ steps.date-check.outputs.is_second_instance }}

steps:
- id: date-check
name: Check if this is the second time this day-of-week happens this month
run: |
DAY_OF_MONTH=$(date +%-d)
WEEK_OF_MONTH=$(( ($(date +%-d) - 1) / 7 + 1 ))
if [[ $WEEK_OF_MONTH -eq 2 ]]; then
echo "is_second_instance=true" >> "$GITHUB_OUTPUT"
else
echo "is_second_instance=false" >> "$GITHUB_OUTPUT"
fi

# Checks if Distribution certificate is present and valid, optionally nukes and
# creates new certs if the repository variable ENABLE_NUKE_CERTS == 'true'
check_certs:
Expand Down Expand Up @@ -190,15 +206,15 @@ jobs:
# Builds LoopFollow
build:
name: Build
needs: [check_certs, check_alive_and_permissions, check_latest_from_upstream]
needs: [check_certs, check_alive_and_permissions, check_latest_from_upstream, day_in_month]
runs-on: macos-15
permissions:
contents: write
if:
| # 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
| # builds with manual start; if automatic: once a month or when new commits are found
github.event_name == 'workflow_dispatch' ||
(needs.check_alive_and_permissions.outputs.WORKFLOW_PERMISSION == 'true' &&
(vars.SCHEDULED_BUILD != 'false' && github.event.schedule == '17 10 8-14 * 6') ||
(vars.SCHEDULED_BUILD != 'false' && needs.day_in_month.outputs.IS_SECOND_IN_MONTH == 'true') ||
(vars.SCHEDULED_SYNC != 'false' && needs.check_latest_from_upstream.outputs.NEW_COMMITS == 'true' )
)
steps:
Expand Down