Debian Codegraph @

.github/workflows/publish-release.yml

raw symbols SCIP
1 name: Publish Release
2 run-name: "Publish Release (pypi_target=${{ inputs.pypi_target }}, repo_release_ref=${{ inputs.repo_release_ref }})"
3
4 on:
5 # Trigger release workflow from other workflows (e.g. release dev build as part of CI)
6 workflow_call:
7 inputs:
8 pypi_target:
9 description: "PyPI repository to publish to"
10 required: true
11 type: string
12 default: "test.pypi.org"
13 repo_release_ref:
14 description: "Gitlint git reference to publish release for"
15 type: string
16 default: "main"
17
18 # Manually trigger a release
19 workflow_dispatch:
20 inputs:
21 pypi_target:
22 description: "PyPI repository to publish to"
23 required: true
24 type: choice
25 options:
26 - "pypi.org"
27 - "test.pypi.org"
28 default: "test.pypi.org"
29 repo_release_ref:
30 description: "Gitlint git reference to publish release for"
31 type: string
32 default: "main"
33
34 jobs:
35 publish:
36 timeout-minutes: 15
37 runs-on: "ubuntu-latest"
38 outputs:
39 gitlint_version: ${{ steps.set_version.outputs.gitlint_version }}
40 steps:
41 - name: Setup python
42 uses: actions/[email protected]
43 with:
44 python-version: "3.11"
45
46 - name: Install pypa/build
47 run: python -m pip install build==0.10.0
48
49 - name: Install Hatch
50 run: python -m pip install hatch==1.6.3
51
52 - uses: actions/[email protected]
53 with:
54 ref: ${{ inputs.repo_release_ref }}
55 fetch-depth: 0 # checkout all history, needed for hatch versioning
56
57 # Run hatch version once to avoid additional output ("Setting up build environment for missing dependencies")
58 # during the next step
59 - name: Hatch version
60 run: hatch version
61
62 # Hatch versioning is based on git (using hatch-vcs). If there is no explicit tag for the commit we're trying to
63 # publish, hatch versioning strings will have this format: 0.19.0.dev52+g9f7dc7d
64 # With the string after '+' being the 'g<short-sha>' of the commit.
65 #
66 # However, PyPI doesn't allow '+' in version numbers (no PEP440 local versions allowed on PyPI).
67 # To work around this, we override the version string by setting the SETUPTOOLS_SCM_PRETEND_VERSION env var
68 # to the version string without the '+' and everything after it.
69 # We do this by setting the `gitlint_version` step output here and re-using it later to
70 # set SETUPTOOLS_SCM_PRETEND_VERSION.
71 #
72 # We only actually publish such releases on the main branch to guarantee the dev numbering scheme remains
73 # unique.
74 # Note that when a tag *is* present (i.e. v0.19.0), hatch versioning will return the tag name (i.e. 0.19.0)
75 # and this step has no effect, ie. SETUPTOOLS_SCM_PRETEND_VERSION will be the same as `hatch version`.
76 - name: Set SETUPTOOLS_SCM_PRETEND_VERSION
77 id: set_version
78 run: |
79 echo "gitlint_version=$(hatch version | cut -d+ -f1)" >> $GITHUB_OUTPUT
80
81 - name: Build (gitlint-core)
82 run: python -m build
83 working-directory: ./gitlint-core
84 env:
85 SETUPTOOLS_SCM_PRETEND_VERSION: ${{ steps.set_version.outputs.gitlint_version }}
86
87 - name: Build (gitlint)
88 run: python -m build
89 env:
90 SETUPTOOLS_SCM_PRETEND_VERSION: ${{ steps.set_version.outputs.gitlint_version }}
91
92 - name: Publish gitlint-core (pypi.org)
93 run: hatch publish
94 working-directory: ./gitlint-core
95 env:
96 HATCH_INDEX_USER: ${{ secrets.PYPI_GITLINT_CORE_USERNAME }}
97 HATCH_INDEX_AUTH: ${{ secrets.PYPI_GITLINT_CORE_PASSWORD }}
98 if: inputs.pypi_target == 'pypi.org'
99
100 - name: Publish gitlint (pypi.org)
101 run: hatch publish
102 env:
103 HATCH_INDEX_USER: ${{ secrets.PYPI_GITLINT_USERNAME }}
104 HATCH_INDEX_AUTH: ${{ secrets.PYPI_GITLINT_PASSWORD }}
105 if: inputs.pypi_target == 'pypi.org'
106
107 - name: Publish gitlint-core (test.pypi.org)
108 run: hatch publish -r test
109 working-directory: ./gitlint-core
110 env:
111 HATCH_INDEX_USER: ${{ secrets.TEST_PYPI_GITLINT_CORE_USERNAME }}
112 HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_GITLINT_CORE_PASSWORD }}
113 if: inputs.pypi_target == 'test.pypi.org'
114
115 - name: Publish gitlint (test.pypi.org)
116 run: hatch publish -r test
117 env:
118 HATCH_INDEX_USER: ${{ secrets.TEST_PYPI_GITLINT_USERNAME }}
119 HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_GITLINT_PASSWORD }}
120 if: inputs.pypi_target == 'test.pypi.org'
121
122 # Wait for gitlint package to be available in PyPI for installation
123 wait-for-package:
124 needs:
125 - publish
126 runs-on: "ubuntu-latest"
127 steps:
128 - name: Install gitlint
129 uses: nick-fields/[email protected]
130 with:
131 timeout_minutes: 1
132 max_attempts: 10
133 command: |
134 python -m pip install gitlint==${{ needs.publish.outputs.gitlint_version }}
135 if: inputs.pypi_target == 'pypi.org'
136
137 - name: Install gitlint (test.pypi.org)
138 uses: nick-fields/[email protected]
139 with:
140 timeout_minutes: 1
141 max_attempts: 10
142 command: |
143 pip install --no-cache-dir -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple gitlint==${{ needs.publish.outputs.gitlint_version }}
144 if: inputs.pypi_target == 'test.pypi.org'
145
146 - name: gitlint --version
147 run: |
148 gitlint --version
149 [ "$(gitlint --version)" == "gitlint, version ${{ needs.publish.outputs.gitlint_version }}" ]
150
151 # Unfortunately, it's not because the newly published package installation worked once that replication
152 # has finished amongst all PyPI servers (subsequent installations might still fail). We sleep for 10 min here
153 # to increase the odds that replication has finished.
154 - name: Sleep
155 run: sleep 600
156
157 test-release:
158 needs:
159 - publish
160 - wait-for-package
161 uses: ./.github/workflows/test-release.yml
162 with:
163 gitlint_version: ${{ needs.publish.outputs.gitlint_version }}
164 pypi_source: ${{ inputs.pypi_target }}
165 repo_test_ref: ${{ inputs.repo_release_ref }}
166
167 publish-docker:
168 needs:
169 - publish
170 - test-release
171 uses: ./.github/workflows/publish-docker.yml
172 secrets: inherit # pass all secrets (required to access secrets in a called workflow)
173 with:
174 gitlint_version: ${{ needs.publish.outputs.gitlint_version }}
175 docker_image_tag: "latest_dev"
176 push_to_dockerhub: true