Skip to content

Commit bb78f7c

Browse files
chore: python-client autorelease flow
1 parent 8da1ce8 commit bb78f7c

File tree

7 files changed

+1004
-150
lines changed

7 files changed

+1004
-150
lines changed

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

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,36 @@ 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+
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 }}
35+
1036
push:
1137
branches:
1238
- main
@@ -30,16 +56,26 @@ jobs:
3056
- id: extract
3157
name: Extract branch or tag name
3258
shell: bash
59+
env:
60+
INPUT_SOURCE_REF: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.source_ref || inputs.source_ref }}
3361
run: |
34-
REF_NAME="${GITHUB_REF#refs/*/}"
62+
if [[ -n "$INPUT_SOURCE_REF" ]]; then
63+
REF_NAME="$INPUT_SOURCE_REF"
64+
echo "Using provided source_ref: $REF_NAME"
65+
else
66+
REF_NAME="${GITHUB_REF#refs/*/}"
67+
echo "Extracted ref from GITHUB_REF: $REF_NAME"
68+
fi
3569
echo "ref_name=$REF_NAME" >> $GITHUB_OUTPUT
36-
echo "Extracted ref: $REF_NAME"
70+
echo "Final ref: $REF_NAME"
3771
3872
build-and-deploy:
3973
permissions:
4074
contents: write
4175
needs: extract_branch_or_tag
4276
runs-on: ubuntu-latest
77+
outputs:
78+
synced_ref: ${{ steps.sync-result.outputs.synced_ref }}
4379
steps:
4480
- name: full-checkout
4581
uses: actions/checkout@v4
@@ -52,20 +88,25 @@ jobs:
5288
persist-credentials: true
5389

5490
- name: push-mirror-repo
91+
id: sync-result
5592
env:
5693
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
5794
SOURCE_REF: ${{ needs.extract_branch_or_tag.outputs.ref_name }}
58-
TARGET_BRANCH_INPUT: ${{ github.event.inputs.target_branch }}
95+
TARGET_REF: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.target_ref || inputs.target_ref }}
5996
run: |
6097
echo "Source reference: $SOURCE_REF"
6198
git pull origin "$SOURCE_REF"
6299
git remote add mirror https://github.com/flexcompute-readthedocs/tidy3d-docs.git
63100
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
101+
if [[ -n "$TARGET_REF" ]]; then
102+
echo "Pushing contents of '$SOURCE_REF' to remote ref '$TARGET_REF'."
103+
git push mirror "$SOURCE_REF:refs/heads/$TARGET_REF" --force
104+
SYNCED_REF="$TARGET_REF"
67105
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.
106+
echo "Pushing '$SOURCE_REF' to the same ref on the mirror."
70107
git push mirror "$SOURCE_REF" --force
108+
SYNCED_REF="$SOURCE_REF"
71109
fi
110+
111+
echo "synced_ref=$SYNCED_REF" >> $GITHUB_OUTPUT
112+
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"

.github/workflows/tidy3d-python-client-develop-cli.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,28 @@ name: "public/tidy3d/python-client-develop-cli"
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
release_tag:
7+
description: 'Release Tag (v2.10.0, v2.10.0rc1)'
8+
required: false
9+
type: string
10+
default: ''
11+
12+
workflow_call:
13+
inputs:
14+
release_tag:
15+
description: 'Release Tag (v2.10.0, v2.10.0rc1)'
16+
required: false
17+
type: string
18+
default: ''
19+
outputs:
20+
workflow_success:
21+
description: 'CLI tests workflow success status'
22+
value: ${{ jobs.test-dev-commands.result == 'success' }}
23+
524
schedule:
625
- cron: '0 2 * * *' # Runs every day at 2:00 AM UTC
26+
727
push:
828
branches:
929
- develop
@@ -14,16 +34,27 @@ permissions:
1434

1535
jobs:
1636
test-dev-commands:
37+
env:
38+
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.release_tag || inputs.release_tag }}
1739
strategy:
1840
matrix:
1941
os: [ubuntu-latest, windows-latest, macos-latest]
2042
runs-on: ${{ matrix.os }}
2143

2244
steps:
23-
- name: Checkout code
45+
- name: Checkout code (HEAD)
46+
if: ${{ !env.RELEASE_TAG }}
2447
uses: actions/checkout@v4
2548
with:
26-
ref: develop
49+
fetch-depth: 1
50+
submodules: false
51+
persist-credentials: false
52+
53+
- name: Checkout code (TAG)
54+
if: ${{ env.RELEASE_TAG }}
55+
uses: actions/checkout@v4
56+
with:
57+
ref: refs/tags/${{ env.RELEASE_TAG }}
2758
fetch-depth: 1
2859
submodules: false
2960
persist-credentials: false

0 commit comments

Comments
 (0)