Skip to content

Commit 7665b1d

Browse files
authored
Merge pull request #23 from auouymous/build-with-github-actions
Build with Github Actions.
2 parents bac5372 + 1e3e420 commit 7665b1d

20 files changed

+267
-2333
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: build and bundle
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build-and-bundle:
7+
name: build
8+
if: >-
9+
github.event_name == 'push' ||
10+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
11+
12+
runs-on: macos-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0 # fetch tags
17+
- run: ./bootstrap.sh
18+
- run: ./build.sh
19+
- run: ./bundle.sh
20+
- run: ./release.sh _build/pythonbase.app $(git describe --tags)
21+
- run: rm -Rf _build/pythonbase.app/ _build/run-*
22+
- uses: actions/upload-artifact@v3
23+
with:
24+
name: bundle
25+
path: /Users/runner/work/gpodder-osx-bundle/gpodder-osx-bundle/_build
26+
retention-days: 30

README.asciidoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is a collection of files required to build pythonbase.app:
66
native dependencies to run gPodder as a native GTK+ Quartz application for Mac OS X 10.9+,
77
with a working python interpreter and pip utility.
88

9-
The scripts are executed on circle.ci, with xcode 9.4.1.
9+
The scripts are executed on github.com, with xcode 13.2.1 on macos 11.6.8 (as of 27aug2022).
1010

1111
NOTE: In case you want just want to run gPodder from source you can ignore all
1212
this and use the released bundle as a development environment. Download the
@@ -58,9 +58,9 @@ Releasing on OS X
5858
. test latest pythonbase-xxx.zip on macOS
5959
. tags are now the year as 2 digits, month as 1 or 2 digits (no leading 0), day as 1 or 2 digits (no leading 0): `git tag -a -m "bla bla" YY.MM.DD`
6060
. `git push`
61-
. rerun the latest circleci master job (will pick the new tag)
62-
. `GITHUB_TOKEN=xxxx ./github_release.py --download --circle-build LATEST_CI_BUILD --previous-tag THE_PREVIOUS_RELEASE_TAG YY.MM.DD`
63-
where LATEST_CI_BUILD is the latest circleci master job number (eg. 123)
61+
. rerun the latest github action master job (will pick the new tag)
62+
. `GITHUB_TOKEN=xxxx ./github_release.py --download --github-workflow LATEST_GA_WORKFLOW --previous-tag THE_PREVIOUS_RELEASE_TAG YY.MM.DD`
63+
where LATEST_GA_WORKFLOW is the number in URL of the latest github action master job (eg. 1234567890)
6464
. repeat the command without `--download` to upload to github
6565
. edit and publish the release on github
6666
. now you can update the tag in `.circleci/config.yml` of the gPodder project.

bootstrap.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ mkdir -p "$HOME/.config"
1515
cp misc/jhbuildrc-custom "$HOME/.config/jhbuildrc-custom"
1616
git clone https://gitlab.gnome.org/GNOME/gtk-osx.git _gtk-osx
1717
# try latest commit (2022-02-18)
18-
(cd _gtk-osx && git checkout 1a8dd873)
18+
(cd _gtk-osx && git checkout 6be92a11)
1919
# fix boostrap failure: error message on pip download
2020
sed -i '' s,https://bootstrap.pypa.io/2.7/get-pip.py,https://bootstrap.pypa.io/pip/2.7/get-pip.py, _gtk-osx/gtk-osx-setup.sh
21-
yes | ./_gtk-osx/gtk-osx-setup.sh
21+
sed -i '' 's:curl -ks :curl -ksS :' _gtk-osx/gtk-osx-setup.sh
22+
./_gtk-osx/gtk-osx-setup.sh
2223
git clone https://gitlab.gnome.org/GNOME/gtk-mac-bundler.git _bundler
2324
(cd _bundler && make install bindir=$HOME/.new_local/bin)

github_release.py

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import sys
1010
import re
11+
import zipfile
1112

1213
from github3 import login
1314
import requests
@@ -37,24 +38,35 @@ def error_exit(msg, code=1):
3738
sys.exit(code)
3839

3940

