Skip to content

Commit

Permalink
Add release upload support
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed Aug 27, 2019
1 parent 1da7eb7 commit 7b51086
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 56 deletions.
36 changes: 12 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ jobs:
- name: mpy-cross
run: make -C mpy-cross -j2
- name: build
run: TRAVIS_BOARDS="${{ matrix.board }}" python3 -u build_release_files.py
run: python3 -u build_release_files.py
working-directory: tools
env:
BOARDS: ${{ matrix.board }}
- uses: actions/upload-artifact@v1.0.0
with:
name: ${{ matrix.board }}
Expand All @@ -179,28 +181,14 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
if: github.event_name == 'push'

website:
runs-on: ubuntu-16.04
needs: build-arm
steps:
- name: Set up Python 3.5
uses: actions/setup-python@v1
with:
python-version: 3.5
- name: Install deps
if: github.event_name == 'push' || (github.event_name == 'release' && github.event.action == 'published')
- name: Install upload deps
run: |
pip install requests sh click
- name: Versions
run: |
gcc --version
python3 --version
- uses: actions/checkout@v1
with:
submodules: true
- name: CircuitPython version
run: git describe --dirty --always --tags
- name: Website
run: python3 build_board_info.py
pip install uritemplate
- name: Upload to Release
run: python3 -u upload_release_files.py
working-directory: tools
env:
UPLOAD_URL: ${{ github.event.release.upload_url }}
ADABOT_GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name == 'release' && github.event.action == 'published'
32 changes: 32 additions & 0 deletions .github/workflows/create_website_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Update CircuitPython.org

on: release

jobs:
website:
runs-on: ubuntu-latest
needs: build-arm
steps:
- name: Set up Python 3.5
uses: actions/setup-python@v1
with:
python-version: 3.5
- name: Install deps
run: |
pip install requests sh click
- name: Versions
run: |
gcc --version
python3 --version
- uses: actions/checkout@v1
with:
submodules: true
- name: CircuitPython version
run: git describe --dirty --always --tags
- name: Website
run: python3 build_board_info.py
working-directory: tools
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
ADABOT_GITHUB_ACCESS_TOKEN: ${{ secrets.ADABOT_GITHUB_ACCESS_TOKEN }}
if: github.event_name == 'release' && github.event.action == 'published'
10 changes: 4 additions & 6 deletions tools/build_board_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ def get_version_info():
# No exact match
pass

if "TRAVIS" in os.environ and os.environ["TRAVIS"] == "true":
sha = os.environ["TRAVIS_COMMIT"]
if os.environ["TRAVIS_PULL_REQUEST"] != "false":
sha = os.environ["TRAVIS_PULL_REQUEST_SHA"]
if "GITHUB_SHA" in os.environ:
sha = os.environ["GITHUB_SHA"]

if not version:
version="{}-{}".format(date.today().strftime("%Y%m%d"), sha[:7])
Expand Down Expand Up @@ -208,7 +206,7 @@ def generate_download_info():
boards = {}
errors = []

new_tag = os.environ["TRAVIS_TAG"]
new_tag = os.environ["RELEASE_TAG"]

changes = {
"new_release": new_tag,
Expand Down Expand Up @@ -280,7 +278,7 @@ def generate_download_info():
print("No new release to update")

if __name__ == "__main__":
if "TRAVIS_TAG" in os.environ and os.environ["TRAVIS_TAG"]:
if "RELEASE_TAG" in os.environ and os.environ["RELEASE_TAG"]:
generate_download_info()
else:
print("skipping website update because this isn't a tag")
34 changes: 8 additions & 26 deletions tools/build_release_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@
for port in build_info.SUPPORTED_PORTS:
result = subprocess.run("rm -rf ../ports/{port}/build*".format(port=port), shell=True)

ROSIE_SETUPS = ["rosie-ci"]
rosie_ok = {}
for rosie in ROSIE_SETUPS:
rosie_ok[rosie] = True

PARALLEL = "-j 5"
travis = False
if "TRAVIS" in os.environ and os.environ["TRAVIS"] == "true":
if "GITHUB_ACTION" in os.environ:
PARALLEL="-j 2"
travis = True

all_boards = build_info.get_board_mapping()
build_boards = list(all_boards.keys())
if "TRAVIS_BOARDS" in os.environ:
build_boards = os.environ["TRAVIS_BOARDS"].split()
if "BOARDS" in os.environ:
build_boards = os.environ["BOARDS"].split()

sha, version = build_info.get_version_info()

Expand Down Expand Up @@ -83,25 +76,14 @@
if exit_status == 0:
exit_status = 1

if travis:
print('travis_fold:start:adafruit-bins-{}-{}\\r'.format(language, board))
print("Build {board} for {language}{clean_build} took {build_duration:.2f}s and {success}".format(
board=board, language=language, clean_build=(" (clean_build)" if clean_build else ""),
build_duration=build_duration, success=success))
if make_result.returncode != 0:
print(make_result.stdout.decode("utf-8"))
print(other_output)
# Only upload to Rosie if its a pull request.
if travis:
for rosie in ROSIE_SETUPS:
if not rosie_ok[rosie]:
break
print("Uploading to https://{rosie}.ngrok.io/upload/{sha}".format(rosie=rosie, sha=sha))
#curl -F "file=@$final_filename" https://$rosie.ngrok.io/upload/$sha
if travis:
print('travis_fold:end:adafruit-bins-{}-{}\\r'.format(language, board))

# Flush so travis will see something before 10 minutes has passed.

print(make_result.stdout.decode("utf-8"))
print(other_output)

# Flush so we will see something before 10 minutes has passed.
print(flush=True)

sys.exit(exit_status)
32 changes: 32 additions & 0 deletions tools/upload_release_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /usr/bin/env python3

import os
import os.path
import sys
import uritemplate

sys.path.append("adabot")
import adabot.github_requests as github

exit_status = 0

for dirpath, dirnames, filenames in os.walk("../bin"):
if not filenames:
continue
for filename in filenames:
full_filename = os.path.join(dirpath, filename)
label = filename.replace("adafruit-circuitpython-", "")
url_vars = {}
url_vars["name"] = filename
url_vars["label"] = label
url = uritemplate.expand(os.environ["UPLOAD_URL"], url_vars)
headers = {"content-type": "application/octet-stream"}
print(url)
with open(full_filename, "rb") as f:
response = github.post(url, data=f, headers=headers)
if not response.ok:
print("Upload of {} failed with {}.".format(filename, response.status_code))
print(response.text)
sys.exit(response.status_code)

sys.exit(exit_status)

0 comments on commit 7b51086

Please sign in to comment.