Skip to content

Commit 7effe1d

Browse files
feat: add zerv-versioning (#112)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent a9e15ef commit 7effe1d

File tree

7 files changed

+533
-427
lines changed

7 files changed

+533
-427
lines changed

.github/workflows/cd.yml

Lines changed: 49 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,92 +4,64 @@ on:
44
push:
55
branches:
66
- main
7+
workflow_dispatch:
78

89
permissions:
910
contents: write
1011
issues: write
1112
pull-requests: write
1213

1314
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
15+
# ====================================================
16+
# Versioning and Release
17+
# ====================================================
18+
semantic-release:
19+
name: semantic-release
20+
uses: wislertt/zerv/.github/workflows/shared-semantic-release.yml@v0
21+
with:
22+
allowed_workflow_dispatch_branches: '["main"]'
23+
fail_on_invalid_workflow_dispatch_ref: true
2524

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
25+
zerv-versioning:
26+
needs: semantic-release
27+
if: needs.semantic-release.outputs.is_valid_semantic_release == 'true'
28+
uses: wislertt/zerv/.github/workflows/shared-zerv-versioning.yml@v0
3829

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 }}
30+
create-version-prefix-tags:
31+
needs: zerv-versioning
32+
uses: wislertt/zerv/.github/workflows/shared-create-tags.yml@v0
33+
with:
34+
tags: >-
35+
[
36+
"${{ fromJson(needs.zerv-versioning.outputs.versions).v_major }}",
37+
"${{ fromJson(needs.zerv-versioning.outputs.versions).v_major_minor }}"
38+
]
4539
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
40+
# ====================================================
41+
# Test and Lint
42+
# ====================================================
43+
test:
44+
uses: ./.github/workflows/test.yml
45+
secrets:
46+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
47+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5848

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
49+
# ====================================================
50+
# Deployment
51+
# ====================================================
52+
publish-pypi:
53+
needs: zerv-versioning
54+
uses: ./.github/workflows/publish.yml
55+
with:
56+
version: ${{ fromJson(needs.zerv-versioning.outputs.versions).pep440 }}
57+
secrets:
58+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
7259

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
60+
publish-test-pypi:
61+
needs: zerv-versioning
62+
uses: ./.github/workflows/publish.yml
63+
with:
64+
version: ${{ fromJson(needs.zerv-versioning.outputs.versions).pep440 }}
65+
repository_url: https://test.pypi.org/legacy/
66+
secrets:
67+
PYPI_API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}

.github/workflows/ci.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
types: [labeled, unlabeled, opened, synchronize, reopened]
6+
7+
permissions:
8+
contents: write
9+
id-token: write
10+
11+
jobs:
12+
# ====================================================
13+
# Versioning and Release
14+
# ====================================================
15+
check-pre-release:
16+
name: check-pre-release
17+
uses: wislertt/zerv/.github/workflows/shared-check-pr-label-and-branch.yml@v0
18+
with:
19+
target_label: "pre-release"
20+
branch_prefixes: '["release/"]'
21+
branch_names: '["develop"]'
22+
23+
zerv-versioning:
24+
name: zerv-versioning
25+
needs: check-pre-release
26+
uses: wislertt/zerv/.github/workflows/shared-zerv-versioning.yml@v0
27+
with:
28+
schema: ${{ (needs.check-pre-release.outputs.is_valid == 'true' && 'standard-base-prerelease-post') || '' }}
29+
30+
tag-pre-release:
31+
name: tag-pre-release
32+
needs: [zerv-versioning, check-pre-release]
33+
if: needs.check-pre-release.outputs.is_valid == 'true'
34+
uses: wislertt/zerv/.github/workflows/shared-create-tags.yml@v0
35+
with:
36+
tags: '["${{ fromJson(needs.zerv-versioning.outputs.versions).v_semver }}"]'
37+
38+
# ====================================================
39+
# Test and Lint
40+
# ====================================================
41+
test:
42+
name: test
43+
uses: ./.github/workflows/test.yml
44+
secrets:
45+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
46+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
47+
48+
test-reproducibility:
49+
name: test-reproducibility
50+
uses: ./.github/workflows/test-reproducibility.yml
51+
52+
pre-commit:
53+
name: pre-commit
54+
uses: ./.github/workflows/pre-commit.yml
55+
56+
# ====================================================
57+
# Deployment
58+
# ====================================================
59+
publish-test-pypi:
60+
if: needs.check-pre-release.outputs.is_valid == 'true'
61+
needs: [zerv-versioning, check-pre-release]
62+
uses: ./.github/workflows/publish.yml
63+
with:
64+
version: ${{ fromJson(needs.zerv-versioning.outputs.versions).pep440 }}
65+
repository_url: https://test.pypi.org/legacy/
66+
secrets:
67+
PYPI_API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
name: ci
1+
name: pre-commit
22

