Build Loop (dev) #37
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: 4. Build Loop | |
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: | |
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: ${{ vars.SYNC_UPSTREAM }} # set an optional "SYNC_UPSTREAM" repository variable to 'false' to disable syncing of fork with the upstream repository | |
jobs: | |
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 != 'false' && github.repository_owner != 'LoopKit' }} # do not run the upstream sync action on the upstream repository | |
id: sync | |
uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 | |
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: | |
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: | |
- name: Select Xcode version | |
run: "sudo xcode-select --switch /Applications/Xcode_14.3.1.app/Contents/Developer" | |
- name: Checkout Repo for syncing | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GH_PAT }} | |
ref: ${{ env.TARGET_BRANCH }} | |
- name: Sync upstream changes | |
if: ${{ env.SYNC_UPSTREAM != 'false' && github.repository_owner != 'LoopKit' }} # do not run the upstream sync action on the upstream repository | |
id: sync | |
uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 | |
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 | |
- name: Checkout Repo for building | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GH_PAT }} | |
submodules: recursive | |
ref: ${{ env.TARGET_BRANCH }} | |
# 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" | |
# Build signed Loop IPA file | |
- name: Fastlane Build & Archive | |
run: fastlane build_loop | |
env: | |
TEAMID: ${{ secrets.TEAMID }} | |
GH_PAT: ${{ secrets.GH_PAT }} | |
FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }} | |
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 | |
env: | |
TEAMID: ${{ secrets.TEAMID }} | |
GH_PAT: ${{ secrets.GH_PAT }} | |
FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }} | |
FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }} | |
FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }} | |
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }} | |
# Upload Build artifacts | |
- name: Upload build log, IPA and Symbol artifacts | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifacts | |
path: | | |
artifacts | |
buildlog |