Skip to content

Commit 5173d26

Browse files
Use CI to build draft releases on a tag push (#177)
Ensure no stray files get sucked into the release ZIP by using a clean CI image to build the package and JSON file. Auto-populate the draft with the git commits since the last release.
1 parent ab02801 commit 5173d26

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Whenever a tag of the form #.xxxx is pushed against master, generate a
2+
# draft release and upload the ZIP and JSON file to it. Maintainers then
3+
# will manually add the changelist and publish it.
4+
5+
name: Arduino-Pico Draft Release
6+
7+
on:
8+
push:
9+
tags:
10+
# Run for tags of the x.x.x* form (i.e. 3.0.0, 3.0.0-beta, etc.).
11+
- '[0-9]+.[0-9]+.[0-9]+*'
12+
13+
jobs:
14+
package:
15+
name: Package
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
with:
20+
submodules: true
21+
- uses: actions/setup-python@v2
22+
with:
23+
python-version: '3.x'
24+
- name: Set GIT tag name
25+
run: |
26+
# Sets an environment variable used in the next steps
27+
echo "::set-env name=TRAVIS_TAG::$(git describe --exact-match --tags)"
28+
- name: Build package JSON
29+
env:
30+
TRAVIS_BUILD_DIR: ${{ github.workspace }}
31+
BUILD_TYPE: package
32+
CI_GITHUB_API_KEY: ${{ secrets.GITHUB_TOKEN }}
33+
run: |
34+
bash ./tests/ci/build_package.sh
35+
pip3 install PyGithub
36+
# Create a draft release and upload the ZIP and JSON files.
37+
# This draft is not visible to normal users and needs to be
38+
# updated manually with release notes and published from the
39+
# GitHub web interface.
40+
json=$(find ./package/versions -name package_rp2040_index.json)
41+
log=$(find ./package/versions -name package_rp2040_index.log)
42+
zip=$(find ./package/versions -name rp2040*zip)
43+
python3 ./package/upload_release.py --user "$GITHUB_ACTOR" --repo "$GITHUB_REPOSITORY" --token "$CI_GITHUB_API_KEY" --tag "$TRAVIS_TAG" --name "Release $TRAVIS_TAG" --msg "@$json" "$zip" "$json"

package/build_boards_manager_package.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ echo "Downloading base package: $base_ver"
174174
old_json=package_rp2040_index_stable.json
175175
curl -L -o $old_json "https://github.com/earlephilhower/arduino-pico/releases/download/${base_ver}/package_rp2040_index.json"
176176
new_json=package_rp2040_index.json
177+
new_log=package_rp2040_index.log
177178

178179
set +e
179180
# Merge the old and new
@@ -195,6 +196,8 @@ mv tmp $new_json
195196
set -e
196197
cat $new_json | jq empty
197198

199+
git log $base_ver..HEAD --oneline | sed 's/\b / * /' | cut -f2- -d" " > $new_log
200+
198201
popd
199202
popd
200203

package/upload_release.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
3+
#from github import Github
4+
import argparse
5+
6+
parser = argparse.ArgumentParser(description='Upload a set of files to a new draft release')
7+
parser.add_argument('--user', help="Github username", type=str, required=True)
8+
parser.add_argument('--token', help="Github Personal Access Token (PAT)", type=str, required=True)
9+
parser.add_argument('--repo', help="Repository", type=str, required=True)
10+
parser.add_argument('--tag', help="Release tag", type=str, required=True)
11+
parser.add_argument('--name', help="Release name", type=str, required=True)
12+
parser.add_argument('--msg', help="Release message", type=str, required=True)
13+
parser.add_argument('files', nargs=argparse.REMAINDER)
14+
args = parser.parse_args()
15+
16+
if len(args.files) == 0:
17+
print("ERROR: No files specified")
18+
quit()
19+
20+
if args.msg[0] == '@':
21+
with open(args.msg[1:], 'r') as f:
22+
args.msg = f.read()
23+
24+
gh = Github(login_or_token=args.token)
25+
repo = gh.get_repo(str(args.repo))
26+
release = repo.create_git_release(args.tag, args.name, args.msg, draft=True)
27+
for fn in args.files:
28+
print("Uploading file: " + fn)
29+
release.upload_asset(fn)

0 commit comments

Comments
 (0)