@@ -3,20 +3,35 @@ name: "docs/tidy3d/sync-to-readthedocs-repo"
33on :
44 workflow_dispatch :
55 inputs :
6- target_branch :
7- description : ' Target mirror repo branch. Defaults to source branch/tag .'
6+ source_ref :
7+ description : ' Source ref ( branch/tag) to sync . Defaults to current ref .'
88 required : false
99 type : string
10- push :
11- branches :
12- - main
13- - latest
14- - develop
15- - ' pre/*'
16- - ' demo/*'
17- tags :
18- - ' v*'
19- - ' demo/*'
10+ default : ' '
11+ target_ref :
12+ description : ' Target mirror repo ref. Defaults to source ref.'
13+ required : false
14+ type : string
15+ default : ' '
16+
17+ workflow_call :
18+ inputs :
19+ source_ref :
20+ description : ' Source ref (branch/tag) to sync. Required for workflow_call.'
21+ required : true
22+ type : string
23+ target_ref :
24+ description : ' Target mirror repo ref. Defaults to source ref.'
25+ required : false
26+ type : string
27+ default : ' '
28+ outputs :
29+ workflow_success :
30+ description : ' Sync workflow success status'
31+ value : ${{ jobs.build-and-deploy.result == 'success' }}
32+ synced_ref :
33+ description : ' The ref that was synced to the mirror'
34+ value : ${{ jobs.build-and-deploy.outputs.synced_ref }}
2035
2136permissions :
2237 contents : read
@@ -30,16 +45,26 @@ jobs:
3045 - id : extract
3146 name : Extract branch or tag name
3247 shell : bash
48+ env :
49+ INPUT_SOURCE_REF : ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.source_ref || inputs.source_ref }}
3350 run : |
34- REF_NAME="${GITHUB_REF#refs/*/}"
51+ if [[ -n "$INPUT_SOURCE_REF" ]]; then
52+ REF_NAME="$INPUT_SOURCE_REF"
53+ echo "Using provided source_ref: $REF_NAME"
54+ else
55+ REF_NAME="${GITHUB_REF#refs/*/}"
56+ echo "Extracted ref from GITHUB_REF: $REF_NAME"
57+ fi
3558 echo "ref_name=$REF_NAME" >> $GITHUB_OUTPUT
36- echo "Extracted ref: $REF_NAME"
59+ echo "Final ref: $REF_NAME"
3760
3861 build-and-deploy :
3962 permissions :
4063 contents : write
4164 needs : extract_branch_or_tag
4265 runs-on : ubuntu-latest
66+ outputs :
67+ synced_ref : ${{ steps.sync-result.outputs.synced_ref }}
4368 steps :
4469 - name : full-checkout
4570 uses : actions/checkout@v4
@@ -52,20 +77,25 @@ jobs:
5277 persist-credentials : true
5378
5479 - name : push-mirror-repo
80+ id : sync-result
5581 env :
5682 GITHUB_TOKEN : ${{ secrets.GH_PAT }}
5783 SOURCE_REF : ${{ needs.extract_branch_or_tag.outputs.ref_name }}
58- TARGET_BRANCH_INPUT : ${{ github.event.inputs.target_branch }}
84+ TARGET_REF : ${{ github.event_name == 'workflow_dispatch' && github. event.inputs.target_ref || inputs.target_ref }}
5985 run : |
6086 echo "Source reference: $SOURCE_REF"
6187 git pull origin "$SOURCE_REF"
6288 git remote add mirror https://github.com/flexcompute-readthedocs/tidy3d-docs.git
6389
64- if [[ -n "$TARGET_BRANCH_INPUT" && "${{ github.event_name }}" == "workflow_dispatch" ]]; then
65- echo "Manual trigger detected. Pushing contents of '$SOURCE_REF' to remote branch '$TARGET_BRANCH_INPUT'."
66- git push mirror "$SOURCE_REF:refs/heads/$TARGET_BRANCH_INPUT" --force
90+ if [[ -n "$TARGET_REF" ]]; then
91+ echo "Pushing contents of '$SOURCE_REF' to remote ref '$TARGET_REF'."
92+ git push mirror "$SOURCE_REF:refs/heads/$TARGET_REF" --force
93+ SYNCED_REF="$TARGET_REF"
6794 else
68- echo "Automatic trigger or manual run without target. Pushing '$SOURCE_REF' to the same ref on the mirror."
69- # This preserves the original behavior: pushes a branch to a branch, or a tag to a tag.
95+ echo "Pushing '$SOURCE_REF' to the same ref on the mirror."
7096 git push mirror "$SOURCE_REF" --force
97+ SYNCED_REF="$SOURCE_REF"
7198 fi
99+
100+ echo "synced_ref=$SYNCED_REF" >> $GITHUB_OUTPUT
101+ echo "? Successfully synced to: $SYNCED_REF"
0 commit comments