10
10
tag :
11
11
description : ' Release tag for which to build'
12
12
required : true
13
- pypi_upload :
14
- description : ' upload to pypi'
15
- required : false
16
- type : choice
17
- options :
18
- - upload
19
- - skip
20
- default : ' upload'
21
13
22
14
jobs :
23
15
pypi :
@@ -27,30 +19,58 @@ jobs:
27
19
release : ${{ steps.name.outputs.release }}
28
20
url : ${{ steps.info.outputs.url }}
29
21
sha256 : ${{ steps.info.outputs.sha256 }}
22
+ changes : ${{ steps.changes.outputs.changes }}
30
23
31
24
steps :
25
+ - name : Set up Python
26
+ uses : actions/setup-python@v4
27
+ with :
28
+ python-version : ' 3.x'
29
+
30
+ - name : Install dependencies
31
+ run : |
32
+ sudo apt-get update -q
33
+ sudo apt-get install -qy pandoc
34
+ python -m pip install --break-system-packages --upgrade pip
35
+ pip install --break-system-packages setuptools wheel twine babel
36
+
32
37
- name : Define name
33
38
id : name
34
39
run : |
35
40
ref=${{ github.ref }}
36
41
[ "${ref::10}" = 'refs/tags/' ] && tag=${ref:10} || tag=${{ github.event.inputs.tag }}
37
42
if echo ${tag#v} | grep -qxE '[0-9]+(\.[0-9]+)*' ; then release=final; else release=prerelease; fi
38
- echo tag=${tag#v} | tee -a $GITHUB_OUTPUT
39
- echo release=$release | tee -a $GITHUB_OUTPUT
43
+ printf '%s\n' "tag=${tag#v}" "release=$release" | tee -a $GITHUB_OUTPUT
40
44
41
- - uses : actions/checkout@v4
42
- with :
43
- ref : v${{ steps.name.outputs.tag }}
45
+ - name : Lookup what is in pypi currently
46
+ id : prev
47
+ run : |
48
+ curl -sL "https://pypi.org/pypi/pympress/json" |
49
+ jq '.releases | to_entries | map(.key as $version | .value | map(select(.packagetype == "sdist")) | first | .version = $version) | sort_by(.upload_time) | last' \
50
+ > last.json
44
51
45
- - name : Set up Python
46
- uses : actions/setup-python@v4
47
- with :
48
- python-version : ' 3.x'
52
+ jq -r '"version=\(.version)","url=\(.url)","sha256=\(.digests.sha256)"' last.json | tee -a $GITHUB_OUTPUT
49
53
50
- - name : Install dependencies
54
+ - name : Extract changes from release
55
+ id : changes
56
+ shell :
57
+ bash
58
+ env :
59
+ tag : ${{ steps.name.outputs.tag }}
60
+ GITHUB_TOKEN : ${{ secrets.PYMPRESS_ACTION_PAT }}
51
61
run : |
52
- python -m pip install --upgrade pip
53
- pip install setuptools wheel twine babel
62
+ curl -s -u "Cimbali:$GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" -H "Accept: application/vnd.github+json" \
63
+ "https://api.github.com/repos/Cimbali/pympress/releases" -o - |
64
+ jq ".[] | select(.tag_name == \"v$tag\") | del(.author, .assets[].uploader)" | tee release.json
65
+
66
+ echo 'changes<<EOF' | tee -a $GITHUB_OUTPUT
67
+ jq -r .body release.json | sed '/\(New Contributors\|Full Changelog\)/,/^\s*$/d;s/^- / &/;1i- Update to v${{ steps.name.outputs.tag }}' |
68
+ pandoc --from=markdown --to=markdown --columns=67 | sed -r 's/^(\s+)-/\1*/;s/\#/#/g' | tee -a $GITHUB_OUTPUT
69
+ echo 'EOF' | tee -a $GITHUB_OUTPUT
70
+
71
+ - uses : actions/checkout@v4
72
+ with :
73
+ ref : v${{ steps.name.outputs.tag }}
54
74
55
75
- name : Build catalogs and packages
56
76
run : |
@@ -61,154 +81,160 @@ jobs:
61
81
env :
62
82
TWINE_USERNAME : __token__
63
83
TWINE_PASSWORD : ${{ secrets.PYPI_API_TOKEN }}
64
- if : ${{ github.event_name == 'release' || github.event.inputs.pypi_upload == 'upload' }}
84
+ if : github.event_name == 'release' && ( steps.prev.outputs.version != steps.name.outputs.tag )
65
85
run : |
66
86
twine upload dist/*
67
87
68
- - name : Get info from pypi
88
+ - name : Check info from pypi
69
89
id : info
70
90
env :
71
91
tag : ${{ steps.name.outputs.tag }}
72
92
run : |
73
93
# Get releases from pypi, exiting with non-zero if expected version not found
74
- jq_script=".releases.\"${tag}\"[]? | select(.python_version == \"source \")"
75
- while ! curl -s https://pypi.org/pypi/pympress/json | jq -r -e "$jq_script" > lastsource .json ; do
94
+ jq_script=".releases.\"${tag}\"[]? | select(.packagetype == \"sdist \")"
95
+ while ! curl -s https://pypi.org/pypi/pympress/json | jq -r -e "$jq_script" > updated .json ; do
76
96
sleep 60 # be patient with pypi
77
97
done
78
- echo url=`jq -r .url lastsource.json` | tee -a $GITHUB_OUTPUT
79
- echo sha256=` jq -r . digests.sha256 lastsource .json` | tee -a $GITHUB_OUTPUT
98
+
99
+ jq -r '"url=\(.url)","sha256=\(. digests.sha256)"' updated .json | tee -a $GITHUB_OUTPUT
80
100
81
101
- name : Run a check on the generated file
82
102
run : |
83
- if ! jq -r '"\(.digests.sha256) dist/\(.filename)"' lastsource .json | sha256sum -c ; then
103
+ if ! jq -r '"\(.digests.sha256) dist/\(.filename)"' updated .json | sha256sum -c ; then
84
104
echo '::warning:: Generated sdist file did not match pypi sha256sum'
85
105
fi
86
106
87
107
88
108
aur :
89
109
name : Publish to AUR
110
+ needs : pypi
90
111
runs-on : ubuntu-latest
91
112
steps :
92
113
- name : Clone repo
93
- run : git clone https://github.com/Cimbali/pympress-pkgbuild aur-repo
114
+ run : git clone https://Cimbali@ github.com/Cimbali/pympress-pkgbuild aur-repo
94
115
95
116
- name : Get info
96
117
id : info
118
+ env :
119
+ tag : ${{ needs.pypi.outputs.tag }}
97
120
run : |
98
- ref=${{ github.ref }}
99
- [ "${ref::10}" = 'refs/tags/' ] && tag=${ref:10} || tag=${{ github.event.inputs.tag }}
100
- tag=${tag#v}
101
-
102
- prev_pkgver=`awk -F= '$1 == "pkgver" {print $2}' aur-repo/PKGBUILD | tr -d "[()\"']"`
103
- if [[ "$prev_pkgver" = "$tag" ]]; then
104
- prev_pkgrel=`awk -F= '$1 == "pkgrel" {print $2}' aur-repo/PKGBUILD | tr -d "[()\"']"`
121
+ version=`awk -F= '$1 == "pkgver" {print $2}' aur-repo/PKGBUILD | tr -d "[()\"']"`
122
+ if [[ "$version" = "$tag" ]]; then
123
+ release=`awk -F= '$1 == "pkgrel" {print $2}' aur-repo/PKGBUILD | tr -d "[()\"']"`
105
124
else
106
- prev_pkrel =0
125
+ release =0
107
126
fi
108
127
109
- url="https://github.com/Cimbali/pympress/releases/download/v${tag}/pympress-${tag}.tar.gz"
110
- sha256=`curl -sL "$url" | sha256sum | awk '{ print $1 }'`
111
-
112
- printf '%s\n' "tag=$tag" "url=$url" "sha256=$sha256" "prev_pkgver=$prev_pkgver" "prev_pkgrel=$prev_pkgrel" |
113
- tee -a $GITHUB_OUTPUT
128
+ printf '%s\n' "version=$version" "release=$release" | tee -a $GITHUB_OUTPUT
114
129
115
130
- name : Update info
116
131
run : |
117
132
while read param value; do
118
133
sed -i -r "s,^(\\s*$param ?=[('\" ]*)[A-Za-z0-9\${\}:/._-]+([ '\")]*)$,\1$value\2," aur-repo/.SRCINFO aur-repo/PKGBUILD
119
134
done <<EOF
120
- source ${{ steps.info .outputs.url }}
121
- sha256sums ${{ steps.info .outputs.sha256 }}
122
- pkgver ${{ steps.info .outputs.tag }}
123
- pkgrel $(( ${{ steps.info.outputs.prev_pkgrel }} + 1 ))
135
+ source ${{ needs.pypi .outputs.url }}
136
+ sha256sums ${{ needs.pypi .outputs.sha256 }}
137
+ pkgver ${{ needs.pypi .outputs.tag }}
138
+ pkgrel $(( ${{ steps.info.outputs.release }} + 1 ))
124
139
EOF
125
140
141
+ head -n999 aur-repo/.SRCINFO aur-repo/PKGBUILD
142
+
126
143
- name : Push the changes
127
- if : ${{ steps.info.outputs.prev_pkgver }} != ${{ steps.info .outputs.tag }}
144
+ if : steps.info.outputs.version != needs.pypi .outputs.tag
128
145
run : |
129
146
cd aur-repo
130
147
git config user.name Cimbali
131
148
git config user.email [email protected]
132
149
echo -e "protocol=https\nhost=github.com\nusername=Cimbali\npassword=$PASSWORD" | git credential-store store
133
150
134
- git commit -am "Update to v${{ steps.info .outputs.tag }}"
151
+ git commit -am "Update to v${{ needs.pypi .outputs.tag }}"
135
152
git push origin "main:main"
136
153
137
154
env :
138
- AUR_PRIVATE_KEY : ${{ secrets.PYMPRESS_ACTION_PAT }}
155
+ PASSWORD : ${{ secrets.PYMPRESS_ACTION_PAT }}
139
156
140
157
141
- copr :
142
- name : Download source RPM from release and upload to COPR and OpenBuildService
158
+ obs :
159
+ name : Download source RPM from release and upload to OpenBuildService
160
+ needs : pypi
143
161
runs-on : ubuntu-latest
162
+ container : opensuse/tumbleweed
144
163
145
164
steps :
146
165
- name : Install dependencies
147
- run : |
148
- sudo apt-get update -q
149
- sudo apt-get install -qy osc cpio rpm2cpio pandoc python3-m2crypto
150
- python3 -m pip install copr-cli
166
+ run : zypper install -y curl jq awk osc
151
167
152
- - name : Get info
168
+ - name : Fetch info from OpenBuildService
153
169
id : info
154
170
run : |
155
- ref=${{ github.ref }}
156
- [ "${ref::10}" = 'refs/tags/' ] && tag=${ref:10} || tag=${{ github.event.inputs.tag }}
157
- tag=${tag#v}
171
+ trap 'rm -f ./osc-config' EXIT && echo "$OPENBUILDSERVICE_TOKEN_SECRET" > ./osc-config
172
+ osc="osc --config $GITHUB_WORKSPACE/osc-config"
158
173
159
- url="https://github.com/Cimbali/pympress/releases/download/v${tag}/pympress-${tag}.tar.gz"
160
- sha256=`curl -sL "$url" | sha256sum | awk ' { print $1 } '`
174
+ $osc co -o osc home:cimbali python-pympress
175
+ version=`awk -F: '$1 == "Version" { print $2 }' osc/pympress.spec | tr -d ' '`
161
176
162
- printf '%s\n' "tag=$tag" "url=$url" "sha256=$sha256" | tee -a $GITHUB_OUTPUT
177
+ echo version=$version | tee -a $GITHUB_OUTPUT
163
178
164
- - name : Extract changes from release
165
- shell :
166
- bash
179
+ if ! grep -qxFe '- Update to v$version' osc/pympress.changes; then
180
+ echo '::warning:: Last version missing from changelog'
181
+ fi
167
182
env :
168
- tag : ${{ steps.info.outputs.tag }}
169
- GITHUB_TOKEN : ${{ secrets.PYMPRESS_ACTION_PAT }}
170
- run : |
171
- curl -s -u "Cimbali:$GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" -H "Accept: application/vnd.github+json" \
172
- "https://api.github.com/repos/Cimbali/pympress/releases" -o - |
173
- jq ".[] | select(.tag_name == \"v$tag\") | del(.author, .assets[].uploader)" | tee release.json
174
-
175
- jq -r .body release.json | sed '/\(New Contributors\|Full Changelog\)/,/^\s*$/d;s/^- / &/;1i- Update to v${{ steps.info.outputs.tag }}' |
176
- pandoc --from=markdown --to=markdown --columns=67 | sed -r 's/^(\s+)-/\1*/;s/\#/#/g' | tee changes
183
+ OPENBUILDSERVICE_TOKEN_SECRET : ${{ secrets.OPENBUILDSERVICE_TOKEN_SECRET }}
177
184
178
185
- name : Upload to OpenBuildService
179
- continue-on-error : true
186
+ if : needs.pypi.outputs.tag != steps.info.outputs.version
180
187
run : |
181
188
trap 'rm -f ./osc-config' EXIT && echo "$OPENBUILDSERVICE_TOKEN_SECRET" > ./osc-config
182
189
osc="osc --config $GITHUB_WORKSPACE/osc-config"
190
+ cd osc
183
191
184
- $osc co -o osc home:cimbali python-pympress
185
- cd osc/
186
-
187
- if grep -qxFe '- Update to v${{ steps.info.outputs.tag }}' pympress.changes; then
188
- echo "Version already in changelog ; skipping request"
189
- else
190
- $osc vc -F ../changes
191
- sed -i "2s/Cimba Li <[email protected] >/[email protected] /" pympress.changes
192
- $osc ci -m "Release ${{ steps.info.outputs.tag }}"
192
+ $osc vc -m "$changes"
193
+ sed -i "2s/Cimba Li <[email protected] >/[email protected] /" pympress.changes
194
+ $osc ci -m "Release $tag"
193
195
194
- $osc sr --yes -m "Version ${{ steps.info.outputs.tag }}" 'X11:Utilities' pympress
195
- fi
196
+ $osc sr --yes -m "Version $tag" 'X11:Utilities' pympress
196
197
env :
197
198
OPENBUILDSERVICE_TOKEN_SECRET : ${{ secrets.OPENBUILDSERVICE_TOKEN_SECRET }}
199
+ tag : ${{ needs.pypi.outputs.tag }}
200
+ changes : ${{ needs.pypi.outputs.changes }}
201
+
202
+
203
+ copr :
204
+ name : Download source RPM from release and upload to COPR
205
+ needs : pypi
206
+ runs-on : ubuntu-latest
207
+
208
+ steps :
209
+ - name : Install dependencies
210
+ run : |
211
+ sudo apt-get update -q
212
+ sudo apt-get install -qy cpio rpm2cpio python3-m2crypto
213
+ python3 -m pip install --break-system-packages copr-cli
214
+
215
+ - name : Fetch info from COPR
216
+ id : info
217
+ run : |
218
+ trap 'rm -f ./copr-config' EXIT && echo "$COPR_TOKEN_CONFIG" > ./copr-config
219
+ copr-cli --config ./copr-config get-package --name=python3-pympress --output-format=json cimbali/pympress |
220
+ jq -r '"version=\(.latest_build.source_package.version | sub("-[0-9]*$"; ""))"' | tee -a $GITHUB_OUTPUT
221
+ env :
222
+ COPR_TOKEN_CONFIG : ${{ secrets.COPR_TOKEN_CONFIG }}
198
223
199
224
- name : Get SRPM URL from GitHub Release and download
200
225
env :
201
- tag : ${{ steps.info .outputs.tag }}
226
+ tag : ${{ needs.pypi .outputs.tag }}
202
227
run : |
203
228
url="https://github.com/Cimbali/pympress/releases/download/v${tag}/python3-pympress-${tag}-1.src.rpm"
204
229
curl -L "$url" -o "python3-pympress-${tag}-1.src.rpm"
205
230
206
231
- name : Upload to COPR
207
- continue-on-error : true
232
+ if : needs.pypi.outputs.tag != steps.info.outputs.version
208
233
run : |
209
234
trap 'rm -f ./copr-config' EXIT && echo "$COPR_TOKEN_CONFIG" > ./copr-config
210
- copr-cli --config ./copr-config build --nowait cimbali/pympress "python3-pympress-${{ steps.info.outputs. tag } }-1.src.rpm"
235
+ copr-cli --config ./copr-config build --nowait cimbali/pympress "python3-pympress-${tag}-1.src.rpm"
211
236
env :
237
+ tag : ${{ needs.pypi.outputs.tag }}
212
238
COPR_TOKEN_CONFIG : ${{ secrets.COPR_TOKEN_CONFIG }}
213
239
214
240
@@ -244,10 +270,17 @@ jobs:
244
270
env :
245
271
PASSWORD : ${{ secrets.PYMPRESS_ACTION_PAT }}
246
272
273
+ - name : Get info from repo
274
+ id : info
275
+ run : |
276
+ cd "`brew --repo homebrew/core`"
277
+ version=`sed -rn 's,^\s*url "[a-z]+://([a-z0-9_.-]+/)*pympress-(.*)\.tar\.gz"$,\2,p' Formula/p/pympress.rb`
278
+ echo version=$version | tee -a $GITHUB_OUTPUT
279
+
247
280
- name : Make a brew PR from pypi’s metadata
248
- if : ${{ needs.pypi.outputs.release == 'final' }}
281
+ if : needs.pypi.outputs.release == 'final' && ( steps.info.outputs.version != needs.pypi.outputs.tag )
249
282
run : |
250
283
brew bump-formula-pr --strict --no-browse --url="${{needs.pypi.outputs.url}}" --sha256="${{needs.pypi.outputs.sha256}}" pympress
251
284
env :
252
- HOMEBREW_GITHUB_API_TOKEN : ${{ secrets.GITHUB_HOMEBREW_TOKEN }}
285
+ HOMEBREW_GITHUB_API_TOKEN : ${{ secrets.PYMPRESS_ACTION_PAT }}
253
286
HUB_REMOTE : https://github.com/Cimbali/homebrew-core/
0 commit comments