|
| 1 | +name: "sync-to-readthedocs-repo" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - latest |
| 9 | + - develop |
| 10 | + - 'pre/*' |
| 11 | + - 'demo/test/*' |
| 12 | + tags: |
| 13 | + - 'v*' |
| 14 | + - 'demo/*' |
| 15 | + |
| 16 | +jobs: |
| 17 | + extract_branch_or_tag: |
| 18 | + outputs: |
| 19 | + ref_name: ${{ steps.extract.outputs.ref_name }} |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - id: extract |
| 23 | + name: Extract branch or tag name |
| 24 | + shell: bash |
| 25 | + run: | |
| 26 | + REF_NAME="${GITHUB_REF#refs/*/}" |
| 27 | + echo "::set-output name=ref_name::$REF_NAME" |
| 28 | + echo "Extracted ref: $REF_NAME" |
| 29 | +
|
| 30 | + build-and-deploy: |
| 31 | + permissions: |
| 32 | + contents: write |
| 33 | + needs: extract_branch_or_tag |
| 34 | + runs-on: ubuntu-latest |
| 35 | + 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-notebook-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 |
| 59 | + with: |
| 60 | + submodules: true |
| 61 | + token: ${{ secrets.GH_PAT }} |
| 62 | + fetch-depth: 0 |
| 63 | + ref: ${{ needs.extract_branch_or_tag.outputs.ref_name }} |
| 64 | + fetch-tags: true |
| 65 | + |
| 66 | + - name: Push corresponding reference to mirror repo if a tag |
| 67 | + if: contains(github.ref, 'refs/tags/') |
| 68 | + run: | |
| 69 | + git remote add mirror https://github.com/flexcompute-readthedocs/tidy3d-notebook-docs.git |
| 70 | + git push mirror ${{ needs.extract_branch_or_tag.outputs.ref_name }} --force # overwrites always |
| 71 | + env: |
| 72 | + GITHUB_TOKEN: ${{ secrets.GH_PAT }} |
0 commit comments