@@ -2,6 +2,11 @@ name: "docs/tidy3d/sync-to-readthedocs-repo"
2
2
3
3
on :
4
4
workflow_dispatch :
5
+ inputs :
6
+ target_branch :
7
+ description : ' Target mirror repo branch. Defaults to source branch/tag.'
8
+ required : false
9
+ type : string
5
10
push :
6
11
branches :
7
12
- main
24
29
shell : bash
25
30
run : |
26
31
REF_NAME="${GITHUB_REF#refs/*/}"
27
- echo "::set-output name= ref_name:: $REF_NAME"
32
+ echo "ref_name= $REF_NAME" >> $GITHUB_OUTPUT
28
33
echo "Extracted ref: $REF_NAME"
29
34
30
35
build-and-deploy :
@@ -33,41 +38,30 @@ jobs:
33
38
needs : extract_branch_or_tag
34
39
runs-on : ubuntu-latest
35
40
steps :
36
- # Conditional Checkout for Branch
37
- - name : Checkout Branch if branch-triggered-sync
38
- if : contains(github.ref, 'refs/heads/')
39
- uses : actions/checkout@v3
40
- with :
41
- submodules : true
42
- token : ${{ secrets.GH_PAT }}
43
- ref : ${{ needs.extract_branch_or_tag.outputs.ref_name }}
44
-
45
- - name : Push corresponding reference to mirror repo if a branch
46
- if : contains(github.ref, 'refs/heads/')
47
- run : |
48
- git fetch --unshallow origin ${{ needs.extract_branch_or_tag.outputs.ref_name }}
49
- git pull origin ${{ needs.extract_branch_or_tag.outputs.ref_name }}
50
- git remote add mirror https://github.com/flexcompute-readthedocs/tidy3d-docs.git
51
- git push mirror ${{ needs.extract_branch_or_tag.outputs.ref_name }} --force # overwrites always
52
- env :
53
- GITHUB_TOKEN : ${{ secrets.GH_PAT }}
54
-
55
- # Conditional Checkout for Tag
56
- - name : Checkout Tag if tag-triggered-sync
57
- if : contains(github.ref, 'refs/tags/')
58
- uses : actions/checkout@v3
41
+ - name : full-checkout
42
+ uses : actions/checkout@v4
59
43
with :
60
44
submodules : true
61
45
token : ${{ secrets.GH_PAT }}
62
46
fetch-depth : 0
63
47
ref : ${{ needs.extract_branch_or_tag.outputs.ref_name }}
64
48
fetch-tags : true
65
49
66
-
67
- - name : Push corresponding reference to mirror repo if a tag
68
- if : contains(github.ref, 'refs/tags/')
69
- run : |
70
- git remote add mirror https://github.com/flexcompute-readthedocs/tidy3d-docs.git
71
- git push mirror ${{ needs.extract_branch_or_tag.outputs.ref_name }} --force # overwrites always
50
+ - name : push-mirror-repo
72
51
env :
73
52
GITHUB_TOKEN : ${{ secrets.GH_PAT }}
53
+ SOURCE_REF : ${{ needs.extract_branch_or_tag.outputs.ref_name }}
54
+ TARGET_BRANCH_INPUT : ${{ github.event.inputs.target_branch }}
55
+ run : |
56
+ echo "Source reference: $SOURCE_REF"
57
+ git pull origin "$SOURCE_REF"
58
+ git remote add mirror https://github.com/flexcompute-readthedocs/tidy3d-docs.git
59
+
60
+ if [[ -n "$TARGET_BRANCH_INPUT" && "${{ github.event_name }}" == "workflow_dispatch" ]]; then
61
+ echo "Manual trigger detected. Pushing contents of '$SOURCE_REF' to remote branch '$TARGET_BRANCH_INPUT'."
62
+ git push mirror "$SOURCE_REF:refs/heads/$TARGET_BRANCH_INPUT" --force
63
+ else
64
+ echo "Automatic trigger or manual run without target. Pushing '$SOURCE_REF' to the same ref on the mirror."
65
+ # This preserves the original behavior: pushes a branch to a branch, or a tag to a tag.
66
+ git push mirror "$SOURCE_REF" --force
67
+ fi
0 commit comments