Auto-update #232
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Auto-update' | |
# Runs only on schedule for the default branch | |
# TARGET_BRANCH should be set as default (normally the `main` branch) | |
# Syncs the target branch with upstream | |
# Checks for activity and creates empty commits to TARGET_BRANCH as needed after 'time_elapsed' days of inactivity | |
# Launches the build workflow if new commits are found. | |
# The build workflow syncs and builds the main branch and uploads to TestFlight | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 4 * * *' # scheduled at 04:00 UTC every day | |
env: | |
UPSTREAM_REPO: Artificial-Pancreas/iAPS | |
UPSTREAM_BRANCH: dev # ${{ github.ref_name }} # branch on upstream repository to sync from | |
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) | |
jobs: | |
check_latest_from_upstream: | |
runs-on: ubuntu-latest | |
name: Check upstream | |
outputs: | |
NEW_COMMITS: ${{ steps.sync.outputs.has_new_commits }} | |
steps: | |
# Step 1: run a standard checkout action | |
- name: Checkout target repo | |
uses: actions/checkout@v3 | |
with: | |
# optional: set the branch to checkout, | |
# sync action checks out your 'target_sync_branch' anyway | |
ref: ${{ env.TARGET_BRANCH }} | |
# Step 2: run the sync action | |
- name: Sync upstream changes | |
if: github.repository_owner != 'Artificial-Pancreas' # do not run the upstream sync action on the upstream repository | |
id: sync | |
uses: aormsby/[email protected] | |
with: | |
target_sync_branch: ${{ env.TARGET_BRANCH }} | |
shallow_since: 6 months ago | |
target_repo_token: ${{ secrets.GH_PAT }} | |
upstream_sync_branch: ${{ env.UPSTREAM_BRANCH }} | |
upstream_sync_repo: ${{ env.UPSTREAM_REPO }} | |
# Step 3: Display a sample message based on the sync output var 'has_new_commits' | |
- name: New commits found | |
if: steps.sync.outputs.has_new_commits == 'true' | |
run: echo "New commits were found to sync." | |
- name: No new commits | |
if: steps.sync.outputs.has_new_commits == 'false' | |
run: echo echo "There were no new commits." | |
- name: Show value of 'has_new_commits' | |
run: | | |
echo ${{ steps.sync.outputs.has_new_commits }} | |
echo "NEW_COMMITS=${{ steps.sync.outputs.has_new_commits }}" >> $GITHUB_OUTPUT | |
# Keep repository "alive": add empty commits to TARGET_BRANCH after "time_elapsed" days of inactivity to avoid inactivation of scheduled workflows | |
- name: Keep alive | |
uses: gautamkrishnar/keepalive-workflow@v1 | |
with: | |
time_elapsed: 50 # Time elapsed from the previous commit to trigger a new automated commit (in days) | |
# Launch build workflow on fork if new commits are found | |
launch_build_workflow: | |
if: needs.check_latest_from_upstream.outputs.NEW_COMMITS == 'true' | |
needs: check_latest_from_upstream | |
name: Launch build workflow | |
uses: ./.github/workflows/build_iAPS.yml | |
secrets: inherit |