|
1 | 1 | name: 4. Build Loop
|
2 |
| -run-name: Build Loop ${{ github.ref_name }} |
| 2 | +run-name: Build Loop (${{ github.ref_name }}) |
3 | 3 | on:
|
4 | 4 | workflow_dispatch:
|
5 | 5 |
|
6 | 6 | ## Remove the "#" sign from the beginning of the line below to get automated builds on push (code changes in your repository)
|
7 | 7 | #push:
|
8 | 8 |
|
9 |
| - ## Remove the "#" sign from the beginning of the two lines below to get automated builds every two months |
10 |
| - #schedule: |
11 |
| - #- cron: '0 17 1 */2 *' # Runs at 17:00 UTC on the 1st in Jan, Mar, May, Jul, Sep and Nov. |
| 9 | + schedule: |
| 10 | + - cron: '0 04 * * *' # Checks for updates at 04:00 UTC every day |
| 11 | + - cron: '0 04 1 * *' # Builds the app on the 1th every month |
| 12 | + |
| 13 | +env: |
| 14 | + UPSTREAM_REPO: LoopKit/LoopWorkspace |
| 15 | + UPSTREAM_BRANCH: ${{ github.ref_name }} # branch on upstream repository to sync from (relpace with specific branch name if needed) |
| 16 | + 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) |
| 17 | + ALIVE_BRANCH: alive |
| 18 | + SYNC_UPSTREAM: 'true' # set to 'false' or 'true' to disable / enable syncing of fork with upstream repository |
12 | 19 |
|
13 | 20 | jobs:
|
14 |
| - secrets: |
15 |
| - uses: ./.github/workflows/validate_secrets.yml |
16 |
| - secrets: inherit |
| 21 | + check_latest_from_upstream: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + name: Check upstream and keep alive |
| 24 | + outputs: |
| 25 | + NEW_COMMITS: ${{ steps.sync.outputs.has_new_commits }} |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout target repo |
| 29 | + uses: actions/checkout@v3 |
| 30 | + with: |
| 31 | + token: ${{ secrets.GH_PAT }} |
| 32 | + ref: alive |
| 33 | + |
| 34 | + - name: Sync upstream changes |
| 35 | + if: ${{ env.SYNC_UPSTREAM == 'true' }} && github.repository_owner != 'LoopKit' # do not run the upstream sync action on the upstream repository |
| 36 | + id: sync |
| 37 | + uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 |
| 38 | + with: |
| 39 | + target_sync_branch: ${{ env.ALIVE_BRANCH }} |
| 40 | + shallow_since: 6 months ago |
| 41 | + target_repo_token: ${{ secrets.GH_PAT }} |
| 42 | + upstream_sync_branch: ${{ env.UPSTREAM_BRANCH }} |
| 43 | + upstream_sync_repo: ${{ env.UPSTREAM_REPO }} |
| 44 | + |
| 45 | + # Display a sample message based on the sync output var 'has_new_commits' |
| 46 | + - name: New commits found |
| 47 | + if: steps.sync.outputs.has_new_commits == 'true' |
| 48 | + run: echo "New commits were found to sync." |
17 | 49 |
|
| 50 | + - name: No new commits |
| 51 | + if: steps.sync.outputs.has_new_commits == 'false' |
| 52 | + run: echo "There were no new commits." |
| 53 | + |
| 54 | + - name: Show value of 'has_new_commits' |
| 55 | + run: | |
| 56 | + echo ${{ steps.sync.outputs.has_new_commits }} |
| 57 | + echo "NEW_COMMITS=${{ steps.sync.outputs.has_new_commits }}" >> $GITHUB_OUTPUT |
| 58 | + |
| 59 | + # Keep repository "alive": add empty commits to ALIVE_BRANCH after "time_elapsed" days of inactivity to avoid inactivation of scheduled workflows |
| 60 | + - name: Keep alive |
| 61 | + uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow with default settings |
| 62 | + with: |
| 63 | + time_elapsed: 20 # Time elapsed from the previous commit to trigger a new automated commit (in days) |
| 64 | + |
18 | 65 | build:
|
19 |
| - needs: secrets |
| 66 | + name: Build |
| 67 | + needs: check_latest_from_upstream |
20 | 68 | runs-on: macos-13
|
| 69 | + 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 |
21 | 70 | steps:
|
22 |
| - # Uncomment to manually select latest Xcode if needed |
23 |
| - - name: Select Latest Xcode |
| 71 | + - name: Select Xcode version |
24 | 72 | run: "sudo xcode-select --switch /Applications/Xcode_14.3.1.app/Contents/Developer"
|
25 | 73 |
|
26 |
| - # Checks-out the repo |
27 | 74 | - name: Checkout Repo
|
28 | 75 | uses: actions/checkout@v3
|
29 | 76 | with:
|
| 77 | + token: ${{ secrets.GH_PAT }} |
30 | 78 | submodules: recursive
|
| 79 | + ref: ${{ env.TARGET_BRANCH }} |
| 80 | + |
| 81 | + - name: Sync upstream changes |
| 82 | + if: ${{ env.SYNC_UPSTREAM == 'true' }} && github.repository_owner != 'LoopKit' # do not run the upstream sync action on the upstream repository |
| 83 | + id: sync |
| 84 | + uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 |
| 85 | + with: |
| 86 | + target_sync_branch: ${{ env.TARGET_BRANCH }} |
| 87 | + shallow_since: 6 months ago |
| 88 | + target_repo_token: ${{ secrets.GH_PAT }} |
| 89 | + upstream_sync_branch: ${{ env.UPSTREAM_BRANCH }} |
| 90 | + upstream_sync_repo: ${{ env.UPSTREAM_REPO }} |
| 91 | + |
| 92 | + # Display a sample message based on the sync output var 'has_new_commits' |
| 93 | + - name: New commits found |
| 94 | + if: steps.sync.outputs.has_new_commits == 'true' |
| 95 | + run: echo "New commits were found to sync." |
| 96 | + |
| 97 | + - name: No new commits |
| 98 | + if: steps.sync.outputs.has_new_commits == 'false' |
| 99 | + run: echo "There were no new commits." |
31 | 100 |
|
| 101 | + - name: Show value of 'has_new_commits' |
| 102 | + run: | |
| 103 | + echo ${{ steps.sync.outputs.has_new_commits }} |
| 104 | + echo "NEW_COMMITS=${{ steps.sync.outputs.has_new_commits }}" >> $GITHUB_OUTPUT |
| 105 | +
|
| 106 | + # Customize Loop: Download and apply patches |
| 107 | + - name: Customize Loop |
| 108 | + run: | |
| 109 | +
|
| 110 | + # LoopWorkspace patches |
| 111 | + # -applies any patches located in the LoopWorkspace/patches/ directory |
| 112 | + if $(ls ./patches/* &> /dev/null); then |
| 113 | + git apply ./patches/* --allow-empty -v --whitespace=fix |
| 114 | + fi |
| 115 | +
|
| 116 | + # Submodule Loop patches: |
| 117 | + # Template for customizing submodule Loop (changes Loop app name to "CustomLoop") |
| 118 | + # Remove the "#" sign from the beginning of the line below to activate: |
| 119 | + #curl https://github.com/loopnlearn/Loop/commit/d206432b024279ef710df462b20bd464cd9682d4.patch | git apply --directory=Loop -v --whitespace=fix |
| 120 | + |
| 121 | + # Submodule LoopKit patches: |
| 122 | + # General template for customizing submodule LoopKit |
| 123 | + # Copy url from a GitHub commit or pull request and insert below, and remove the "#" sign from the beginning of the line to activate: |
| 124 | + #curl url_to_github_commit.patch | git apply --directory=LoopKit -v --whitespace=fix |
| 125 | + |
| 126 | + # Submodule xxxxx patches: |
| 127 | +
|
| 128 | + # Add patches for customization of additional submodules by following the templates above, |
| 129 | + # and make sure to specify the submodule by setting "--directory=(submodule_name)". |
| 130 | + # Several patches may be added per submodule. |
| 131 | + # Adding comments (#) may be useful to easily tell the individual patches apart. |
| 132 | + |
| 133 | + |
32 | 134 | # Patch Fastlane Match to not print tables
|
33 | 135 | - name: Patch Match Tables
|
34 | 136 | run: find /usr/local/lib/ruby/gems -name table_printer.rb | xargs sed -i "" "/puts(Terminal::Table.new(params))/d"
|
|
0 commit comments