-
Notifications
You must be signed in to change notification settings - Fork 4
236 lines (211 loc) · 7.7 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
name: Publish
on:
push:
branches:
# we publish to Test PyPI on pushes to the main branch
- "main"
tags:
- "v*"
env:
REGISTRY: 'ghcr.io'
IMAGE_NAME: ${{ github.repository }}
PYTHON_VERSION: '3.12'
POETRY_VERSION: '1.8.5'
permissions:
contents: read
concurrency:
group: publish-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
prepare:
if: github.repository == 'eclipse-csi/otterdog'
runs-on: ubuntu-22.04
outputs:
release-tag: ${{ steps.context.outputs.RELEASE_TAG }}
release-version: ${{ steps.context.outputs.RELEASE_VERSION }}
project-version: ${{ steps.context.outputs.PROJECT_VERSION }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
fetch-depth: 0
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
with:
virtualenvs-in-project: true
version: ${{ env.POETRY_VERSION }}
plugins: poetry-dynamic-versioning
- name: "Setup context"
id: context
shell: bash
env:
REF: ${{ github.ref }}
REF_NAME: ${{ github.ref_name }}
run: |
if [[ "${REF}" =~ ^refs/heads/.* ]]; then
echo "RELEASE_TAG=${REF_NAME}" >> $GITHUB_OUTPUT
# extract the current version from the pyproject.toml and replace .devN with -SNAPSHOT
VERSION=$(poetry version -s | sed 's/.dev[0-9]*/-SNAPSHOT/')
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_OUTPUT
PROJECT_VERSION=$(poetry version -s)
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_OUTPUT
else
echo "RELEASE_TAG=${REF_NAME}" >> $GITHUB_OUTPUT
VERSION=$(echo ${REF_NAME} | sed 's/v//')
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "PROJECT_VERSION=$VERSION" >> $GITHUB_OUTPUT
fi
build-and-push-image:
runs-on: ubuntu-22.04
needs: ['prepare']
permissions:
packages: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
ref: ${{ needs.release.outputs.release-tag }}
- name: "Log in to the Container registry"
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Extract metadata (tags, labels) for Docker"
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with:
tags: |
${{ needs.prepare.outputs.release-version }}
labels: |
org.opencontainers.image.version=${{ needs.prepare.outputs.release-version }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: "Build and push Docker image"
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
with:
context: .
file: docker/Dockerfile
build-args: |
version=${{ needs.prepare.outputs.project-version }}
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.release-version }}
labels: ${{ steps.meta.outputs.labels }}
build-dist:
runs-on: ubuntu-22.04
needs: ["prepare"]
outputs:
hashes: ${{ steps.hash.outputs.hashes }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ needs.prepare.outputs.release-tag }}
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
with:
virtualenvs-in-project: true
version: ${{ env.POETRY_VERSION }}
plugins: poetry-dynamic-versioning
- name: "Install dependencies"
run: poetry install --only=main
- name: "Build package"
run: poetry build
- name: "Generate hashes"
id: hash
run: |
cd dist && echo "hashes=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT
- name: "Upload dist"
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: "dist"
path: "dist/"
if-no-files-found: error
retention-days: 5
provenance:
needs: ['prepare', 'build-dist']
permissions:
actions: read
contents: write
id-token: write # Needed to access the workflow's OIDC identity.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] # ignore: pin
with:
base64-subjects: "${{ needs.build-dist.outputs.hashes }}"
upload-assets: true
github-publish:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-22.04
needs: ['prepare', 'build-dist', 'provenance']
permissions:
contents: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: "Download dists"
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: "dist"
path: "dist/"
- name: "Extract release notes"
id: extract-release-notes
uses: ffurrer2/extract-release-notes@9989ccec43d726ef05aa1cd7b2854fb96b6df6ab # v2.2.0
with:
release_notes_file: RELEASE_NOTES.md
- name: "Create GitHub release"
# keep at 2.1.0 due to https://github.com/softprops/action-gh-release/issues/556
uses: softprops/action-gh-release@01570a1f39cb168c169c802c3bceb9e93fb10974 # v2.1.0
with:
name: "Otterdog ${{ needs.prepare.outputs.release-tag }}"
tag_name: "${{ needs.prepare.outputs.release-tag }}"
body_path: RELEASE_NOTES.md
draft: false
prerelease: false
generate_release_notes: false
make_latest: true
files: dist/*
pypi-publish:
name: "Publish to PyPI"
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-22.04
needs: ['build-dist', 'provenance']
environment:
name: pypi
url: https://pypi.org/p/otterdog
permissions:
id-token: write
steps:
- name: "Download dists"
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: "dist"
path: "dist/"
- name: "Publish dists to PyPI"
uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3
with:
attestations: true
test-pypi-publish:
name: "Publish to Test PyPI"
if: startsWith(github.ref, 'refs/heads/')
runs-on: ubuntu-22.04
needs: ['build-dist', 'provenance']
environment:
name: test-pypi
permissions:
id-token: write
steps:
- name: "Download dists"
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: "dist"
path: "dist/"
- name: "Publish dists to Test PyPI"
uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3
with:
repository-url: https://test.pypi.org/legacy/
attestations: true
verbose: true