33
on:
4-
pull_request:
5-
types: [opened, synchronize, reopened]
4+
workflow_call:
5+
inputs:
6+
python_version:
7+
description: "Python version to use"
8+
required: false
9+
type: string
10+
default: "3.14"
611

712
jobs:
813
pre-commit:
@@ -16,7 +21,7 @@ jobs:
1621

1722
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
1823
with:
19-
python-version: "3.14"
24+
python-version: ${{ inputs.python_version }}
2025

2126
- name: Install Poetry
2227
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1

.github/workflows/publish.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: publish-python-package
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
required: true
8+
type: string
9+
description: "PEP440 version string"
10+
repository_url:
11+
required: false
12+
type: string
13+
description: "PyPI repository URL (default: official PyPI)"
14+
default: ""
15+
secrets:
16+
PYPI_API_TOKEN:
17+
required: true
18+
19+
jobs:
20+
publish:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
26+
27+
- name: Update version in pyproject.toml
28+
run: |
29+
sed -i.bak 's/^version = .*/version = "${{ inputs.version }}"/' pyproject.toml
30+
grep '^version' pyproject.toml
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
34+
with:
35+
python-version: "3.14"
36+
37+
- name: Install uv
38+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7.1.6
39+
with:
40+
version: "latest"
41+
42+
- name: Build package
43+
run: uv build
44+
45+
- name: Publish to PyPI
46+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
47+
with:
48+
repository-url: ${{ inputs.repository_url || '' }}
49+
password: ${{ secrets.PYPI_API_TOKEN }}
50+
verbose: true
51+
skip-existing: true

.github/workflows/ci-test-reproducibility.yml renamed to .github/workflows/test-reproducibility.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
name: ci
1+
name: test-reproducibility
22

33
on:
4-
push:
5-
branches: [main]
6-
pull_request:
7-
types: [opened, synchronize, reopened]
4+
workflow_call:
5+
inputs:
6+
python_version:
7+
description: "Python version to use"
8+
required: false
9+
type: string
10+
default: "3.14"
811

912
jobs:
1013
test-reproducibility:
@@ -16,7 +19,7 @@ jobs:
1619
- name: Set up Python
1720
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
1821
with:
19-
python-version: "3.14"
22+
python-version: ${{ inputs.python_version }}
2023

2124
- name: Install Poetry
2225
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
name: ci
1+
name: test
22

33
on:
4-
push:
5-
branches: [main]
6-
pull_request:
7-
types: [opened, synchronize, reopened]
8-
9-
env:
10-
TARGET_PYTHON_VERSION: "3.14"
4+
workflow_call:
5+
inputs:
6+
target_python_version:
7+
description: "Target Python version for SonarQube and Codecov"
8+
required: false
9+
type: string
10+
default: "3.14"
11+
secrets:
12+
SONAR_TOKEN:
13+
required: false
14+
CODECOV_TOKEN:
15+
required: false
1116

1217
jobs:
1318
test:
@@ -76,14 +81,14 @@ jobs:
7681
run: make test
7782

7883
- name: SonarQube Scan
79-
if: matrix.python-version == env.TARGET_PYTHON_VERSION && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
80-
uses: SonarSource/sonarqube-scan-action@fd88b7d7ccbaefd23d8f36f73b59db7a3d246602 # v6.0.0
84+
if: matrix.python-version == inputs.target_python_version && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
85+
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0
8186
env:
8287
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
8388

8489
- name: Upload coverage reports to Codecov
85-
if: matrix.python-version == env.TARGET_PYTHON_VERSION && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
86-
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
90+
if: matrix.python-version == inputs.target_python_version && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
91+
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
8792
with:
8893
fail_ci_if_error: true
8994
token: ${{ secrets.CODECOV_TOKEN }}

0 commit comments

Comments
 (0)