Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scheduled sync and build, template for customization of Loop #48

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 72 additions & 10 deletions .github/workflows/build_loop.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
name: 4. Build Loop
run-name: Build Loop
run-name: Build Loop ${{ github.ref_name }}
on:
workflow_dispatch:

workflow_call:

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

## Remove the "#" sign from the beginning of the two lines below to get automated builds every two months
#schedule:
#- cron: '0 17 1 */2 *' # Runs at 17:00 UTC on the 1st in Jan, Mar, May, Jul, Sep and Nov.
env:
UPSTREAM_REPO: LoopKit/LoopWorkspace
UPSTREAM_BRANCH: main # upstream branch to sync from
TARGET_BRANCH: main # branch on fork to build from
SYNC_UPSTREAM: 'true' # set to 'false' or 'true' to disable / enable syncing of fork with upstream repository

jobs:
secrets:
name: Secrets
uses: ./.github/workflows/validate_secrets.yml
secrets: inherit

build:

upstream_sync_and_build:
name: build
needs: secrets
runs-on: macos-12
steps:
Expand All @@ -28,11 +33,68 @@ jobs:
uses: actions/checkout@v3
with:
submodules: recursive

ref: ${{ env.TARGET_BRANCH }}

# Run the sync action
- name: Sync upstream changes
if: ${{ env.SYNC_UPSTREAM == 'true' }}
id: sync
uses: aormsby/[email protected]
with:
target_sync_branch: ${{ env.TARGET_BRANCH }}
target_branch_checkout_args: --recurse-submodules
shallow_since: 6 months ago
# REQUIRED 'target_repo_token' exactly like this!
target_repo_token: ${{ secrets.GH_PAT }}
upstream_sync_branch: ${{ env.UPSTREAM_BRANCH }}
upstream_sync_repo: ${{ env.UPSTREAM_REPO }}
# upstream_repo_access_token: ${{ secrets.UPSTREAM_REPO_SECRET }}

# 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 "There were no new commits."

- name: Show value of 'has_new_commits'
run: echo ${{ steps.sync.outputs.has_new_commits }}

# Customize Loop: Download and apply patches
- name: Customize Loop
run: |

# LoopWorkspace patches
# -applies any patches located in the LoopWorkspace/patches/ directory
if $(ls ./patches/* &> /dev/null); then
git apply ./patches/* --allow-empty -v --whitespace=fix
fi

# For more information,
# see: https://loopkit.github.io/loopdocs/build/code_customization/
# For each patch, edit comment line (keep the #)
# then update curl line for username and SHA-1 (and remove the #)

# LoopWorkspace patches:
# LoopWorkspace: Filename: customization details
#curl https://github.com/username/LoopWorkspace/commit/SHA-1.patch | git apply

# Submodule Loop patches:
# Loop: Filename: customization details
#curl https://github.com/username/Loop/commit/SHA-1.patch | git apply --directory=Loop

# Submodule LoopKit patches:
# LoopKit: Filename: customization details
#curl https://github.com/username/LoopKit/commit/SHA-1.patch | git apply --directory=LoopKit

# Add patches for additional submodules using templates above,

# Patch Fastlane Match to not print tables
- name: Patch Match Tables
run: find /usr/local/lib/ruby/gems -name table_printer.rb | xargs sed -i "" "/puts(Terminal::Table.new(params))/d"

# Build signed Loop IPA file
- name: Fastlane Build & Archive
run: fastlane build_loop
Expand All @@ -43,7 +105,7 @@ jobs:
FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }}
FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }}
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}

# Upload to TestFlight
- name: Fastlane upload to TestFlight
run: fastlane release
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: 'Auto-update'

# Runs only on schedule for the default branch
# TARGET_BRANCH should be set as default
# 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 7 * * 1,4'
# scheduled at 07:00 every Monday and Thursday

env:
UPSTREAM_REPO: LoopKit/LoopWorkspace
UPSTREAM_BRANCH: main
TARGET_BRANCH: main # target branch on fork to be kept "alive" for running scheduled workflows (repo activity required at least every 60 days for scheduled workflows to remain active)

jobs:
check_latest_from_upstream:
runs-on: ubuntu-latest
name: Check upstream
outputs:
NEW_COMMITS: ${{ steps.sync.outputs.has_new_commits }}

steps:
# REQUIRED step
# Step 1: run a standard checkout action, provided by github
- name: Checkout target repo
uses: actions/checkout@v3
with:
# optional: set the branch to checkout,
# sync action checks out your 'target_sync_branch' anyway
#submodules: recursive
ref: ${{ env.TARGET_BRANCH }}

# REQUIRED step
# Step 2: run the sync action
- name: Sync upstream changes
id: sync
uses: aormsby/[email protected]
with:
target_sync_branch: ${{ env.TARGET_BRANCH }}
#target_branch_checkout_args: --recurse-submodules
shallow_since: 6 months ago
# REQUIRED 'target_repo_token' exactly like this!
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
if: github.ref == 'refs/heads/${{ env.TARGET_BRANCH }}'
uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow with default settings
with:
time_elapsed: 27 # Time elapsed from the previous commit to trigger a new automated commit (in days)

# Launch build workflow 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_loop.yml
secrets: inherit