From 2e6e0c4be4ae86dd44f27b594510e16bf85f142f Mon Sep 17 00:00:00 2001 From: marionbarker Date: Tue, 4 Apr 2023 14:43:33 -0700 Subject: [PATCH 1/2] Modify Bjorn idea to auto sync and build, with customize template --- .github/workflows/build_loop.yml | 80 ++++++++++++++++++++++++++++---- .github/workflows/update.yml | 80 ++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/update.yml diff --git a/.github/workflows/build_loop.yml b/.github/workflows/build_loop.yml index 26ee8c1ed1..e1e490cb18 100644 --- a/.github/workflows/build_loop.yml +++ b/.github/workflows/build_loop.yml @@ -2,20 +2,25 @@ name: 4. Build Loop run-name: Build Loop 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: @@ -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/Fork-Sync-With-Upstream-action@v3.4 + 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 @@ -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 diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000000..1bce42aeac --- /dev/null +++ b/.github/workflows/update.yml @@ -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/Fork-Sync-With-Upstream-action@v3.4 + 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 From 10d4827a4da1533c243c3678884ddf228505fd14 Mon Sep 17 00:00:00 2001 From: marionbarker Date: Thu, 6 Apr 2023 07:56:50 -0700 Subject: [PATCH 2/2] add tag/branch name to build step --- .github/workflows/build_loop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_loop.yml b/.github/workflows/build_loop.yml index e1e490cb18..563196f251 100644 --- a/.github/workflows/build_loop.yml +++ b/.github/workflows/build_loop.yml @@ -1,5 +1,5 @@ name: 4. Build Loop -run-name: Build Loop +run-name: Build Loop ${{ github.ref_name }} on: workflow_dispatch: workflow_call: