Skip to content

Commit 9c95c4d

Browse files
CI to update JSON when releases are published (#178)
1 parent 7e0eefe commit 9c95c4d

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Arduino-Pico Release Publisher
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
package:
9+
name: Update master JSON file
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
submodules: true
15+
- uses: actions/setup-python@v2
16+
with:
17+
python-version: '3.x'
18+
- name: Deploy updated JSON
19+
env:
20+
TRAVIS_BUILD_DIR: ${{ github.workspace }}
21+
BUILD_TYPE: package
22+
CI_GITHUB_API_KEY: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
TAG=$(git describe --exact-match --tags)
25+
curl -L -o ./package_rp2040_index.json "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/$TAG/package_rp2040_index.json"
26+
./package/update_release.py --token ${CI_GITHUB_API_KEY} --repo "$GITHUB_REPOSITORY" --tag global ./package_rp2040_index.json

.github/workflows/tag-to-draft-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ jobs:
3838
log=$(find ./package/versions -name package_rp2040_index.log)
3939
zip=$(find ./package/versions -name rp2040*zip)
4040
tag=$(find ./package/versions -name package_rp2040_index.tag -exec cat \{\} \;)
41-
python3 ./package/upload_release.py --user "$GITHUB_ACTOR" --repo "$GITHUB_REPOSITORY" --token "$CI_GITHUB_API_KEY" --tag "$tag" --name "Release $tag" --msg "@$log" "$zip" "$json"
41+
python3 ./package/upload_release.py --repo "$GITHUB_REPOSITORY" --token "$CI_GITHUB_API_KEY" --tag "$tag" --name "Release $tag" --msg "@$log" "$zip" "$json"

package/update_release.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
from github import Github
4+
import argparse
5+
6+
parser = argparse.ArgumentParser(description='Refresh a set of files in an existing release')
7+
parser.add_argument('--token', help="Github Personal Access Token (PAT)", type=str, required=True)
8+
parser.add_argument('--repo', help="Repository", type=str, required=True)
9+
parser.add_argument('--tag', help="Release tag", type=str, required=True)
10+
parser.add_argument('files', nargs=argparse.REMAINDER)
11+
args = parser.parse_args()
12+
13+
if len(args.files) == 0:
14+
print("ERROR: No files specified")
15+
quit()
16+
17+
gh = Github(login_or_token=args.token)
18+
repo = gh.get_repo(str(args.repo))
19+
for fn in args.files:
20+
release = repo.get_release(args.tag)
21+
for asset in release.get_assets():
22+
if asset.name == fn:
23+
print("Found '" + fn + "', updating")
24+
asset.delete_asset()
25+
release.upload_asset(fn)

package/upload_release.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
from github import Github
44
import argparse
5-
import re
65

76
parser = argparse.ArgumentParser(description='Upload a set of files to a new draft release')
8-
parser.add_argument('--user', help="Github username", type=str, required=True)
97
parser.add_argument('--token', help="Github Personal Access Token (PAT)", type=str, required=True)
108
parser.add_argument('--repo', help="Repository", type=str, required=True)
119
parser.add_argument('--tag', help="Release tag", type=str, required=True)

0 commit comments

Comments
 (0)