-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (65 loc) · 2.21 KB
/
Copy pathrelease.yaml
File metadata and controls
75 lines (65 loc) · 2.21 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
name: Release
on:
# Run when you push any tag
push:
tags:
- "*"
workflow_dispatch: # Allows manual trigger
inputs:
version:
description: "Version to publish, e.g. 1.3.4. Defaults to the version already in pyproject.toml."
required: false
type: string
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Determine version
id: get_version
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
# On a tag push GITHUB_REF_NAME is the tag itself ("1.2.3" or "v1.2.3").
# On a manual run it is the branch, so fall back to the input, and then
# to whatever pyproject.toml already declares.
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
VERSION="$GITHUB_REF_NAME"
elif [ -n "$INPUT_VERSION" ]; then
VERSION="$INPUT_VERSION"
else
VERSION=""
fi
echo "Version is ${VERSION:-<unset: keeping pyproject.toml>}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build twine mypy
- name: Set version from tag
if: steps.get_version.outputs.version != ''
env:
VERSION: ${{ steps.get_version.outputs.version }}
run: |
set -euo pipefail
sed -i "s/^version = .*/version = \"${VERSION}\"/" pyproject.toml
grep -n '^version' pyproject.toml
- name: Build sdist and wheel
# No flags: builds the sdist, then builds the wheel *from* that sdist,
# which verifies the sdist is complete enough to rebuild the package.
run: python -m build --outdir dist
- name: Check artifacts
run: |
ls -l dist
twine check dist/*
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}