Skip to content

Commit 538bb8e

Browse files
committed
Separate obs and copr workflows
The osc tool shipped in Ubuntu is obsolete (contains in May 2025 a bug fixed in Aug 2022) so avoid relying on it.
1 parent 7db008e commit 538bb8e

File tree

1 file changed

+123
-90
lines changed

1 file changed

+123
-90
lines changed

.github/workflows/publish_release.yml

+123-90
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ on:
1010
tag:
1111
description: 'Release tag for which to build'
1212
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'
2113

2214
jobs:
2315
pypi:
@@ -27,30 +19,58 @@ jobs:
2719
release: ${{ steps.name.outputs.release }}
2820
url: ${{ steps.info.outputs.url }}
2921
sha256: ${{ steps.info.outputs.sha256 }}
22+
changes: ${{ steps.changes.outputs.changes }}
3023

3124
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+
3237
- name: Define name
3338
id: name
3439
run: |
3540
ref=${{ github.ref }}
3641
[ "${ref::10}" = 'refs/tags/' ] && tag=${ref:10} || tag=${{ github.event.inputs.tag }}
3742
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
4044
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
4451
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
4953
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 }}
5161
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 }}
5474

5575
- name: Build catalogs and packages
5676
run: |
@@ -61,154 +81,160 @@ jobs:
6181
env:
6282
TWINE_USERNAME: __token__
6383
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 )
6585
run: |
6686
twine upload dist/*
6787
68-
- name: Get info from pypi
88+
- name: Check info from pypi
6989
id: info
7090
env:
7191
tag: ${{ steps.name.outputs.tag }}
7292
run: |
7393
# 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
7696
sleep 60 # be patient with pypi
7797
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
80100
81101
- name: Run a check on the generated file
82102
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
84104
echo '::warning:: Generated sdist file did not match pypi sha256sum'
85105
fi
86106
87107
88108
aur:
89109
name: Publish to AUR
110+
needs: pypi
90111
runs-on: ubuntu-latest
91112
steps:
92113
- 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
94115

95116
- name: Get info
96117
id: info
118+
env:
119+
tag: ${{ needs.pypi.outputs.tag }}
97120
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 "[()\"']"`
105124
else
106-
prev_pkrel=0
125+
release=0
107126
fi
108127
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
114129
115130
- name: Update info
116131
run: |
117132
while read param value; do
118133
sed -i -r "s,^(\\s*$param ?=[('\" ]*)[A-Za-z0-9\${\}:/._-]+([ '\")]*)$,\1$value\2," aur-repo/.SRCINFO aur-repo/PKGBUILD
119134
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 ))
124139
EOF
125140
141+
head -n999 aur-repo/.SRCINFO aur-repo/PKGBUILD
142+
126143
- 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
128145
run: |
129146
cd aur-repo
130147
git config user.name Cimbali
131148
git config user.email [email protected]
132149
echo -e "protocol=https\nhost=github.com\nusername=Cimbali\npassword=$PASSWORD" | git credential-store store
133150
134-
git commit -am "Update to v${{ steps.info.outputs.tag }}"
151+
git commit -am "Update to v${{ needs.pypi.outputs.tag }}"
135152
git push origin "main:main"
136153
137154
env:
138-
AUR_PRIVATE_KEY: ${{ secrets.PYMPRESS_ACTION_PAT }}
155+
PASSWORD: ${{ secrets.PYMPRESS_ACTION_PAT }}
139156

140157

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
143161
runs-on: ubuntu-latest
162+
container: opensuse/tumbleweed
144163

145164
steps:
146165
- 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
151167

152-
- name: Get info
168+
- name: Fetch info from OpenBuildService
153169
id: info
154170
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"
158173
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 ' '`
161176
162-
printf '%s\n' "tag=$tag" "url=$url" "sha256=$sha256" | tee -a $GITHUB_OUTPUT
177+
echo version=$version | tee -a $GITHUB_OUTPUT
163178
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
167182
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 }}
177184

178185
- name: Upload to OpenBuildService
179-
continue-on-error: true
186+
if: needs.pypi.outputs.tag != steps.info.outputs.version
180187
run: |
181188
trap 'rm -f ./osc-config' EXIT && echo "$OPENBUILDSERVICE_TOKEN_SECRET" > ./osc-config
182189
osc="osc --config $GITHUB_WORKSPACE/osc-config"
190+
cd osc
183191
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"
193195
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
196197
env:
197198
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 }}
198223

199224
- name: Get SRPM URL from GitHub Release and download
200225
env:
201-
tag: ${{ steps.info.outputs.tag }}
226+
tag: ${{ needs.pypi.outputs.tag }}
202227
run: |
203228
url="https://github.com/Cimbali/pympress/releases/download/v${tag}/python3-pympress-${tag}-1.src.rpm"
204229
curl -L "$url" -o "python3-pympress-${tag}-1.src.rpm"
205230
206231
- name: Upload to COPR
207-
continue-on-error: true
232+
if: needs.pypi.outputs.tag != steps.info.outputs.version
208233
run: |
209234
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"
211236
env:
237+
tag: ${{ needs.pypi.outputs.tag }}
212238
COPR_TOKEN_CONFIG: ${{ secrets.COPR_TOKEN_CONFIG }}
213239

214240

@@ -244,10 +270,17 @@ jobs:
244270
env:
245271
PASSWORD: ${{ secrets.PYMPRESS_ACTION_PAT }}
246272

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+
247280
- 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 )
249282
run: |
250283
brew bump-formula-pr --strict --no-browse --url="${{needs.pypi.outputs.url}}" --sha256="${{needs.pypi.outputs.sha256}}" pympress
251284
env:
252-
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_HOMEBREW_TOKEN }}
285+
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.PYMPRESS_ACTION_PAT }}
253286
HUB_REMOTE: https://github.com/Cimbali/homebrew-core/

0 commit comments

Comments
 (0)