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, and allow for customization of Loop with GitHub Actions / Fastlane builds #43

Merged
merged 25 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d854e3b
Scheduled sync and build, with option to customize Loop
bjornoleh Jun 27, 2023
0ad2bc1
Add ./patches/save_patches_here.md
bjornoleh Mar 15, 2023
f5ff351
build_loop.yml: update patch templates for submodules
bjornoleh Mar 16, 2023
a62873b
build_loop.yml: comment out patch template for submodule Loop
bjornoleh Mar 16, 2023
3751219
build_loop.yml: patch template app name = CustomLoop
bjornoleh Mar 16, 2023
d8a160f
Update build_loop.yml: fix typo
bjornoleh Mar 16, 2023
c830f5d
Update save_patches_here.md: fix typo
bjornoleh Mar 16, 2023
6ae3b1d
build_loop.yml: delete test_mode
bjornoleh Mar 16, 2023
bbf5e11
build_loop.yml: remove env CUSTOMIZE_APP
bjornoleh Mar 16, 2023
c387019
Update build_loop.yml: remove remaining env CUSTOMIZE_APP refs
bjornoleh Mar 16, 2023
175b034
build_loop.yml: remove '--exclude=' from 'git apply'
bjornoleh Mar 17, 2023
66c5908
Create update.yml
bjornoleh Mar 17, 2023
da5de54
Remove keepalive action from build_loop.yml
bjornoleh Mar 17, 2023
8ede04a
Adapt build_loop.yml and update.yml to be run in an "actions" branch
bjornoleh Mar 17, 2023
f4e6f5a
build_loop.yml: Add job names for `secrets` and `upstream_sync_and_bu…
bjornoleh Mar 27, 2023
277178f
update.yml: shorter job name for `check_latest_from_upstream`:
bjornoleh Mar 27, 2023
7874c02
build_loop.yml: use curl instead of wget for downloading patches
bjornoleh Mar 28, 2023
27b97a4
Changes to build_loop.yml and update.yml:
bjornoleh May 25, 2023
52106bf
Add branch name to run-names
bjornoleh May 26, 2023
c8d10df
Remove mention of setting TARGET_BRANCH as default, since its not fixed
bjornoleh May 25, 2023
7a83fa8
Move update and keep alive features to build_loop.yml
bjornoleh Jun 27, 2023
42a7386
Delete update.yml
bjornoleh Jun 21, 2023
5705c01
testflight.md: update GH_PAT instructions
bjornoleh Jun 21, 2023
86feb3e
testflight.md instructions: Create a branch named "alive"
bjornoleh Jul 10, 2023
9ee263e
testflight.md: rephrase section on ‘Create a branch named "alive"’
bjornoleh Jul 11, 2023
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
124 changes: 113 additions & 11 deletions .github/workflows/build_loop.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,136 @@
name: 4. Build Loop
run-name: Build Loop ${{ github.ref_name }}
run-name: Build Loop (${{ 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:

## 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.
schedule:
- cron: '0 04 * * *' # Checks for updates at 04:00 UTC every day
- cron: '0 04 1 * *' # Builds the app on the 1th every month

env:
UPSTREAM_REPO: LoopKit/LoopWorkspace
UPSTREAM_BRANCH: ${{ github.ref_name }} # branch on upstream repository to sync from (relpace with specific branch name if needed)
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)
ALIVE_BRANCH: alive
SYNC_UPSTREAM: 'true' # set to 'false' or 'true' to disable / enable syncing of fork with upstream repository

jobs:
secrets:
uses: ./.github/workflows/validate_secrets.yml
secrets: inherit
check_latest_from_upstream:
runs-on: ubuntu-latest
name: Check upstream and keep alive
outputs:
NEW_COMMITS: ${{ steps.sync.outputs.has_new_commits }}

steps:
- name: Checkout target repo
uses: actions/checkout@v3
with:
token: ${{ secrets.GH_PAT }}
ref: alive

- name: Sync upstream changes
if: ${{ env.SYNC_UPSTREAM == 'true' }} && github.repository_owner != 'LoopKit' # do not run the upstream sync action on the upstream repository
id: sync
uses: aormsby/[email protected]
with:
target_sync_branch: ${{ env.ALIVE_BRANCH }}
shallow_since: 6 months ago
target_repo_token: ${{ secrets.GH_PAT }}
upstream_sync_branch: ${{ env.UPSTREAM_BRANCH }}
upstream_sync_repo: ${{ env.UPSTREAM_REPO }}

# 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 }}
echo "NEW_COMMITS=${{ steps.sync.outputs.has_new_commits }}" >> $GITHUB_OUTPUT

# Keep repository "alive": add empty commits to ALIVE_BRANCH after "time_elapsed" days of inactivity to avoid inactivation of scheduled workflows
- name: Keep alive
uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow with default settings
with:
time_elapsed: 20 # Time elapsed from the previous commit to trigger a new automated commit (in days)

build:
needs: secrets
name: Build
needs: check_latest_from_upstream
runs-on: macos-13
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
steps:
# Uncomment to manually select latest Xcode if needed
- name: Select Latest Xcode
- name: Select Xcode version
run: "sudo xcode-select --switch /Applications/Xcode_14.3.1.app/Contents/Developer"

# Checks-out the repo
- name: Checkout Repo
uses: actions/checkout@v3
with:
token: ${{ secrets.GH_PAT }}
submodules: recursive
ref: ${{ env.TARGET_BRANCH }}

- name: Sync upstream changes
if: ${{ env.SYNC_UPSTREAM == 'true' }} && github.repository_owner != 'LoopKit' # 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 }}

# 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 }}
echo "NEW_COMMITS=${{ steps.sync.outputs.has_new_commits }}" >> $GITHUB_OUTPUT

# 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

# Submodule Loop patches:
# Template for customizing submodule Loop (changes Loop app name to "CustomLoop")
# Remove the "#" sign from the beginning of the line below to activate:
#curl https://github.com/loopnlearn/Loop/commit/d206432b024279ef710df462b20bd464cd9682d4.patch | git apply --directory=Loop -v --whitespace=fix

# Submodule LoopKit patches:
# General template for customizing submodule LoopKit
# Copy url from a GitHub commit or pull request and insert below, and remove the "#" sign from the beginning of the line to activate:
#curl url_to_github_commit.patch | git apply --directory=LoopKit -v --whitespace=fix

# Submodule xxxxx patches:

# Add patches for customization of additional submodules by following the templates above,
# and make sure to specify the submodule by setting "--directory=(submodule_name)".
# Several patches may be added per submodule.
# Adding comments (#) may be useful to easily tell the individual patches apart.


# 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"
Expand Down
18 changes: 16 additions & 2 deletions fastlane/testflight.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ Log into your GitHub account to create a personal access token; this is one of t

1. Create a [new personal access token](https://github.com/settings/tokens/new):
* Enter a name for your token, use "FastLane Access Token".
* Change the selection to 90 days.
* Select the `repo` permission scope.
* Change the Expiration selection to `No expiration`.
* Select the `repo` and `workflow` permission scopes.
* Click "Generate token".
* Copy the token and record it. It will be used below as `GH_PAT`.

Expand Down Expand Up @@ -159,6 +159,20 @@ You do not need to fill out the next form. That is for submitting to the app sto
1. On the right side, click "Run Workflow", and tap the green `Run workflow` button.
1. Wait, and within a minute or two you should see a green checkmark indicating the workflow succeeded.

## Create a branch named "alive"

TestFlight builds expire after 90 days. This process you are implementing here will update and rebuild Loop periodically, and requires that you create a branch named "alive" so that GitHub will not inactivate the scheduled rebuild if no code updates are made.

The "alive" branch will only receive some additional commits to its history, and is not used for building the app.

1. Go to the "Code" tab of your LoopWorkspace repository.
1. Click the branch selection dropdown button, and then `View all branches`.
1. Click the green "New branch" button (upper right).
1. Type `alive` in the "New branch name" field.
1. Select `LoopKit/LoopWorkspace` as "Source".
1. Select `dev` in the branch dropdown.
1. Click the green "Create new branch" button.

## Build Loop

1. Click on the "Actions" tab of your LoopWorkspace repository.
Expand Down
1 change: 1 addition & 0 deletions patches/save_patches_here.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LoopWorkspace-level patches can be saved in this directory (LoopWorkspace/patches/)