Skip to content

Commit bd0f712

Browse files
committed
ci: dev
1 parent 8a956b8 commit bd0f712

File tree

2 files changed

+47
-83
lines changed

2 files changed

+47
-83
lines changed

.github/workflows/cd.yml

Lines changed: 47 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,60 @@
11
name: cd
22

3+
# Note: Ensure CD pipeline is idempotent to safely handle re-runs from push,
4+
# workflow dispatch, and tag versioning triggers
35
on:
46
push:
57
branches:
68
- main
9+
workflow_dispatch:
710

811
permissions:
912
contents: write
1013
issues: write
1114
pull-requests: write
1215

1316
jobs:
14-
versioning:
15-
name: versioning
16-
runs-on: ubuntu-latest
17-
outputs:
18-
new_release_version: ${{ steps.set-outputs.outputs.version }}
19-
new_release_published: ${{ steps.set-outputs.outputs.published }}
20-
steps:
21-
- name: Checkout
22-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
23-
with:
24-
fetch-depth: 0
25-
26-
- name: Check existing release
27-
id: check-release
28-
run: |
29-
CURRENT_SHA=$(git rev-parse HEAD)
30-
EXISTING_TAG=$(git tag --points-at $CURRENT_SHA | grep '^v' | head -1)
31-
if [ -n "$EXISTING_TAG" ]; then
32-
echo "existing_tag=$EXISTING_TAG" >> $GITHUB_OUTPUT
33-
echo "existing_version=${EXISTING_TAG#v}" >> $GITHUB_OUTPUT
34-
echo "has_existing=true" >> $GITHUB_OUTPUT
35-
else
36-
echo "has_existing=false" >> $GITHUB_OUTPUT
37-
fi
38-
39-
- id: release
40-
name: Release
41-
if: steps.check-release.outputs.has_existing == 'false'
42-
uses: cycjimmy/semantic-release-action@b12c8f6015dc215fe37bc154d4ad456dd3833c90 # v6.0.0
43-
env:
44-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45-
46-
- name: Set outputs
47-
id: set-outputs
48-
run: |
49-
if [ "${{ steps.check-release.outputs.has_existing }}" == "true" ]; then
50-
echo "version=${{ steps.check-release.outputs.existing_version }}" >> $GITHUB_OUTPUT
51-
echo "published=true" >> $GITHUB_OUTPUT
52-
echo "Using existing release: ${{ steps.check-release.outputs.existing_version }}"
53-
else
54-
echo "version=${{ steps.release.outputs.new_release_version }}" >> $GITHUB_OUTPUT
55-
echo "published=${{ steps.release.outputs.new_release_published }}" >> $GITHUB_OUTPUT
56-
echo "New release: ${{ steps.release.outputs.new_release_version }}"
57-
fi
58-
59-
publish:
60-
name: publish to pypi
61-
runs-on: ubuntu-latest
62-
needs: versioning
63-
if: needs.versioning.outputs.new_release_published == 'true'
64-
environment:
65-
name: pypi
66-
url: https://pypi.org/p/leetcode-py
67-
permissions:
68-
id-token: write
69-
steps:
70-
- name: Checkout
71-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
72-
73-
- name: Set up Python
74-
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
75-
with:
76-
python-version: "3.14"
77-
78-
- name: Install Poetry
79-
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
80-
with:
81-
version: latest
82-
virtualenvs-create: true
83-
virtualenvs-in-project: true
84-
85-
- name: Update version in pyproject.toml
86-
run: |
87-
poetry version ${{ needs.versioning.outputs.new_release_version }}
88-
89-
- name: Build package
90-
run: poetry build
91-
92-
- name: Publish to PyPI
93-
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
94-
with:
95-
verbose: true
17+
# ====================================================
18+
# Versioning and Release
19+
# ====================================================
20+
semantic-release:
21+
name: semantic-release
22+
uses: wislertt/zerv/.github/workflows/shared-semantic-release.yml@v0
23+
with:
24+
allowed_workflow_dispatch_branches: '["main"]'
25+
fail_on_invalid_workflow_dispatch_ref: true
26+
27+
zerv-versioning:
28+
needs: semantic-release
29+
if: needs.semantic-release.outputs.is_valid_semantic_release == 'true'
30+
uses: wislertt/zerv/.github/workflows/shared-zerv-versioning.yml@v0
31+
32+
create-version-prefix-tags:
33+
needs: zerv-versioning
34+
uses: wislertt/zerv/.github/workflows/shared-create-tags.yml@v0
35+
with:
36+
tags: >-
37+
[
38+
"${{ fromJson(needs.zerv-versioning.outputs.versions).v_major }}",
39+
"${{ fromJson(needs.zerv-versioning.outputs.versions).v_major_minor }}"
40+
]
41+
42+
# ====================================================
43+
# Test and Lint
44+
# ====================================================
45+
test:
46+
uses: ./.github/workflows/test.yml
47+
secrets:
48+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
49+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
50+
51+
# ====================================================
52+
# Deployment
53+
# ====================================================
54+
publish-pypi:
55+
needs: zerv-versioning
56+
uses: ./.github/workflows/publish.yml
57+
with:
58+
version: ${{ fromJson(needs.zerv-versioning.outputs.versions).pep440 }}
59+
secrets:
60+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ jobs:
5959
# Deployment
6060
# ====================================================
6161
publish-test-pypi:
62-
name: publish-to-test-pypi
6362
if: needs.check-pre-release.outputs.is_valid == 'true'
6463
needs: [zerv-versioning, check-pre-release]
6564
uses: ./.github/workflows/publish.yml

0 commit comments

Comments
 (0)