sync-to-readthedocs-repo #492
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "sync-to-readthedocs-repo" | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
- latest | |
- develop | |
- 'pre/*' | |
- 'demo/*' | |
tags: | |
- 'v*' | |
- 'demo/*' | |
jobs: | |
extract_branch_or_tag: | |
outputs: | |
ref_name: ${{ steps.extract.outputs.ref_name }} | |
runs-on: ubuntu-latest | |
steps: | |
- id: extract | |
name: Extract branch or tag name | |
shell: bash | |
run: | | |
REF_NAME="${GITHUB_REF#refs/*/}" | |
echo "::set-output name=ref_name::$REF_NAME" | |
echo "Extracted ref: $REF_NAME" | |
build-and-deploy: | |
permissions: | |
contents: write | |
needs: extract_branch_or_tag | |
runs-on: ubuntu-latest | |
steps: | |
# Conditional Checkout for Branch | |
- name: Checkout Branch if branch-triggered-sync | |
if: contains(github.ref, 'refs/heads/') | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
token: ${{ secrets.GH_PAT }} | |
ref: ${{ needs.extract_branch_or_tag.outputs.ref_name }} | |
# Conditional Checkout for Tag | |
- name: Checkout Tag if tag-triggered-sync | |
if: contains(github.ref, 'refs/tags/') | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
token: ${{ secrets.GH_PAT }} | |
fetch-depth: 0 | |
ref: ${{ needs.extract_branch_or_tag.outputs.ref_name }} | |
fetch-tags: true | |
- name: Create new branch or tag only if branch-triggered-sync | |
uses: GuillaumeFalourd/[email protected] | |
if: contains(github.ref, 'refs/heads/') | |
with: | |
repository_owner: flexcompute-readthedocs | |
repository_name: tidy3d-docs | |
new_branch_name: ${{ needs.extract_branch_or_tag.outputs.ref_name }} | |
access_token: ${{ secrets.GH_PAT }} | |
new_branch_ref: default_clean_sync_branch | |
ignore_branch_exists: true | |
- name: Push branch only if branch-triggered-sync | |
uses: JamesIves/github-pages-deploy-action@v4 | |
if: contains(github.ref, 'refs/heads/') | |
with: | |
folder: . | |
token: ${{ secrets.GH_PAT }} | |
repository-name: flexcompute-readthedocs/tidy3d-docs | |
target-folder: . | |
branch: ${{ needs.extract_branch_or_tag.outputs.ref_name }} | |
force: true | |
- name: Push tag if tag-triggered-sync | |
if: contains(github.ref, 'refs/tags/') | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
const owner = 'flexcompute-readthedocs'; | |
const repo = 'tidy3d-docs'; | |
const tagName = '${{ needs.extract_branch_or_tag.outputs.ref_name }}'; | |
const sha = context.sha; | |
github.rest.git.createRef({ | |
owner, | |
repo, | |
ref: `refs/tags/${tagName}`, | |
sha | |
}); | |
token: ${{ secrets.GH_PAT }} |