Skip to content

Commit 695d955

Browse files
chore: python-client autorelease flow
1 parent d160d0f commit 695d955

13 files changed

+1814
-370
lines changed

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

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,35 @@ name: "docs/tidy3d/sync-to-readthedocs-repo"
33
on:
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-
push:
11-
branches:
12-
- main
13-
- latest
14-
- develop
15-
- 'pre/*'
16-
- 'demo/*'
17-
tags:
18-
- 'v*'
19-
- 'demo/*'
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 }}
2035

2136
permissions:
2237
contents: read
@@ -30,16 +45,26 @@ jobs:
3045
- id: extract
3146
name: Extract branch or tag name
3247
shell: bash
48+
env:
49+
INPUT_SOURCE_REF: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.source_ref || inputs.source_ref }}
3350
run: |
34-
REF_NAME="${GITHUB_REF#refs/*/}"
51+
if [[ -n "$INPUT_SOURCE_REF" ]]; then
52+
REF_NAME="$INPUT_SOURCE_REF"
53+
echo "Using provided source_ref: $REF_NAME"
54+
else
55+
REF_NAME="${GITHUB_REF#refs/*/}"
56+
echo "Extracted ref from GITHUB_REF: $REF_NAME"
57+
fi
3558
echo "ref_name=$REF_NAME" >> $GITHUB_OUTPUT
36-
echo "Extracted ref: $REF_NAME"
59+
echo "Final ref: $REF_NAME"
3760
3861
build-and-deploy:
3962
permissions:
4063
contents: write
4164
needs: extract_branch_or_tag
4265
runs-on: ubuntu-latest
66+
outputs:
67+
synced_ref: ${{ steps.sync-result.outputs.synced_ref }}
4368
steps:
4469
- name: full-checkout
4570
uses: actions/checkout@v4
@@ -52,20 +77,25 @@ jobs:
5277
persist-credentials: true
5378

5479
- name: push-mirror-repo
80+
id: sync-result
5581
env:
5682
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
5783
SOURCE_REF: ${{ needs.extract_branch_or_tag.outputs.ref_name }}
58-
TARGET_BRANCH_INPUT: ${{ github.event.inputs.target_branch }}
84+
TARGET_REF: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.target_ref || inputs.target_ref }}
5985
run: |
6086
echo "Source reference: $SOURCE_REF"
6187
git pull origin "$SOURCE_REF"
6288
git remote add mirror https://github.com/flexcompute-readthedocs/tidy3d-docs.git
6389
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
90+
if [[ -n "$TARGET_REF" ]]; then
91+
echo "Pushing contents of '$SOURCE_REF' to remote ref '$TARGET_REF'."
92+
git push mirror "$SOURCE_REF:refs/heads/$TARGET_REF" --force
93+
SYNCED_REF="$TARGET_REF"
6794
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.
95+
echo "Pushing '$SOURCE_REF' to the same ref on the mirror."
7096
git push mirror "$SOURCE_REF" --force
97+
SYNCED_REF="$SOURCE_REF"
7198
fi
99+
100+
echo "synced_ref=$SYNCED_REF" >> $GITHUB_OUTPUT
101+
echo "? Successfully synced to: $SYNCED_REF"
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: "public/tidy3d/python-client-create-tag"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release_tag:
7+
description: 'Release Tag (e.g., v2.10.0, v2.10.0rc1)'
8+
required: true
9+
type: string
10+
11+
release_type:
12+
description: 'Release Type (draft=test, final=PyPI)'
13+
type: choice
14+
default: 'draft'
15+
required: false
16+
options:
17+
- draft
18+
- final
19+
20+
workflow_call:
21+
inputs:
22+
release_tag:
23+
description: 'Release Tag (e.g., v2.10.0, v2.10.0rc1)'
24+
required: true
25+
type: string
26+
27+
release_type:
28+
description: 'Release Type (draft=test, final=PyPI)'
29+
type: string
30+
default: 'draft'
31+
required: false
32+
33+
outputs:
34+
tag_created:
35+
description: 'Whether tag was successfully created'
36+
value: ${{ jobs.create-and-push-tag.result == 'success' }}
37+
38+
permissions:
39+
contents: write
40+
41+
jobs:
42+
create-and-push-tag:
43+
runs-on: ubuntu-latest
44+
env:
45+
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.release_tag || inputs.release_tag }}
46+
RELEASE_TYPE: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.release_type || inputs.release_type }}
47+
steps:
48+
- name: checkout-code
49+
uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 1
52+
persist-credentials: true
53+
token: ${{ secrets.GH_PAT }}
54+
55+
- name: validate-version-match
56+
if: env.RELEASE_TYPE == 'final'
57+
run: |
58+
set -e
59+
echo "Validating version match with pyproject.toml..."
60+
61+
# Extract version from pyproject.toml
62+
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
63+
echo "pyproject.toml version: $PYPROJECT_VERSION"
64+
65+
# Strip 'v' prefix from release tag
66+
TAG_VERSION="${RELEASE_TAG#v}"
67+
echo "Release tag version: $TAG_VERSION"
68+
69+
if [[ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]]; then
70+
echo "Version mismatch!"
71+
echo " pyproject.toml: $PYPROJECT_VERSION"
72+
echo " Release tag: $TAG_VERSION"
73+
echo ""
74+
echo "Please update pyproject.toml version to match the release tag."
75+
exit 1
76+
fi
77+
78+
echo "Version matches: $PYPROJECT_VERSION"
79+
80+
- name: retag
81+
run: |
82+
set -e
83+
echo "Creating and pushing tag: $RELEASE_TAG"
84+
85+
git config user.name "github-actions[bot]"
86+
git config user.email "github-actions[bot]@users.noreply.github.com"
87+
88+
# Fetch existing tags
89+
git fetch --tags origin || true
90+
91+
# Check if tag exists
92+
if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then
93+
echo "Tag $RELEASE_TAG already exists"
94+
echo "Deleting existing tag locally and remotely..."
95+
git tag -d "$RELEASE_TAG" || true
96+
git push --delete origin "$RELEASE_TAG" || true
97+
else
98+
echo "Tag $RELEASE_TAG does not exist yet"
99+
fi
100+
101+
# Create new tag
102+
echo "Creating tag $RELEASE_TAG at commit $(git rev-parse HEAD)"
103+
git tag "$RELEASE_TAG"
104+
105+
# Push tag
106+
echo "Pushing tag to origin..."
107+
git push origin "$RELEASE_TAG"
108+
109+
echo "Successfully created and pushed tag $RELEASE_TAG"
110+
111+
- name: confirm-push
112+
run: |
113+
echo "Tag creation complete"
114+
echo "Tag: $RELEASE_TAG"
115+
echo "Commit: $(git rev-parse HEAD)"
116+
echo "Pushed to: origin"

0 commit comments

Comments
 (0)