Skip to content

Commit 7b51086

Browse files
committed
Add release upload support
1 parent 1da7eb7 commit 7b51086

File tree

5 files changed

+88
-56
lines changed

5 files changed

+88
-56
lines changed

.github/workflows/build.yml

+12-24
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ jobs:
168168
- name: mpy-cross
169169
run: make -C mpy-cross -j2
170170
- name: build
171-
run: TRAVIS_BOARDS="${{ matrix.board }}" python3 -u build_release_files.py
171+
run: python3 -u build_release_files.py
172172
working-directory: tools
173+
env:
174+
BOARDS: ${{ matrix.board }}
173175
- uses: actions/[email protected]
174176
with:
175177
name: ${{ matrix.board }}
@@ -179,28 +181,14 @@ jobs:
179181
env:
180182
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
181183
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
182-
if: github.event_name == 'push'
183-
184-
website:
185-
runs-on: ubuntu-16.04
186-
needs: build-arm
187-
steps:
188-
- name: Set up Python 3.5
189-
uses: actions/setup-python@v1
190-
with:
191-
python-version: 3.5
192-
- name: Install deps
184+
if: github.event_name == 'push' || (github.event_name == 'release' && github.event.action == 'published')
185+
- name: Install upload deps
193186
run: |
194-
pip install requests sh click
195-
- name: Versions
196-
run: |
197-
gcc --version
198-
python3 --version
199-
- uses: actions/checkout@v1
200-
with:
201-
submodules: true
202-
- name: CircuitPython version
203-
run: git describe --dirty --always --tags
204-
- name: Website
205-
run: python3 build_board_info.py
187+
pip install uritemplate
188+
- name: Upload to Release
189+
run: python3 -u upload_release_files.py
206190
working-directory: tools
191+
env:
192+
UPLOAD_URL: ${{ github.event.release.upload_url }}
193+
ADABOT_GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
194+
if: github.event_name == 'release' && github.event.action == 'published'
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Update CircuitPython.org
2+
3+
on: release
4+
5+
jobs:
6+
website:
7+
runs-on: ubuntu-latest
8+
needs: build-arm
9+
steps:
10+
- name: Set up Python 3.5
11+
uses: actions/setup-python@v1
12+
with:
13+
python-version: 3.5
14+
- name: Install deps
15+
run: |
16+
pip install requests sh click
17+
- name: Versions
18+
run: |
19+
gcc --version
20+
python3 --version
21+
- uses: actions/checkout@v1
22+
with:
23+
submodules: true
24+
- name: CircuitPython version
25+
run: git describe --dirty --always --tags
26+
- name: Website
27+
run: python3 build_board_info.py
28+
working-directory: tools
29+
env:
30+
RELEASE_TAG: ${{ github.event.release.tag_name }}
31+
ADABOT_GITHUB_ACCESS_TOKEN: ${{ secrets.ADABOT_GITHUB_ACCESS_TOKEN }}
32+
if: github.event_name == 'release' && github.event.action == 'published'

tools/build_board_info.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,8 @@ def get_version_info():
8888
# No exact match
8989
pass
9090

91-
if "TRAVIS" in os.environ and os.environ["TRAVIS"] == "true":
92-
sha = os.environ["TRAVIS_COMMIT"]
93-
if os.environ["TRAVIS_PULL_REQUEST"] != "false":
94-
sha = os.environ["TRAVIS_PULL_REQUEST_SHA"]
91+
if "GITHUB_SHA" in os.environ:
92+
sha = os.environ["GITHUB_SHA"]
9593

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

211-
new_tag = os.environ["TRAVIS_TAG"]
209+
new_tag = os.environ["RELEASE_TAG"]
212210

