Skip to content

Commit c6be584

Browse files
ci: Enable manual overwrite tidy3d-docs
1 parent f7d939d commit c6be584

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

.github/workflows/tidy3d-docs-sync-readthedocs-repo.yml

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: "docs/tidy3d/sync-to-readthedocs-repo"
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
target_branch:
7+
description: 'Target mirror repo branch. Defaults to source branch/tag.'
8+
required: false
9+
type: string
510
push:
611
branches:
712
- main
@@ -24,7 +29,7 @@ jobs:
2429
shell: bash
2530
run: |
2631
REF_NAME="${GITHUB_REF#refs/*/}"
27-
echo "::set-output name=ref_name::$REF_NAME"
32+
echo "ref_name=$REF_NAME" >> $GITHUB_OUTPUT
2833
echo "Extracted ref: $REF_NAME"
2934
3035
build-and-deploy:
@@ -33,41 +38,30 @@ jobs:
3338
needs: extract_branch_or_tag
3439
runs-on: ubuntu-latest
3540
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
5943
with:
6044
submodules: true
6145
token: ${{ secrets.GH_PAT }}
6246
fetch-depth: 0
6347
ref: ${{ needs.extract_branch_or_tag.outputs.ref_name }}
6448
fetch-tags: true
6549

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
7251
env:
7352
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

Comments
 (0)