-
Notifications
You must be signed in to change notification settings - Fork 3
115 lines (105 loc) · 3.81 KB
/
merge.yml
File metadata and controls
115 lines (105 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Latest release
env:
CACHE_VERSION: 2
DEFAULT_PYTHON: "3.14"
on:
push:
branches:
- main
jobs:
determine_version:
name: Determine Package Version
runs-on: ubuntu-latest
outputs:
package_version: ${{ steps.get_version.outputs.package_version }}
should_publish: ${{ steps.scheck_pypi.outputs.should_publish }}
permissions:
contents: read
steps:
- name: Check out committed code
uses: actions/checkout@v6
- name: Get Package Version from pyproject.toml
id: get_version
run: |
# Install toml to parse pyproject.toml
pip install toml
PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
# Set outputs for the next jobs
echo "package_version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
echo "Package name and version: $PACKAGE_NAME==$PACKAGE_VERSION"
- name: Check for existing package on PyPI
id: scheck_pypi
run: |
# Using the package name and version from the previous step
PACKAGE_VERSION=${{ steps.get_version.outputs.package_version }}
PACKAGE_NAME=${{ steps.get_version.outputs.package_name }}
if curl -s "https://pypi.org/pypi/$PACKAGE_NAME/json" | jq -r '.releases | keys[]' | grep -q "^$PACKAGE_VERSION$"; then
echo "Package version already exists. Skipping upload."
echo "should_publish=false" >> $GITHUB_OUTPUT
else
echo "Package version does not exist. Proceeding with upload."
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
publishing:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
needs: determine_version
if: needs.determine_version.outputs.should_publish == 'true'
environment: pypi
permissions:
contents: read
id-token: write
steps:
- name: Check out committed code
uses: actions/checkout@v6
- name: Prepare uv
run: |
pip install uv
uv venv --seed venv
. venv/bin/activate
- name: Build
run: |
. venv/bin/activate
uv build
- name: Publish distribution 📦 to PyPI
run: |
. venv/bin/activate
uv publish
create_tag:
name: Create Git Tag for Release
runs-on: ubuntu-latest
needs: [determine_version, publishing]
if: always() && needs.publishing.result == 'success' && needs.determine_version.outputs.should_publish == 'true'
permissions:
contents: write
steps:
- name: Check out committed code
uses: actions/checkout@v6
- name: Create release tag
id: tag_release
uses: actions/github-script@v9
with:
script: |
const version = process.env.PACKAGE_VERSION;
const tagName = `v${version}`;
console.log(`Attempting to create tag: ${tagName}`);
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: context.sha,
});
console.log(`Successfully created tag: ${tagName}`);
} catch (error) {
console.error(`Failed to create tag: ${error.message}`);
if (error.status === 422) {
console.log(`Tag ${tagName} already exists. Skipping creation.`);
} else {
throw error;
}
}
env:
PACKAGE_VERSION: ${{ needs.determine_version.outputs.package_version }}