@@ -55,29 +55,36 @@ jobs:
5555
5656 - name : Check for alive branches
5757 if : steps.workflow-permission.outputs.has_permission == 'true'
58+ id : check-alive
5859 env :
5960 GITHUB_TOKEN : ${{ secrets.GH_PAT }}
6061 run : |
61- if [[ $(gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository_owner }}/Trio/branches | jq --raw-output '[.[] | select(.name == "alive-main" or .name == "alive-dev")] | length > 0') == "true" ]]; then
62- echo "Branches 'alive-main' or 'alive-dev' exist."
63- echo "ALIVE_BRANCH_EXISTS=true" >> $GITHUB_ENV
62+ branch_list=$(gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository_owner }}/Trio/branches | jq -r '.[].name')
63+
64+ if echo "$branch_list" | grep -q '^alive-main$'; then
65+ echo "alive-main exists"
66+ echo "ALIVE_MAIN_EXISTS=true" >> $GITHUB_ENV
67+ else
68+ echo "alive-main missing"
69+ echo "ALIVE_MAIN_EXISTS=false" >> $GITHUB_ENV
70+ fi
71+
72+ if echo "$branch_list" | grep -q '^alive-dev$'; then
73+ echo "alive-dev exists"
74+ echo "ALIVE_DEV_EXISTS=true" >> $GITHUB_ENV
6475 else
65- echo "Branches ' alive-main' and 'alive- dev' do not exist. "
66- echo "ALIVE_BRANCH_EXISTS =false" >> $GITHUB_ENV
76+ echo "alive-dev missing "
77+ echo "ALIVE_DEV_EXISTS =false" >> $GITHUB_ENV
6778 fi
6879
69- - name : Create alive branches
70- if : env.ALIVE_BRANCH_EXISTS == 'false'
80+ - name : Create alive-main branch if missing
81+ if : env.ALIVE_MAIN_EXISTS == 'false'
7182 env :
7283 GITHUB_TOKEN : ${{ secrets.GH_PAT }}
7384 run : |
74- # Get ref for UPSTREAM_REPO:main
7585 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')
76-
77- # Get ref for UPSTREAM_REPO:dev
78- 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')
79-
80- # Create alive-main branch in Trio fork based on UPSTREAM_REPO:main
86+
87+ echo "Creating alive-main from upstream main"
8188 gh api \
8289 --method POST \
8390 -H "Authorization : token $GITHUB_TOKEN" \
8693 -f ref='refs/heads/alive-main' \
8794 -f sha=$SHA_MAIN
8895
89- # Create alive-dev branch in Trio fork based on UPSTREAM_REPO:dev
96+ - name : Create alive-dev branch if missing
97+ if : env.ALIVE_DEV_EXISTS == 'false'
98+ env :
99+ GITHUB_TOKEN : ${{ secrets.GH_PAT }}
100+ run : |
101+ 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')
102+
103+ echo "Creating alive-dev from upstream dev"
90104 gh api \
91105 --method POST \
92106 -H "Authorization : token $GITHUB_TOKEN" \
95109 -f ref='refs/heads/alive-dev' \
96110 -f sha=$SHA_DEV
97111
112+
98113 # Checks for changes in upstream repository; if changes exist prompts sync for build
99114 # Performs keepalive to avoid stale fork
100115 check_latest_from_upstream :
0 commit comments