@@ -3,10 +3,36 @@ 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+ 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 }}
35+
1036 push :
1137 branches :
1238 - main
@@ -30,16 +56,26 @@ jobs:
3056 - id : extract
3157 name : Extract branch or tag name
3258 shell : bash
59+ env :
60+ INPUT_SOURCE_REF : ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.source_ref || inputs.source_ref }}
3361 run : |
34- REF_NAME="${GITHUB_REF#refs/*/}"
62+ if [[ -n "$INPUT_SOURCE_REF" ]]; then
63+ REF_NAME="$INPUT_SOURCE_REF"
64+ echo "Using provided source_ref: $REF_NAME"
65+ else
66+ REF_NAME="${GITHUB_REF#refs/*/}"
67+ echo "Extracted ref from GITHUB_REF: $REF_NAME"
68+ fi
3569 echo "ref_name=$REF_NAME" >> $GITHUB_OUTPUT
36- echo "Extracted ref: $REF_NAME"
70+ echo "Final ref: $REF_NAME"
3771
3872 build-and-deploy :
3973 permissions :
4074 contents : write
4175 needs : extract_branch_or_tag
4276 runs-on : ubuntu-latest
77+ outputs :
78+ synced_ref : ${{ steps.sync-result.outputs.synced_ref }}
4379 steps :
4480 - name : full-checkout
4581 uses : actions/checkout@v4
@@ -52,20 +88,25 @@ jobs:
5288 persist-credentials : true
5389
5490 - name : push-mirror-repo
91+ id : sync-result
5592 env :
5693 GITHUB_TOKEN : ${{ secrets.GH_PAT }}
5794 SOURCE_REF : ${{ needs.extract_branch_or_tag.outputs.ref_name }}
58- TARGET_BRANCH_INPUT : ${{ github.event.inputs.target_branch }}
95+ TARGET_REF : ${{ github.event_name == 'workflow_dispatch' && github. event.inputs.target_ref || inputs.target_ref }}
5996 run : |
6097 echo "Source reference: $SOURCE_REF"
6198 git pull origin "$SOURCE_REF"
6299 git remote add mirror https://github.com/flexcompute-readthedocs/tidy3d-docs.git
63100
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
101+ if [[ -n "$TARGET_REF" ]]; then
102+ echo "Pushing contents of '$SOURCE_REF' to remote ref '$TARGET_REF'."
103+ git push mirror "$SOURCE_REF:refs/heads/$TARGET_REF" --force
104+ SYNCED_REF="$TARGET_REF"
67105 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.
106+ echo "Pushing '$SOURCE_REF' to the same ref on the mirror."
70107 git push mirror "$SOURCE_REF" --force
108+ SYNCED_REF="$SOURCE_REF"
71109 fi
110+
111+ echo "synced_ref=$SYNCED_REF" >> $GITHUB_OUTPUT
112+ echo "? Successfully synced to: $SYNCED_REF"
0 commit comments