40-
def download_circleci(circle_build):
41-
""" download build artifacts from circleCI and exit """
42-
print("I: downloading release artifacts")
43-
os.mkdir("_build")
44-
artifacts = requests.get("https://circleci.com/api/v1.1/project/github/gpodder/gpodder-osx-bundle/%s/artifacts" % circle_build).json()
45-
items = set([u["url"] for u in artifacts
46-
if re.match(".+/pythonbase-.+\.zip.*$", u["path"])
47-
or u["path"].endswith("/pythonbase.contents")])
48-
if len(items) == 0:
41+
def download_github(github_workflow):
42+
""" download workflow artifacts from github and exit """
43+
headers = {'Accept': 'application/vnd.github+json', 'Authorization': 'token %s' % github_token}
44+
45+
print("I: downloading release artifacts for workflow %d" % github_workflow)
46+
r = requests.get("https://api.github.com/repos/gpodder/gpodder-osx-bundle/actions/artifacts", headers=headers)
47+
if not r.ok:
48+
print('ERROR: API fetch failed %d %s' % (r.status_code, r.reason))
49+
sys.exit(1)
50+
artifacts = r.json()
51+
artifact = [(a['id'], a['archive_download_url']) for a in artifacts['artifacts'] if a['workflow_run']['id'] == github_workflow]
52+
if len(artifact) != 1:
4953
error_exit("Nothing found to download")
50-
print("D: downloading %s" % items)
51-
for url in items:
52-
print("I: downloading %s" % url)
53-
output = os.path.join("_build", url.split('/')[-1])
54-
with requests.get(url, stream=True) as r:
55-
with open(output, "wb") as f:
56-
for chunk in r.iter_content(chunk_size=1000000):
57-
f.write(chunk)
54+
id, url = artifact[0]
55+
print("I: found artifact %d" % id)
56+
57+
print("I: downloading %s" % url)
58+
os.mkdir("_build")
59+
with requests.get(url, stream=True, headers=headers) as r:
60+
if not r.ok:
61+
print('ERROR: artifact fetch failed %d %s' % (r.status_code, r.reason))
62+
sys.exit(1)
63+
with open('_build/bundle.zip', "wb") as f:
64+
for chunk in r.iter_content(chunk_size=1000000):
65+
f.write(chunk)
66+
print("I: unzipping _build/bundle.zip")
67+
with zipfile.ZipFile('_build/bundle.zip', 'r') as z:
68+
z.extractall('_build')
69+
os.remove('_build/bundle.zip')
5870
checksum()
5971
print("I: download success. Rerun without --download to upload")
6072
sys.exit(0)
@@ -114,7 +126,7 @@ def get_diff_previous_tag(tag, previous_tag):
114126
return "```\n%s\n```" % "".join(diff)
115127

116128

117-
def upload(repo, tag, previous_tag, circle_build):
129+
def upload(repo, tag, previous_tag, github_workflow):
118130
""" create github release (draft) and upload assets """
119131
print("I: creating release %s" % tag)
120132
try:
@@ -139,12 +151,12 @@ def upload(repo, tag, previous_tag, circle_build):
139151

140152
print("I: updating release description with diff")
141153
diff = get_diff_previous_tag(tag, previous_tag)
142-
if circle_build:
143-
build = ("\ncircleCI build [%i](https://circleci.com/gh/gpodder/gpodder-osx-bundle/%i)"
144-
% (circle_build, circle_build))
154+
if github_workflow:
155+
workflow = ("\ngithub workflow [%i](https://github.com/gpodder/gpodder-osx-bundle/actions/runs/%i)"
156+
% (github_workflow, github_workflow))
145157
else:
146-
build = ""
147-
if release.edit(body=diff + build):
158+
workflow = ""
159+
if release.edit(body=diff + workflow):
148160
print("I: updated release description with diff")
149161
else:
150162
error_exit("E: updating release description")
@@ -153,15 +165,15 @@ def upload(repo, tag, previous_tag, circle_build):
153165
if __name__ == "__main__":
154166
parser = argparse.ArgumentParser(description='upload gpodder-osx-bundle artifacts to a github release\n'
155167
'Example usage: \n'
156-
' GITHUB_TOKEN=xxx python github_release.py --download --circle-build 33 --previous-tag base-3.10.0_0 base-3.10.2_0\n'
157-
' GITHUB_TOKEN=xxx python github_release.py --circle-build 33 --previous-tag base-3.10.0_0 base-3.10.2_0\n',
168+
' GITHUB_TOKEN=xxx python github_release.py --download --github-workflow 1234567890 --previous-tag 22.7.27 22.7.28\n'
169+
' GITHUB_TOKEN=xxx python github_release.py --github-workflow 1234567890 --previous-tag 22.7.27 22.7.28\n',
158170
formatter_class=argparse.RawTextHelpFormatter)
159171
parser.add_argument('tag', type=str,
160172
help='gpodder-osx-bundle git tag to create a release from')
161173
parser.add_argument('--download', action='store_true',
162-
help='download artifacts from given circle.ci build number')
163-
parser.add_argument('--circle-build', type=int, required=False,
164-
help='circleCI build number')
174+
help='download artifacts from given github workflow')
175+
parser.add_argument('--github-workflow', type=int, required=False,
176+
help='github workflow number (in URL)')
165177
parser.add_argument('--previous-tag', type=str, required=False,
166178
help='previous github tag for contents comparison')
167179
parser.add_argument('--debug', '-d', action='store_true',
@@ -180,14 +192,14 @@ def upload(repo, tag, previous_tag, circle_build):
180192
repo = gh.repository('gpodder', 'gpodder-osx-bundle')
181193

182194
if args.download:
183-
if not args.circle_build:
184-
error_exit("E: --download requires --circle-build number")
195+
if not args.github_workflow:
196+
error_exit("E: --download requires --github-workflow number")
185197
if os.path.isdir("_build"):
186198
error_exit("E: _build directory exists", -1)
187-
download_circleci(args.circle_build)
199+
download_github(args.github_workflow)
188200
else:
189201
if not os.path.exists("_build"):
190-
error_exit("E: _build directory doesn't exist. Maybe you want to download circleci build artifacts (see Usage)", -1)
202+
error_exit("E: _build directory doesn't exist. Maybe you want to download github workflow artifacts (see Usage)", -1)
191203

192204
checksum()
193-
upload(repo, args.tag, args.previous_tag, args.circle_build)
205+
upload(repo, args.tag, args.previous_tag, args.github_workflow)

0 commit comments

Comments
 (0)