-
Notifications
You must be signed in to change notification settings - Fork 1
executable file
·138 lines (121 loc) · 3.77 KB
/
Copy pathrelease.yml
File metadata and controls
executable file
·138 lines (121 loc) · 3.77 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
129
130
131
132
133
134
135
136
137
138
name: Release
on:
workflow_dispatch:
inputs:
publish-destination:
description: 'Publish destination (main branch only)'
required: true
default: "test.pypi"
type: choice
options:
- pypi
- test.pypi
pypi-tag:
description: 'Git tag to release to PyPI, e.g. v2.2.1 (required when destination is pypi; ignored for test.pypi)'
required: false
type: string
permissions:
contents: read
jobs:
publish-check:
runs-on: ubuntu-latest
steps:
- name: Check preconditions
run: |
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "This workflow can only be triggered from the main branch."
exit 1
fi
if [ "${{ inputs.publish-destination }}" = "pypi" ] && [ -z "${{ inputs.pypi-tag }}" ]; then
echo "Please provide the git tag to release to PyPI (e.g. v2.2.1)."
exit 1
fi
- name: Checkout repository
if: inputs.publish-destination == 'pypi'
uses: actions/checkout@v5
with:
fetch-tags: true
fetch-depth: 0
- name: Validate PyPI tag
if: inputs.publish-destination == 'pypi'
run: |
if ! git rev-parse -q --verify "refs/tags/${{ inputs.pypi-tag }}" >/dev/null; then
echo "::error::Tag '${{ inputs.pypi-tag }}' was not found in this repository. Check the tag name (e.g. v2.2.1) and try again."
exit 1
fi
build:
needs: [publish-check]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
ref: ${{ inputs.publish-destination == 'pypi' && inputs.pypi-tag || github.ref_name }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install build
run: pip install build
- name: Build distributions
run: python -m build
- name: Upload distributions
uses: actions/upload-artifact@v7
with:
name: dist
path: dist/
publish-pypi:
name: Publish to PyPI
needs: build
if: inputs.publish-destination == 'pypi'
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
publish-testpypi:
name: Publish to TestPyPI
needs: build
if: inputs.publish-destination == 'test.pypi'
runs-on: ubuntu-latest
environment: testpypi
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
tag:
name: Create git tag
needs: [publish-testpypi]
if: inputs.publish-destination == 'test.pypi'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Determine version
id: version
run: |
VERSION=$(grep -oP '(?<=^__version__ = ")[^"]+' src/powersensor_local/__init__.py)
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"