blob: 22ac4bedf0c5f91944a8e83931775259426b6471 (
plain)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
name: Publish Release
run-name: "Publish Release (pypi_target=${{ inputs.pypi_target }}, repo_release_ref=${{ inputs.repo_release_ref }})"
on:
# Trigger release workflow from other workflows (e.g. release dev build as part of CI)
workflow_call:
inputs:
pypi_target:
description: "PyPI repository to publish to"
required: true
type: string
default: "test.pypi.org"
repo_release_ref:
description: "Gitlint git reference to publish release for"
type: string
default: "main"
# Manually trigger a release
workflow_dispatch:
inputs:
pypi_target:
description: "PyPI repository to publish to"
required: true
type: choice
options:
- "pypi.org"
- "test.pypi.org"
default: "test.pypi.org"
repo_release_ref:
description: "Gitlint git reference to publish release for"
type: string
default: "main"
jobs:
publish:
timeout-minutes: 15
runs-on: "ubuntu-latest"
outputs:
gitlint_version: ${{ steps.set_version.outputs.gitlint_version }}
steps:
- name: Setup python
uses: actions/setup-python@v4.5.0
with:
python-version: "3.11"
- name: Install pypa/build
run: python -m pip install build==0.10.0
- name: Install Hatch
run: python -m pip install hatch==1.6.3
- uses: actions/checkout@v3.3.0
with:
ref: ${{ inputs.repo_release_ref }}
fetch-depth: 0 # checkout all history, needed for hatch versioning
# Run hatch version once to avoid additional output ("Setting up build environment for missing dependencies")
# during the next step
- name: Hatch version
run: hatch version
# Hatch versioning is based on git (using hatch-vcs). If there is no explicit tag for the commit we're trying to
# publish, hatch versioning strings will have this format: 0.19.0.dev52+g9f7dc7d
# With the string after '+' being the 'g<short-sha>' of the commit.
#
# However, PyPI doesn't allow '+' in version numbers (no PEP440 local versions allowed on PyPI).
# To work around this, we override the version string by setting the SETUPTOOLS_SCM_PRETEND_VERSION env var
# to the version string without the '+' and everything after it.
# We do this by setting the `gitlint_version` step output here and re-using it later to
# set SETUPTOOLS_SCM_PRETEND_VERSION.
#
# We only actually publish such releases on the main branch to guarantee the dev numbering scheme remains
# unique.
# Note that when a tag *is* present (i.e. v0.19.0), hatch versioning will return the tag name (i.e. 0.19.0)
# and this step has no effect, ie. SETUPTOOLS_SCM_PRETEND_VERSION will be the same as `hatch version`.
- name: Set SETUPTOOLS_SCM_PRETEND_VERSION
id: set_version
run: |
echo "gitlint_version=$(hatch version | cut -d+ -f1)" >> $GITHUB_OUTPUT
- name: Build (gitlint-core)
run: python -m build
working-directory: ./gitlint-core
env:
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ steps.set_version.outputs.gitlint_version }}
- name: Build (gitlint)
run: python -m build
env:
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ steps.set_version.outputs.gitlint_version }}
- name: Publish gitlint-core (pypi.org)
run: hatch publish
working-directory: ./gitlint-core
env:
HATCH_INDEX_USER: ${{ secrets.PYPI_GITLINT_CORE_USERNAME }}
HATCH_INDEX_AUTH: ${{ secrets.PYPI_GITLINT_CORE_PASSWORD }}
if: inputs.pypi_target == 'pypi.org'
- name: Publish gitlint (pypi.org)
run: hatch publish
env:
HATCH_INDEX_USER: ${{ secrets.PYPI_GITLINT_USERNAME }}
HATCH_INDEX_AUTH: ${{ secrets.PYPI_GITLINT_PASSWORD }}
if: inputs.pypi_target == 'pypi.org'
- name: Publish gitlint-core (test.pypi.org)
run: hatch publish -r test
working-directory: ./gitlint-core
env:
HATCH_INDEX_USER: ${{ secrets.TEST_PYPI_GITLINT_CORE_USERNAME }}
HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_GITLINT_CORE_PASSWORD }}
if: inputs.pypi_target == 'test.pypi.org'
- name: Publish gitlint (test.pypi.org)
run: hatch publish -r test
env:
HATCH_INDEX_USER: ${{ secrets.TEST_PYPI_GITLINT_USERNAME }}
HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_GITLINT_PASSWORD }}
if: inputs.pypi_target == 'test.pypi.org'
# Wait for gitlint package to be available in PyPI for installation
wait-for-package:
needs:
- publish
runs-on: "ubuntu-latest"
steps:
- name: Install gitlint
uses: nick-fields/retry@v2.8.3
with:
timeout_minutes: 1
max_attempts: 10
command: |
python -m pip install gitlint==${{ needs.publish.outputs.gitlint_version }}
if: inputs.pypi_target == 'pypi.org'
- name: Install gitlint (test.pypi.org)
uses: nick-fields/retry@v2.8.3
with:
timeout_minutes: 1
max_attempts: 10
command: |
pip install --no-cache-dir -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple gitlint==${{ needs.publish.outputs.gitlint_version }}
if: inputs.pypi_target == 'test.pypi.org'
- name: gitlint --version
run: |
gitlint --version
[ "$(gitlint --version)" == "gitlint, version ${{ needs.publish.outputs.gitlint_version }}" ]
# Unfortunately, it's not because the newly published package installation worked once that replication
# has finished amongst all PyPI servers (subsequent installations might still fail). We sleep for 10 min here
# to increase the odds that replication has finished.
- name: Sleep
run: sleep 600
test-release:
needs:
- publish
- wait-for-package
uses: ./.github/workflows/test-release.yml
with:
gitlint_version: ${{ needs.publish.outputs.gitlint_version }}
pypi_source: ${{ inputs.pypi_target }}
repo_test_ref: ${{ inputs.repo_release_ref }}
publish-docker:
needs:
- publish
- test-release
uses: ./.github/workflows/publish-docker.yml
secrets: inherit # pass all secrets (required to access secrets in a called workflow)
with:
gitlint_version: ${{ needs.publish.outputs.gitlint_version }}
docker_image_tag: "latest_dev"
push_to_dockerhub: true
|