Repository navigation
111 lines (103 loc) · 3.68 KB
/
Copy pathrelease.yml
File metadata and controls
111 lines (103 loc) · 3.68 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
# Publishes didit-sdk to PyPI with trusted publishing (OIDC, no API token). It runs when
# release-please creates a release (release-please.yml starts it with the tag) or when a
# GitHub release is published by hand. The PyPI project lists this repository, the workflow
# release.yml and the environment pypi as a trusted publisher.
name: Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: Release tag to publish (for example v1.2.0); release-please starts this run
required: true
type: string
permissions:
contents: read
concurrency:
group: release-${{ github.event.release.tag_name || inputs.tag }}
cancel-in-progress: false
defaults:
run:
shell: bash
jobs:
build:
name: Build the distribution
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check out the release tag
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.release.tag_name || inputs.tag }}
persist-credentials: false
- name: Set up uv
uses: astral-sh/setup-uv@18d369b23da25a81e9458561248e1aafff6a70fa # v10.3.1
with:
# No dependency cache in the release build.
enable-cache: false
- name: Check that the release tag matches the package version
env:
RELEASE_TAG: ${{ github.event.release.tag_name || inputs.tag }}
run: |
uv run --no-project python - <<'PY'
import os
import pathlib
import re
import sys
import tomllib
tag = os.environ["RELEASE_TAG"]
text = pathlib.Path("src/didit/_version.py").read_text(encoding="utf-8")
match = re.search(r'^__version__ = "([^"]+)"', text, re.MULTILINE)
if match is None:
print("::error::Could not read __version__ from src/didit/_version.py")
sys.exit(1)
version = match.group(1)
pyproject = pathlib.Path("pyproject.toml").read_text(encoding="utf-8")
project_version = tomllib.loads(pyproject)["project"]["version"]
problems = []
if tag != f"v{version}":
problems.append(
f"Release tag {tag!r} does not match src/didit/_version.py "
f"({version}); expected 'v{version}'."
)
if project_version != version:
problems.append(
f"pyproject.toml version {project_version} does not match "
f"src/didit/_version.py ({version})."
)
for problem in problems:
print(f"::error::{problem}")
if problems:
sys.exit(1)
print(f"Release tag {tag} matches version {version}.")
PY
- name: Build the sdist and the wheel
run: uv build
- name: Upload the distribution
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dist
path: dist/
if-no-files-found: error
retention-days: 7
publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
environment:
name: pypi
url: https://pypi.org/project/didit-sdk/
permissions:
id-token: write # trusted publishing (OIDC)
steps:
- name: Download the distribution
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: dist/