Skip to content

Commit b2ad3b5

Browse files
committed
Add release workflow
1 parent 1e75b69 commit b2ad3b5

File tree

3 files changed

+235
-1
lines changed

3 files changed

+235
-1
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Update the Arduino board package index with a new release version.
4+
"""
5+
import json
6+
import os
7+
import sys
8+
9+
10+
def main():
11+
version = os.environ.get('VERSION')
12+
archive_name = os.environ.get('ARCHIVE_NAME')
13+
checksum = os.environ.get('CHECKSUM')
14+
size = os.environ.get('SIZE')
15+
16+
if not all([version, archive_name, checksum, size]):
17+
print("Error: Missing required environment variables")
18+
print(f"VERSION={version}, ARCHIVE_NAME={archive_name}, CHECKSUM={checksum}, SIZE={size}")
19+
sys.exit(1)
20+
21+
# Load existing package index
22+
with open('package_n-able_boards_index.json', 'r') as f:
23+
package_data = json.load(f)
24+
25+
# New platform entry
26+
new_platform = {
27+
"name": "Arm (Nim)BLE Boards",
28+
"architecture": "arm-ble",
29+
"version": version,
30+
"category": "Contributed",
31+
"help": {
32+
"online": "https://github.com/h2zero/n-able-Arduino/issues"
33+
},
34+
"url": f"https://github.com/h2zero/n-able-Arduino/archive/{version}.tar.gz",
35+
"archiveFileName": archive_name,
36+
"checksum": f"SHA-256:{checksum}",
37+
"size": str(size),
38+
"boards": [
39+
{"name": "Adafruit CLUE nRF52840"},
40+
{"name": "Adafruit Circuit Playground Bluefruit"},
41+
{"name": "Adafruit Feather nRF52832"},
42+
{"name": "Adafruit Feather nRF52840 Express"},
43+
{"name": "Adafruit Feather nRF52840 Sense"},
44+
{"name": "Adafruit ItsyBitsy nRF52840 Express"},
45+
{"name": "BBC micro:bit"},
46+
{"name": "BBC micro:bit v2"},
47+
{"name": "Bluz DK"},
48+
{"name": "Calliope mini"},
49+
{"name": "Ebyte E104-BT5032A-TB"},
50+
{"name": "Ebyte E104-BT5040UA Dongle"},
51+
{"name": "Electronut labs bluey"},
52+
{"name": "Electronut labs hackaBLE"},
53+
{"name": "Electronut labs hackaBLE v2"},
54+
{"name": "Generic nRF51822"},
55+
{"name": "Generic nRF52810"},
56+
{"name": "Generic nRF52832"},
57+
{"name": "Generic nRF52833"},
58+
{"name": "Generic nRF52840"},
59+
{"name": "ng-beacon"},
60+
{"name": "nRF51 Dongle"},
61+
{"name": "nRF51822 DK"},
62+
{"name": "nRF52832 DK"},
63+
{"name": "nRF52833 DK"},
64+
{"name": "nRF52840 DK"},
65+
{"name": "nRF52840 Dongle"},
66+
{"name": "Nordic Beacon Kit"},
67+
{"name": "OSHChip"},
68+
{"name": "RedBear BLE Nano"},
69+
{"name": "RedBear BLE Nano 2"},
70+
{"name": "RedBear Blend 2"},
71+
{"name": "RedBear nRF51822"},
72+
{"name": "Sino:bit"},
73+
{"name": "TinyBLE"},
74+
{"name": "Waveshare BLE400"},
75+
{"name": "Seeed XIAO nRF52840 Sense"}
76+
],
77+
"toolsDependencies": [
78+
{
79+
"packager": "h2zero",
80+
"name": "gcc-arm-none-eabi",
81+
"version": "9.3.1-1"
82+
},
83+
{
84+
"packager": "h2zero",
85+
"name": "openocd",
86+
"version": "0.11.0-4"
87+
}
88+
]
89+
}
90+
91+
# Check if version already exists and update or append
92+
found = False
93+
for platform in package_data['packages'][0]['platforms']:
94+
if platform['version'] == version:
95+
# Update existing version
96+
platform.update(new_platform)
97+
found = True
98+
print(f"Updated existing package index entry for version {version}")
99+
break
100+
101+
if not found:
102+
# Append new version (maintaining reverse chronological order)
103+
package_data['packages'][0]['platforms'].insert(0, new_platform)
104+
print(f"Added new package index entry for version {version}")
105+
106+
# Write updated package index
107+
with open('package_n-able_boards_index.json', 'w') as f:
108+
json.dump(package_data, f, indent=2)
109+
110+
print(f"Successfully updated package index")
111+
112+
113+
if __name__ == '__main__':
114+
main()

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches:
66
-master
7-
pull_request:
7+
#pull_request:
88
workflow_dispatch:
99

1010
jobs:

.github/workflows/release.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- release-wf
7+
release:
8+
types: [published]
9+
workflow_dispatch:
10+
inputs:
11+
tag:
12+
description: 'Release tag (e.g., 0.3.0)'
13+
required: true
14+
15+
permissions:
16+
contents: write
17+
18+
jobs:
19+
release:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout source
24+
uses: actions/checkout@v4
25+
26+
- name: Set version
27+
id: version
28+
run: |
29+
if [ "${{ github.event_name }}" == "release" ]; then
30+
VERSION=${{ github.event.release.tag_name }}
31+
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
32+
VERSION=${{ github.event.inputs.tag }}
33+
else
34+
# For push events, use a test version
35+
VERSION="0.3.1-testt"
36+
fi
37+
# Remove 'v' prefix if present
38+
VERSION=${VERSION#v}
39+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
40+
41+
- name: Create source archive
42+
id: archive
43+
run: |
44+
VERSION=${{ steps.version.outputs.version }}
45+
ARCHIVE_NAME="n-able-Arduino-${VERSION}.tar.gz"
46+
echo "Creating archive: ${ARCHIVE_NAME}"
47+
48+
# Temporarily disable exit on error for tar (it may return 1 if files change during archiving)
49+
set +e
50+
tar --warning=no-file-changed -czf "${ARCHIVE_NAME}" \
51+
--exclude=.git \
52+
--exclude=.github \
53+
--exclude=.gitignore \
54+
--exclude=.gitattributes \
55+
--exclude=node_modules \
56+
--exclude=build \
57+
--exclude=dist \
58+
--exclude='*.tar.gz' \
59+
--transform="s,^,n-able-Arduino-${VERSION}/," \
60+
.
61+
TAR_EXIT=$?
62+
set -e
63+
64+
# Tar exit codes: 0 = success, 1 = some files changed during archiving (but archive created)
65+
if [ $TAR_EXIT -gt 1 ]; then
66+
echo "Tar failed with exit code $TAR_EXIT"
67+
ls -la
68+
exit 1
69+
fi
70+
71+
# Calculate checksum and size
72+
echo "Files in directory:"
73+
ls -lh "${ARCHIVE_NAME}"
74+
CHECKSUM=$(sha256sum "${ARCHIVE_NAME}" | cut -d ' ' -f 1)
75+
if [ -f "${ARCHIVE_NAME}" ]; then
76+
SIZE=$(stat -c%s "${ARCHIVE_NAME}")
77+
else
78+
echo "Archive not created!"
79+
exit 1
80+
fi
81+
82+
echo "archive_name=${ARCHIVE_NAME}" >> $GITHUB_OUTPUT
83+
echo "checksum=${CHECKSUM}" >> $GITHUB_OUTPUT
84+
echo "size=${SIZE}" >> $GITHUB_OUTPUT
85+
86+
- name: Upload archive artifact
87+
uses: actions/upload-artifact@v4
88+
with:
89+
name: n-able-Arduino-${{ steps.version.outputs.version }}
90+
path: n-able-Arduino-${{ steps.version.outputs.version }}.tar.gz
91+
retention-days: 7
92+
93+
- name: Checkout gh-pages
94+
uses: actions/checkout@v4
95+
with:
96+
ref: release-test
97+
path: gh-pages
98+
99+
- name: Update package index
100+
id: update-index
101+
env:
102+
VERSION: ${{ steps.version.outputs.version }}
103+
ARCHIVE_NAME: ${{ steps.archive.outputs.archive_name }}
104+
CHECKSUM: ${{ steps.archive.outputs.checksum }}
105+
SIZE: ${{ steps.archive.outputs.size }}
106+
run: |
107+
cd gh-pages
108+
python ../.github/scripts/update_package_index.py
109+
110+
- name: Commit and push to gh-pages
111+
working-directory: gh-pages
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
run: |
115+
git config user.name "github-actions"
116+
git config user.email "github-actions@github.com"
117+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git
118+
git add package_n-able_boards_index.json
119+
git commit -m "Update package index for v${{ steps.version.outputs.version }}" || echo "No changes to commit"
120+
git push origin release-test

0 commit comments

Comments
 (0)