@@ -12,6 +12,11 @@ name: Upstream Sync Workflow
1212 required : false
1313 type : string
1414 default : stable
15+ fallback_branch_prefix :
16+ description : ' The fallback prefix of the upstream branch you want to sync against.'
17+ required : false
18+ type : string
19+ default : unmaintained
1520env :
1621 GITHUB_TOKEN : ${{github.token}}
1722 DOWNSTREAM_OWNER : stackhpc
@@ -23,11 +28,38 @@ jobs:
2328 - name : Get upstream SHA
2429 id : get_upstream_sha
2530 run : |
26- upstream_sha=$(gh api \
27- -H "Accept: application/vnd.github.v3+json" \
28- "/repos/${{env.UPSTREAM_OWNER}}/$(basename $(pwd))/commits/${{inputs.branch_prefix}}/${{inputs.release_series}}" --jq ".sha")
31+ set +e
32+
33+ function get_sha {
34+ ref=$1
35+ gh api \
36+ -H "Accept: application/vnd.github.v3+json" \
37+ "/repos/${{env.UPSTREAM_OWNER}}/$(basename $(pwd))/commits/${ref}" --jq ".sha"
38+ }
39+
40+ upstream_ref="${{inputs.branch_prefix}}/${{inputs.release_series}}"
41+ upstream_sha=$(get_sha $upstream_ref)
42+ result=$?
43+ if [[ $result -ne 0 ]] && [[ -n "${{inputs.fallback_branch_prefix}}" ]]; then
44+ echo "Failed to get SHA using standard branch prefix. Trying fallback."
45+ upstream_ref="${{inputs.fallback_branch_prefix}}/${{inputs.release_series}}"
46+ upstream_sha=$(get_sha $upstream_ref)
47+ result=$?
48+ fi
49+ if [[ $result -ne 0 ]]; then
50+ echo "Failed to get SHA using standard or fallback branch prefixes. Checking for EOL tag."
51+ upstream_ref="${{inputs.release_series}}-eol"
52+ upstream_sha=$(get_sha $upstream_ref)
53+ result=$?
54+ if [[ $result -ne 0 ]]; then
55+ echo "Unable to find EOL tag - failing"
56+ exit 1
57+ fi
58+ fi
59+ echo "upstream_ref=$upstream_ref" >> $GITHUB_OUTPUT
2960 echo "result=$upstream_sha" >> $GITHUB_OUTPUT
3061 - name : Check if downstream branch exists
62+ if : steps.get_upstream_sha.outputs.result != ''
3163 id : check_if_downstream_branch_exists
3264 run : |
3365 api_path="/repos/${{env.DOWNSTREAM_OWNER}}/$(basename $(pwd))/branches/stackhpc/${{inputs.release_series}}"
5688 -H "Accept: application/vnd.github.v3+json" \
5789 "/repos/${{env.DOWNSTREAM_OWNER}}/$(basename $(pwd))"\
5890 "/compare/stackhpc/${{inputs.release_series}}..."\
59- "${{env.UPSTREAM_OWNER}}:${{inputs.branch_prefix}}/${{inputs.release_series }}" --jq '.ahead_by')
91+ "${{env.UPSTREAM_OWNER}}:${{steps.get_upstream_sha.outputs.result }}" --jq '.ahead_by')
6092 echo "result=$ahead_by" >> $GITHUB_OUTPUT
6193 - name : Create copy of the upstream branch
6294 if : steps.check_if_ahead.outputs.result > 0
76108 -H "Accept: application/vnd.github.v3+json" \
77109 /repos/${{env.DOWNSTREAM_OWNER}}/$(basename $(pwd))/pulls \
78110 -f title="Synchronise ${{inputs.release_series}} with upstream" \
79- -f body="This PR contains a snapshot of ${{inputs.release_series}} from upstream." \
111+ -f body="This PR contains a snapshot of ${{inputs.release_series}} from upstream ${{steps.get_upstream_sha.outputs.upstream_ref}} ." \
80112 -f head="${{env.DOWNSTREAM_OWNER}}:upstream/${{inputs.release_series}}-$(date +%F)" \
81113 -f base="stackhpc/${{inputs.release_series}}" --jq '.url')
82114 echo "result=$(basename $pull_request_url)" >> $GITHUB_OUTPUT
0 commit comments