-
Notifications
You must be signed in to change notification settings - Fork 1
113 lines (100 loc) · 3.5 KB
/
publish.yml
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
name: Test, Build, and Publish
on:
push:
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false
dry_run:
type: boolean
description: 'Do not actually release the package, just check that it is valid.'
required: false
default: false
jobs:
run-tests:
uses: ./.github/workflows/test.yml
with:
debug_enabled: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
secrets: inherit
check-tag:
needs:
- run-tests
runs-on: ubuntu-latest
outputs:
tag-matches-version: ${{ steps.check-tag.outputs.tag-matches-version }}
fail-reason: ${{ steps.check-tag.outputs.fail-reason }}
steps:
- uses: actions/checkout@v4
- name: Install hatch
run: |
python -m pip install hatch
- name: Check tag matches version
id: check-tag
run: |
# Check if the tag matches the version or the version with a 'v' prefix
tag="$(git tag --points-at HEAD)"
# validate tag
if [[ "$tag" == "" || "$tag" == "v" || "$tag" == "vv"* ]]; then
echo "tag-matches-version=false" >> $GITHUB_OUTPUT
echo "fail-reason=tag not valid" >> $GITHUB_OUTPUT
exit 0
fi
hatch_version="$(hatch version)"
if [[ "$tag" == "v$hatch_version" || "$tag" == "$hatch_version" ]]; then
echo "tag-matches-version=true" >> $GITHUB_OUTPUT
else
echo "tag-matches-version=false" >> $GITHUB_OUTPUT
echo "fail-reason=v?tag != version" >> $GITHUB_OUTPUT
fi
publish-pypi:
runs-on: ubuntu-latest
needs:
- check-tag
if: github.event.inputs.dry-run != 'true' && needs.check-tag.outputs.tag-matches-version == 'true'
environment:
name: pypi
url: https://pypi.org/p/galv-harvester
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- uses: actions/checkout@v4
- name: Install hatch
run: |
python -m pip install hatch
- name: Build dist
run: hatch run +py=3.11 build
- name: Publish 🐍 📦 to PyPI
# run if not dry-run AND we're pushing to a tag
uses: pypa/gh-action-pypi-publish@release/v1
publish-testpypi:
runs-on: ubuntu-latest
needs:
- check-tag
if: github.event.inputs.dry-run == 'true' || needs.check-tag.outputs.tag-matches-version != 'true'
environment:
name: testpypi
url: https://test.pypi.org/p/galv-harvester
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- uses: actions/checkout@v4
- name: Install hatch
run: |
python -m pip install hatch
- name: Build dist
run: hatch run +py=3.11 build
- name: Publish 🐍 📦 to TestPyPI (dry-run)
if: github.event.inputs.dry-run == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
- name: Publish 🐍 📦 to TestPyPI (${{ steps.check-tag.outputs.fail-reason }})
if: github.event.inputs.dry-run != 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true