-
Notifications
You must be signed in to change notification settings - Fork 12
175 lines (155 loc) · 5.47 KB
/
Copy pathcreate-release.yaml
File metadata and controls
175 lines (155 loc) · 5.47 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
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
name: Create Release
on:
workflow_dispatch:
inputs:
package-version:
description: "Package version"
required: false
default: ""
type: string
permissions:
contents: write # Allow to commit and push.
env:
DEFAULT_PYTHON_VERSION: "3.13"
jobs:
#----------------------------------------------
# Prepare
prepare:
name: Prepare
outputs:
package-version: ${{ steps.select-package-version.outputs.package-version }}
default_python_version: ${{ env.DEFAULT_PYTHON_VERSION }}
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# Display Github environment variables
- name: Display Github environment variables
run: printenv | grep '^GITHUB_' | sort
#----------------------------------------------
# Check-out repo
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
#----------------------------------------------
# Compute the version of the project based in the current checkout branch
- name: Compute version
id: compute-version
uses: ./.github/workflows/compute-version
if: ${{ inputs.package-version == '' }}
#----------------------------------------------
# Select package version
- name: Select package version
id: select-package-version
run: |
if [ -z "${{ inputs.package-version }}" ]; then
echo "package-version=${{ steps.compute-version.outputs.pep440-version }}" >> $GITHUB_OUTPUT
else
echo "package-version=${{ inputs.package-version }}" >> $GITHUB_OUTPUT
fi
#----------------------------------------------
# Display versions
- name: Display versions
run: |
echo "package-version=${{ steps.select-package-version.outputs.package-version }}"
echo "default-python-version=${{ env.DEFAULT_PYTHON_VERSION }}"
#----------------------------------------------
# Build and publish the pip package and docker image
build:
name: Build
needs: prepare
runs-on: "ubuntu-latest"
steps:
#----------------------------------------------
# Checkout repo
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-tags: true
#----------------------------------------------
# Install & configure poetry -----
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
#----------------------------------------------
- name: Bump version to ${{ needs.prepare.outputs.package-version }}
run: poetry version ${{ needs.prepare.outputs.package-version }}
#----------------------------------------------
# Commit the changes
- name: Commit changes
if: true
run: |
git config --global user.name github-actions
git config --global user.email github-actions@github.com
git add pyproject.toml
git commit --allow-empty -m "Bump version to ${{ needs.prepare.outputs.package-version }}"
git push
#----------------------------------------------
# Tag the commit
- name: Git tag
if: true
uses: ./.github/workflows/git-tag
with:
tag-name: ${{ needs.prepare.outputs.package-version }}
#----------------------------------------------
# Set-up python
- uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
#----------------------------------------------
- name: Build package
run: poetry build
#----------------------------------------------
- name: Upload package
uses: actions/upload-artifact@v4
with:
name: pygazpar
path: dist/
#----------------------------------------------
# Publish to PyPI
publish-to-pypi:
name: Publish to PyPI
runs-on: "ubuntu-latest"
needs: build
if: ${{ startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/release/') }}
environment:
name: pypi
url: https://pypi.org/p/pygazpar
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download the package
uses: actions/download-artifact@v4
with:
name: pygazpar
path: dist/
- name: Publish 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
#----------------------------------------------
# Publish to TestPyPI
publish-to-testpypi:
name: Publish to TestPyPI
runs-on: "ubuntu-latest"
needs: build
if: ${{ !startsWith(github.ref, 'refs/heads/main') && !startsWith(github.ref, 'refs/heads/develop') && !startsWith(github.ref, 'refs/heads/release/') }}
environment:
name: testpypi
url: https://test.pypi.org/p/pygazpar
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download the package
uses: actions/download-artifact@v4
with:
name: pygazpar
path: dist/
- name: Publish 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
verbose: true