Debian Codegraph @

.github/workflows/merge.yml

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