Repository navigation
128 lines (107 loc) · 3.69 KB
/
Copy pathpython_package.yml
File metadata and controls
128 lines (107 loc) · 3.69 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
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Publish Python package
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
ref:
description: "Git ref to build and publish. Schema upload only runs if HEAD has a version tag."
required: true
permissions:
contents: read
jobs:
build:
name: Build package & schema
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
ref: ${{ github.event.inputs.ref || github.ref }}
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
version: "0.13.6"
python-version: 3.11
activate-environment: true
# A release build must not restore a cache other workflows could have written.
enable-cache: false
- name: Install python packages
run: uv sync --no-default-groups
- name: Build a binary wheel and a source tarball
run: uv build
- name: Generate OpenAPI schema
run: uv run python scripts/generate_openapi.py
- name: Upload package artifacts
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: pypi-dists
path: "./dist"
- name: Upload schema artifacts
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: openapi-schema
path: "./schema"
publish-pypi:
name: Publish to PyPI
needs: [build]
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/otf-api
permissions:
id-token: write
steps:
- name: Download package artifacts
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: pypi-dists
path: "./dist"
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # release/v1
upload-schema:
name: Upload schema to release
needs: [build]
if: >-
startsWith(github.ref, 'refs/tags/v')
|| (github.event_name == 'workflow_dispatch' && startsWith(github.event.inputs.ref, 'v'))
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download schema artifacts
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: openapi-schema
path: "./schema"
- name: Upload schema to release
run: |
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
TAG="$INPUT_REF"
else
TAG="$GITHUB_REF_NAME"
fi
echo "Uploading schema files to release ${TAG}..."
for i in 1 2 3; do
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
break
fi
echo "Release not found yet (attempt $i/3), waiting 10s..."
sleep 10
done
if ! gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
echo "Release ${TAG} not found after 3 attempts — cannot upload schema"
exit 1
fi
gh release upload "$TAG" ./schema/openapi.yaml ./schema/openapi.json \
--repo "$GITHUB_REPOSITORY" \
--clobber
echo "Schema files uploaded successfully!"
env:
GH_TOKEN: ${{ github.token }}
INPUT_REF: ${{ github.event.inputs.ref }}