Skip to content

Commit

Permalink
Merge pull request #23 from auouymous/build-with-github-actions
Browse files Browse the repository at this point in the history
Build with Github Actions.
  • Loading branch information
elelay authored Aug 27, 2022
2 parents bac5372 + 1e3e420 commit 7665b1d
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 2,333 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: build and bundle

on: [push, pull_request]

jobs:
build-and-bundle:
name: build
if: >-
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # fetch tags
- run: ./bootstrap.sh
- run: ./build.sh
- run: ./bundle.sh
- run: ./release.sh _build/pythonbase.app $(git describe --tags)
- run: rm -Rf _build/pythonbase.app/ _build/run-*
- uses: actions/upload-artifact@v3
with:
name: bundle
path: /Users/runner/work/gpodder-osx-bundle/gpodder-osx-bundle/_build
retention-days: 30
8 changes: 4 additions & 4 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a collection of files required to build pythonbase.app:
native dependencies to run gPodder as a native GTK+ Quartz application for Mac OS X 10.9+,
with a working python interpreter and pip utility.

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

NOTE: In case you want just want to run gPodder from source you can ignore all
this and use the released bundle as a development environment. Download the
Expand Down Expand Up @@ -58,9 +58,9 @@ Releasing on OS X
. test latest pythonbase-xxx.zip on macOS
. 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`
. `git push`
. rerun the latest circleci master job (will pick the new tag)
. `GITHUB_TOKEN=xxxx ./github_release.py --download --circle-build LATEST_CI_BUILD --previous-tag THE_PREVIOUS_RELEASE_TAG YY.MM.DD`
where LATEST_CI_BUILD is the latest circleci master job number (eg. 123)
. rerun the latest github action master job (will pick the new tag)
. `GITHUB_TOKEN=xxxx ./github_release.py --download --github-workflow LATEST_GA_WORKFLOW --previous-tag THE_PREVIOUS_RELEASE_TAG YY.MM.DD`
where LATEST_GA_WORKFLOW is the number in URL of the latest github action master job (eg. 1234567890)
. repeat the command without `--download` to upload to github
. edit and publish the release on github
. now you can update the tag in `.circleci/config.yml` of the gPodder project.
Expand Down
5 changes: 3 additions & 2 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ mkdir -p "$HOME/.config"
cp misc/jhbuildrc-custom "$HOME/.config/jhbuildrc-custom"
git clone https://gitlab.gnome.org/GNOME/gtk-osx.git _gtk-osx
# try latest commit (2022-02-18)
(cd _gtk-osx && git checkout 1a8dd873)
(cd _gtk-osx && git checkout 6be92a11)
# fix boostrap failure: error message on pip download
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
yes | ./_gtk-osx/gtk-osx-setup.sh
sed -i '' 's:curl -ks :curl -ksS :' _gtk-osx/gtk-osx-setup.sh
./_gtk-osx/gtk-osx-setup.sh
git clone https://gitlab.gnome.org/GNOME/gtk-mac-bundler.git _bundler
(cd _bundler && make install bindir=$HOME/.new_local/bin)
78 changes: 45 additions & 33 deletions github_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import sys
import re
import zipfile

from github3 import login
import requests
Expand Down Expand Up @@ -37,24 +38,35 @@ def error_exit(msg, code=1):
sys.exit(code)


def download_circleci(circle_build):
""" download build artifacts from circleCI and exit """
print("I: downloading release artifacts")
os.mkdir("_build")
artifacts = requests.get("https://circleci.com/api/v1.1/project/github/gpodder/gpodder-osx-bundle/%s/artifacts" % circle_build).json()
items = set([u["url"] for u in artifacts
if re.match(".+/pythonbase-.+\.zip.*$", u["path"])
or u["path"].endswith("/pythonbase.contents")])
if len(items) == 0:
def download_github(github_workflow):
""" download workflow artifacts from github and exit """
headers = {'Accept': 'application/vnd.github+json', 'Authorization': 'token %s' % github_token}

print("I: downloading release artifacts for workflow %d" % github_workflow)
r = requests.get("https://api.github.com/repos/gpodder/gpodder-osx-bundle/actions/artifacts", headers=headers)
if not r.ok:
print('ERROR: API fetch failed %d %s' % (r.status_code, r.reason))
sys.exit(1)
artifacts = r.json()
artifact = [(a['id'], a['archive_download_url']) for a in artifacts['artifacts'] if a['workflow_run']['id'] == github_workflow]
if len(artifact) != 1:
error_exit("Nothing found to download")
print("D: downloading %s" % items)
for url in items:
print("I: downloading %s" % url)
output = os.path.join("_build", url.split('/')[-1])
with requests.get(url, stream=True) as r:
with open(output, "wb") as f:
for chunk in r.iter_content(chunk_size=1000000):
f.write(chunk)
id, url = artifact[0]
print("I: found artifact %d" % id)

print("I: downloading %s" % url)
os.mkdir("_build")
with requests.get(url, stream=True, headers=headers) as r:
if not r.ok:
print('ERROR: artifact fetch failed %d %s' % (r.status_code, r.reason))
sys.exit(1)
with open('_build/bundle.zip', "wb") as f:
for chunk in r.iter_content(chunk_size=1000000):
f.write(chunk)
print("I: unzipping _build/bundle.zip")
with zipfile.ZipFile('_build/bundle.zip', 'r') as z:
z.extractall('_build')
os.remove('_build/bundle.zip')
checksum()
print("I: download success. Rerun without --download to upload")
sys.exit(0)
Expand Down Expand Up @@ -114,7 +126,7 @@ def get_diff_previous_tag(tag, previous_tag):
return "```\n%s\n```" % "".join(diff)


def upload(repo, tag, previous_tag, circle_build):
def upload(repo, tag, previous_tag, github_workflow):
""" create github release (draft) and upload assets """
print("I: creating release %s" % tag)
try:
Expand All @@ -139,12 +151,12 @@ def upload(repo, tag, previous_tag, circle_build):

print("I: updating release description with diff")
diff = get_diff_previous_tag(tag, previous_tag)
if circle_build:
build = ("\ncircleCI build [%i](https://circleci.com/gh/gpodder/gpodder-osx-bundle/%i)"
% (circle_build, circle_build))
if github_workflow:
workflow = ("\ngithub workflow [%i](https://github.com/gpodder/gpodder-osx-bundle/actions/runs/%i)"
% (github_workflow, github_workflow))
else:
build = ""
if release.edit(body=diff + build):
workflow = ""
if release.edit(body=diff + workflow):
print("I: updated release description with diff")
else:
error_exit("E: updating release description")
Expand All @@ -153,15 +165,15 @@ def upload(repo, tag, previous_tag, circle_build):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='upload gpodder-osx-bundle artifacts to a github release\n'
'Example usage: \n'
' GITHUB_TOKEN=xxx python github_release.py --download --circle-build 33 --previous-tag base-3.10.0_0 base-3.10.2_0\n'
' GITHUB_TOKEN=xxx python github_release.py --circle-build 33 --previous-tag base-3.10.0_0 base-3.10.2_0\n',
' GITHUB_TOKEN=xxx python github_release.py --download --github-workflow 1234567890 --previous-tag 22.7.27 22.7.28\n'
' GITHUB_TOKEN=xxx python github_release.py --github-workflow 1234567890 --previous-tag 22.7.27 22.7.28\n',
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('tag', type=str,
help='gpodder-osx-bundle git tag to create a release from')
parser.add_argument('--download', action='store_true',
help='download artifacts from given circle.ci build number')
parser.add_argument('--circle-build', type=int, required=False,
help='circleCI build number')
help='download artifacts from given github workflow')
parser.add_argument('--github-workflow', type=int, required=False,
help='github workflow number (in URL)')
parser.add_argument('--previous-tag', type=str, required=False,
help='previous github tag for contents comparison')
parser.add_argument('--debug', '-d', action='store_true',
Expand All @@ -180,14 +192,14 @@ def upload(repo, tag, previous_tag, circle_build):
repo = gh.repository('gpodder', 'gpodder-osx-bundle')

if args.download:
if not args.circle_build:
error_exit("E: --download requires --circle-build number")
if not args.github_workflow:
error_exit("E: --download requires --github-workflow number")
if os.path.isdir("_build"):
error_exit("E: _build directory exists", -1)
download_circleci(args.circle_build)
download_github(args.github_workflow)
else:
if not os.path.exists("_build"):
error_exit("E: _build directory doesn't exist. Maybe you want to download circleci build artifacts (see Usage)", -1)
error_exit("E: _build directory doesn't exist. Maybe you want to download github workflow artifacts (see Usage)", -1)

checksum()
upload(repo, args.tag, args.previous_tag, args.circle_build)
upload(repo, args.tag, args.previous_tag, args.github_workflow)
Loading

0 comments on commit 7665b1d

Please sign in to comment.