213211
changes = {
214212
"new_release": new_tag,
@@ -280,7 +278,7 @@ def generate_download_info():
280278
print("No new release to update")
281279

282280
if __name__ == "__main__":
283-
if "TRAVIS_TAG" in os.environ and os.environ["TRAVIS_TAG"]:
281+
if "RELEASE_TAG" in os.environ and os.environ["RELEASE_TAG"]:
284282
generate_download_info()
285283
else:
286284
print("skipping website update because this isn't a tag")

tools/build_release_files.py

+8-26
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,14 @@
1010
for port in build_info.SUPPORTED_PORTS:
1111
result = subprocess.run("rm -rf ../ports/{port}/build*".format(port=port), shell=True)
1212

13-
ROSIE_SETUPS = ["rosie-ci"]
14-
rosie_ok = {}
15-
for rosie in ROSIE_SETUPS:
16-
rosie_ok[rosie] = True
17-
1813
PARALLEL = "-j 5"
19-
travis = False
20-
if "TRAVIS" in os.environ and os.environ["TRAVIS"] == "true":
14+
if "GITHUB_ACTION" in os.environ:
2115
PARALLEL="-j 2"
22-
travis = True
2316

2417
all_boards = build_info.get_board_mapping()
2518
build_boards = list(all_boards.keys())
26-
if "TRAVIS_BOARDS" in os.environ:
27-
build_boards = os.environ["TRAVIS_BOARDS"].split()
19+
if "BOARDS" in os.environ:
20+
build_boards = os.environ["BOARDS"].split()
2821

2922
sha, version = build_info.get_version_info()
3023

@@ -83,25 +76,14 @@
8376
if exit_status == 0:
8477
exit_status = 1
8578

86-
if travis:
87-
print('travis_fold:start:adafruit-bins-{}-{}\\r'.format(language, board))
8879
print("Build {board} for {language}{clean_build} took {build_duration:.2f}s and {success}".format(
8980
board=board, language=language, clean_build=(" (clean_build)" if clean_build else ""),
9081
build_duration=build_duration, success=success))
91-
if make_result.returncode != 0:
92-
print(make_result.stdout.decode("utf-8"))
93-
print(other_output)
94-
# Only upload to Rosie if its a pull request.
95-
if travis:
96-
for rosie in ROSIE_SETUPS:
97-
if not rosie_ok[rosie]:
98-
break
99-
print("Uploading to https://{rosie}.ngrok.io/upload/{sha}".format(rosie=rosie, sha=sha))
100-
#curl -F "file=@$final_filename" https://$rosie.ngrok.io/upload/$sha
101-
if travis:
102-
print('travis_fold:end:adafruit-bins-{}-{}\\r'.format(language, board))
103-
104-
# Flush so travis will see something before 10 minutes has passed.
82+
83+
print(make_result.stdout.decode("utf-8"))
84+
print(other_output)
85+
86+
# Flush so we will see something before 10 minutes has passed.
10587
print(flush=True)
10688

10789
sys.exit(exit_status)

tools/upload_release_files.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#! /usr/bin/env python3
2+
3+
import os
4+
import os.path
5+
import sys
6+
import uritemplate
7+
8+
sys.path.append("adabot")
9+
import adabot.github_requests as github
10+
11+
exit_status = 0
12+
13+
for dirpath, dirnames, filenames in os.walk("../bin"):
14+
if not filenames:
15+
continue
16+
for filename in filenames:
17+
full_filename = os.path.join(dirpath, filename)
18+
label = filename.replace("adafruit-circuitpython-", "")
19+
url_vars = {}
20+
url_vars["name"] = filename
21+
url_vars["label"] = label
22+
url = uritemplate.expand(os.environ["UPLOAD_URL"], url_vars)
23+
headers = {"content-type": "application/octet-stream"}
24+
print(url)
25+
with open(full_filename, "rb") as f:
26+
response = github.post(url, data=f, headers=headers)
27+
if not response.ok:
28+
print("Upload of {} failed with {}.".format(filename, response.status_code))
29+
print(response.text)
30+
sys.exit(response.status_code)
31+
32+
sys.exit(exit_status)

0 commit comments

Comments
 (0)