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
2214jobs :
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,159 +81,165 @@ 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 :
92- - name : Clone repo
93- run : git clone https://github.com/Cimbali/pympress-pkgbuild aur-repo
94-
95- - name : Get info
96- id : info
97- 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 "[()\"']"`
105- else
106- prev_pkrel=0
107- fi
108-
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
114-
115- - name : Update info
116- run : |
117- while read param value; do
118- sed -i -r "s,^(\\s*$param ?=[('\" ]*)[A-Za-z0-9\${\}:/._-]+([ '\")]*)$,\1$value\2," aur-repo/.SRCINFO aur-repo/PKGBUILD
119- 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 ))
124- EOF
125-
126- - name : Push the changes
127- if : ${{ steps.info.outputs.prev_pkgver }} != ${{ steps.info.outputs.tag }}
128- run : |
129- cd aur-repo
130- git config user.name Cimbali
131- git config user.email [email protected] 132- echo -e "protocol=https\nhost=github.com\nusername=Cimbali\npassword=$PASSWORD" | git credential-store store
133-
134- git commit -am "Update to v${{ steps.info.outputs.tag }}"
135- git push origin "main:main"
136-
137- env :
138- AUR_PRIVATE_KEY : ${{ secrets.PYMPRESS_ACTION_PAT }}
113+ - name : Clone repo
114+ run :
git clone https://[email protected] /Cimbali/pympress-pkgbuild aur-repo 115+
116+ - name : Get info
117+ id : info
118+ env :
119+ tag : ${{ needs.pypi.outputs.tag }}
120+ run : |
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 "[()\"']"`
124+ else
125+ release=0
126+ fi
139127
128+ printf '%s\n' "version=$version" "release=$release" | tee -a $GITHUB_OUTPUT
140129
141- copr :
142- name : Download source RPM from release and upload to COPR and OpenBuildService
130+ - name : Update info
131+ run : |
132+ while read param value; do
133+ sed -i -r "s,^(\\s*$param ?=[('\" ]*)[A-Za-z0-9\${\}:/._-]+([ '\")]*)$,\1$value\2," aur-repo/.SRCINFO aur-repo/PKGBUILD
134+ done <<EOF
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 ))
139+ EOF
140+
141+ head -n999 aur-repo/.SRCINFO aur-repo/PKGBUILD
142+
143+ - name : Push the changes
144+ if : steps.info.outputs.version != needs.pypi.outputs.tag
145+ run : |
146+ cd aur-repo
147+ git config user.name Cimbali
148+ git config user.email [email protected] 149+ echo -e "protocol=https\nhost=github.com\nusername=Cimbali\npassword=$PASSWORD" | git credential-store store
150+
151+ git commit -am "Update to v${{ needs.pypi.outputs.tag }}"
152+ git push origin "main:main"
153+
154+ env :
155+ PASSWORD : ${{ secrets.PYMPRESS_ACTION_PAT }}
156+
157+
158+ obs :
159+ name : 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 : 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
215241 brew :
216- name : Request new pypi package be pulled into Homebrew
242+ name : Request Homebrew pull new version
217243 needs : pypi
218244 runs-on : macos-latest
219245
@@ -223,7 +249,7 @@ jobs:
223249 run : |
224250 brew update
225251 brew upgrade
226- brew install pipgrip
252+ brew install pipgrip gnu-sed
227253
228254 - name : Configure brew repo
229255 run : |
@@ -244,10 +270,32 @@ 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+
278+ version=`gsed -rn 's,^\s*url "[a-z]+://([a-z0-9_.-]+/)*pympress-(.*)\.tar\.gz"$,\2,p' Formula/p/pympress.rb`
279+ echo version=$version | tee -a $GITHUB_OUTPUT
280+
281+ curl -sL -u "Cimbali:$GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" -H "Accept: application/vnd.github+json" -o - \
282+ 'https://api.github.com/repos/Homebrew/homebrew-core/pulls?state=open&per_page=100' > pulls.json
283+ jq -r '.[] | [.number, .title] | join(",")' > pulls.csv
284+
285+ pr=`jq -r "map(select(.title == \"pympress $tag\")) | first.number? " pulls.json`
286+ echo pr=$pr | tee -a $GITHUB_OUTPUT
287+
288+ if [ "$pr" != "null" ]; then
289+ echo "::warning:: Pull request already open at https://github.com/Homebrew/homebrew-core/pull/$pr"
290+ fi
291+
292+ env :
293+ tag : ${{ needs.pypi.outputs.tag }}
294+
247295 - name : Make a brew PR from pypi’s metadata
248- if : ${{ needs.pypi.outputs.release == 'final' }}
296+ if : needs.pypi.outputs.release == 'final' && ( steps.info.outputs.version != needs.pypi.outputs.tag ) && ! steps.info.outputs.pr
249297 run : |
250298 brew bump-formula-pr --strict --no-browse --url="${{needs.pypi.outputs.url}}" --sha256="${{needs.pypi.outputs.sha256}}" pympress
251299 env :
252- HOMEBREW_GITHUB_API_TOKEN : ${{ secrets.GITHUB_HOMEBREW_TOKEN }}
300+ HOMEBREW_GITHUB_API_TOKEN : ${{ secrets.PYMPRESS_ACTION_PAT }}
253301 HUB_REMOTE : https://github.com/Cimbali/homebrew-core/
0 commit comments