1010env :
1111 UPSTREAM_REPO : loopandlearn/LoopFollow
1212 UPSTREAM_BRANCH : ${{ github.ref_name }} # branch on upstream repository to sync from (replace with specific branch name if needed)
13- TARGET_BRANCH : ${{ github.ref_name }} # target branch on fork to be kept in sync, and target branch on upstream to be kept alive (replace with specific branch name if needed)
14- ALIVE_BRANCH_MAIN : alive-main
15- ALIVE_BRANCH_DEV : alive-dev
13+ TARGET_BRANCH : ${{ github.ref_name }} # target branch on fork to be kept in sync
1614
1715jobs :
1816
@@ -43,11 +41,10 @@ jobs:
4341 secrets : inherit
4442
4543 # Checks if GH_PAT holds workflow permissions
46- # Checks for existence of alive branch; if non-existent creates it
47- check_alive_and_permissions :
44+ check_permissions :
4845 needs : check_certs
4946 runs-on : ubuntu-latest
50- name : Check alive branch and permissions
47+ name : Check permissions
5148 permissions :
5249 contents : write
5350 outputs :
@@ -70,72 +67,27 @@ jobs:
7067 echo "has_permission=false" >> $GITHUB_OUTPUT # Set WORKFLOW_PERMISSION to false.
7168 fi
7269
73- - name : Check for alive branches
74- if : steps.workflow-permission.outputs.has_permission == 'true'
75- env :
76- GITHUB_TOKEN : ${{ secrets.GH_PAT }}
77- run : |
78- if [[ $(gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository_owner }}/LoopFollow/branches | jq --raw-output '[.[] | select(.name == "alive-main" or .name == "alive-dev")] | length > 0') == "true" ]]; then
79- echo "Branches 'alive-main' or 'alive-dev' exist."
80- echo "ALIVE_BRANCH_EXISTS=true" >> $GITHUB_ENV
81- else
82- echo "Branches 'alive-main' and 'alive-dev' do not exist."
83- echo "ALIVE_BRANCH_EXISTS=false" >> $GITHUB_ENV
84- fi
85-
86- - name : Create alive branches
87- if : env.ALIVE_BRANCH_EXISTS == 'false'
88- env :
89- GITHUB_TOKEN : ${{ secrets.GH_PAT }}
90- run : |
91- # Get ref for UPSTREAM_REPO:main
92- SHA_MAIN=$(curl -sS -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/${{ env.UPSTREAM_REPO }}/git/refs/heads/main | jq -r '.object.sha')
93-
94- # Get ref for UPSTREAM_REPO:dev
95- SHA_DEV=$(curl -sS -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/${{ env.UPSTREAM_REPO }}/git/refs/heads/dev | jq -r '.object.sha')
96-
97- # Create alive-main branch in LoopFollow fork based on UPSTREAM_REPO:main
98- gh api \
99- --method POST \
100- -H "Authorization: token $GITHUB_TOKEN" \
101- -H "Accept: application/vnd.github.v3+json" \
102- /repos/${{ github.repository_owner }}/LoopFollow/git/refs \
103- -f ref='refs/heads/alive-main' \
104- -f sha=$SHA_MAIN
105-
106- # Create alive-dev branch in LoopFollow fork based on UPSTREAM_REPO:dev
107- gh api \
108- --method POST \
109- -H "Authorization: token $GITHUB_TOKEN" \
110- -H "Accept: application/vnd.github.v3+json" \
111- /repos/${{ github.repository_owner }}/LoopFollow/git/refs \
112- -f ref='refs/heads/alive-dev' \
113- -f sha=$SHA_DEV
114-
11570 # Checks for changes in upstream repository; if changes exist prompts sync for build
116- # Performs keepalive to avoid stale fork
11771 check_latest_from_upstream :
118- needs : [check_certs, check_alive_and_permissions ]
72+ needs : [check_certs, check_permissions ]
11973 runs-on : ubuntu-latest
120- name : Check upstream and keep alive
74+ name : Check upstream
12175 outputs :
12276 NEW_COMMITS : ${{ steps.sync.outputs.has_new_commits }}
12377 ABORT_SYNC : ${{ steps.check_branch.outputs.ABORT_SYNC }}
12478
12579 steps :
12680 - name : Check if running on main or dev branch
12781 if : |
128- needs.check_alive_and_permissions .outputs.WORKFLOW_PERMISSION == 'true' &&
82+ needs.check_permissions .outputs.WORKFLOW_PERMISSION == 'true' &&
12983 (vars.SCHEDULED_BUILD != 'false' || vars.SCHEDULED_SYNC != 'false')
13084 id : check_branch
13185 run : |
13286 if [ "${GITHUB_REF##*/}" = "main" ]; then
13387 echo "Running on main branch"
134- echo "ALIVE_BRANCH=${ALIVE_BRANCH_MAIN}" >> $GITHUB_OUTPUT
13588 echo "ABORT_SYNC=false" >> $GITHUB_OUTPUT
13689 elif [ "${GITHUB_REF##*/}" = "dev" ]; then
13790 echo "Running on dev branch"
138- echo "ALIVE_BRANCH=${ALIVE_BRANCH_DEV}" >> $GITHUB_OUTPUT
13991 echo "ABORT_SYNC=false" >> $GITHUB_OUTPUT
14092 else
14193 echo "Not running on main or dev branch"
@@ -144,21 +96,20 @@ jobs:
14496
14597 - name : Checkout target repo
14698 if : |
147- needs.check_alive_and_permissions .outputs.WORKFLOW_PERMISSION == 'true' &&
99+ needs.check_permissions .outputs.WORKFLOW_PERMISSION == 'true' &&
148100 (vars.SCHEDULED_BUILD != 'false' || vars.SCHEDULED_SYNC != 'false')
149101 uses : actions/checkout@v4
150102 with :
151103 token : ${{ secrets.GH_PAT }}
152- ref : ${{ steps.check_branch.outputs.ALIVE_BRANCH }}
153104
154105 - name : Sync upstream changes
155106 if : | # do not run the upstream sync action on the upstream repository
156- needs.check_alive_and_permissions .outputs.WORKFLOW_PERMISSION == 'true' &&
107+ needs.check_permissions .outputs.WORKFLOW_PERMISSION == 'true' &&
157108 vars.SCHEDULED_SYNC != 'false' && github.repository_owner != 'loopandlearn' && steps.check_branch.outputs.ABORT_SYNC == 'false'
158109 id : sync
159110160111 with :
161- target_sync_branch : ${{ steps.check_branch.outputs.ALIVE_BRANCH }}
112+ target_sync_branch : ${{ env.TARGET_BRANCH }}
162113 shallow_since : 6 months ago
163114 target_repo_token : ${{ secrets.GH_PAT }}
164115 upstream_sync_branch : ${{ env.UPSTREAM_BRANCH }}
@@ -167,35 +118,24 @@ jobs:
167118 # Display a sample message based on the sync output var 'has_new_commits'
168119 - name : New commits found
169120 if : |
170- needs.check_alive_and_permissions .outputs.WORKFLOW_PERMISSION == 'true' &&
121+ needs.check_permissions .outputs.WORKFLOW_PERMISSION == 'true' &&
171122 vars.SCHEDULED_SYNC != 'false' && steps.sync.outputs.has_new_commits == 'true'
172123 run : echo "New commits were found to sync."
173124
174125 - name : No new commits
175126 if : |
176- needs.check_alive_and_permissions .outputs.WORKFLOW_PERMISSION == 'true' &&
127+ needs.check_permissions .outputs.WORKFLOW_PERMISSION == 'true' &&
177128 vars.SCHEDULED_SYNC != 'false' && steps.sync.outputs.has_new_commits == 'false'
178129 run : echo "There were no new commits."
179130
180131 - name : Show value of 'has_new_commits'
181- if : needs.check_alive_and_permissions .outputs.WORKFLOW_PERMISSION == 'true' && vars.SCHEDULED_SYNC != 'false' && steps.check_branch.outputs.ABORT_SYNC == 'false'
132+ if : needs.check_permissions .outputs.WORKFLOW_PERMISSION == 'true' && vars.SCHEDULED_SYNC != 'false' && steps.check_branch.outputs.ABORT_SYNC == 'false'
182133 run : |
183134 echo ${{ steps.sync.outputs.has_new_commits }}
184135 echo "NEW_COMMITS=${{ steps.sync.outputs.has_new_commits }}" >> $GITHUB_OUTPUT
185136
186- # Keep repository "alive": add empty commits to ALIVE_BRANCH after "time_elapsed" days of inactivity to avoid inactivation of scheduled workflows
187- - name : Keep alive
188- run : |
189- echo "Keep Alive is no longer available"
190- # if: |
191- # needs.check_alive_and_permissions.outputs.WORKFLOW_PERMISSION == 'true' &&
192- # (vars.SCHEDULED_BUILD != 'false' || vars.SCHEDULED_SYNC != 'false')
193- # uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow with default settings
194- # with:
195- # time_elapsed: 20 # Time elapsed from the previous commit to trigger a new automated commit (in days)
196-
197137 - name : Show scheduled build configuration message
198- if : needs.check_alive_and_permissions .outputs.WORKFLOW_PERMISSION != 'true'
138+ if : needs.check_permissions .outputs.WORKFLOW_PERMISSION != 'true'
199139 run : |
200140 echo "### :calendar: Scheduled Sync and Build Disabled :mobile_phone_off:" >> $GITHUB_STEP_SUMMARY
201141 echo "You have not yet configured the scheduled sync and build for LoopFollow's browser build." >> $GITHUB_STEP_SUMMARY
@@ -206,63 +146,18 @@ jobs:
206146 # Builds LoopFollow
207147 build :
208148 name : Build
209- needs : [check_certs, check_alive_and_permissions, check_latest_from_upstream, day_in_month]
149+ needs : [check_certs, check_latest_from_upstream, day_in_month]
210150 runs-on : macos-15
211151 permissions :
212152 contents : write
213153 if :
214- | # builds with manual start; if automatic : once a month or when new commits are found
154+ | # builds with manual start; if scheduled : once a month or when new commits are found
215155 github.event_name == 'workflow_dispatch' ||
216- (needs.check_alive_and_permissions.outputs.WORKFLOW_PERMISSION == 'true' &&
217156 (vars.SCHEDULED_BUILD != 'false' && needs.day_in_month.outputs.IS_SECOND_IN_MONTH == 'true') ||
218157 (vars.SCHEDULED_SYNC != 'false' && needs.check_latest_from_upstream.outputs.NEW_COMMITS == 'true' )
219- )
220158 steps :
221159 - name : Select Xcode version
222160 run : " sudo xcode-select --switch /Applications/Xcode_16.4.app/Contents/Developer"
223-
224- - name : Checkout Repo for syncing
225- if : |
226- needs.check_alive_and_permissions.outputs.WORKFLOW_PERMISSION == 'true' &&
227- vars.SCHEDULED_SYNC != 'false'
228- uses : actions/checkout@v4
229- with :
230- token : ${{ secrets.GH_PAT }}
231- ref : ${{ env.TARGET_BRANCH }}
232-
233- - name : Sync upstream changes
234- if : | # do not run the upstream sync action on the upstream repository
235- needs.check_alive_and_permissions.outputs.WORKFLOW_PERMISSION == 'true' &&
236- vars.SCHEDULED_SYNC != 'false' && github.repository_owner != 'loopandlearn' && needs.check_latest_from_upstream.outputs.ABORT_SYNC == 'false'
237- id : sync
238- 239- with :
240- target_sync_branch : ${{ env.TARGET_BRANCH }}
241- shallow_since : 6 months ago
242- target_repo_token : ${{ secrets.GH_PAT }}
243- upstream_sync_branch : ${{ env.UPSTREAM_BRANCH }}
244- upstream_sync_repo : ${{ env.UPSTREAM_REPO }}
245-
246- # Display a sample message based on the sync output var 'has_new_commits'
247- - name : New commits found
248- if : |
249- needs.check_alive_and_permissions.outputs.WORKFLOW_PERMISSION == 'true' &&
250- vars.SCHEDULED_SYNC != 'false' && steps.sync.outputs.has_new_commits == 'true' && needs.check_latest_from_upstream.outputs.ABORT_SYNC == 'false'
251- run : echo "New commits were found to sync."
252-
253- - name : No new commits
254- if : |
255- needs.check_alive_and_permissions.outputs.WORKFLOW_PERMISSION == 'true' &&
256- vars.SCHEDULED_SYNC != 'false' && steps.sync.outputs.has_new_commits == 'false' && needs.check_latest_from_upstream.outputs.ABORT_SYNC == 'false'
257- run : echo "There were no new commits."
258-
259- - name : Show value of 'has_new_commits'
260- if : |
261- needs.check_alive_and_permissions.outputs.WORKFLOW_PERMISSION == 'true'
262- && vars.SCHEDULED_SYNC != 'false' && needs.check_latest_from_upstream.outputs.ABORT_SYNC == 'false'
263- run : |
264- echo ${{ steps.sync.outputs.has_new_commits }}
265- echo "NEW_COMMITS=${{ steps.sync.outputs.has_new_commits }}" >> $GITHUB_OUTPUT
266161
267162 - name : Checkout Repo for building
268163 uses : actions/checkout@v4
0 commit comments