Skip to content

Commit 58f0f27

Browse files
committed
Add release workflow
1 parent 1e75b69 commit 58f0f27

File tree

2 files changed

+202
-1
lines changed

2 files changed

+202
-1
lines changed

.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: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
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-test"
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+
tar --warning=no-file-changed -czf "${ARCHIVE_NAME}" \
48+
--exclude=.git \
49+
--exclude=.github \
50+
--exclude=.gitignore \
51+
--exclude=node_modules \
52+
--exclude=build \
53+
--exclude=dist \
54+
--transform="s,^,n-able-Arduino-${VERSION}/," \
55+
. || { echo "Tar failed with exit code $?"; ls -la; exit 1; }
56+
57+
# Calculate checksum and size
58+
echo "Files in directory:"
59+
ls -lh "${ARCHIVE_NAME}"
60+
CHECKSUM=$(sha256sum "${ARCHIVE_NAME}" | cut -d ' ' -f 1)
61+
if [ -f "${ARCHIVE_NAME}" ]; then
62+
SIZE=$(stat -c%s "${ARCHIVE_NAME}")
63+
else
64+
echo "Archive not created!"
65+
exit 1
66+
fi
67+
68+
echo "archive_name=${ARCHIVE_NAME}" >> $GITHUB_OUTPUT
69+
echo "checksum=${CHECKSUM}" >> $GITHUB_OUTPUT
70+
echo "size=${SIZE}" >> $GITHUB_OUTPUT
71+
72+
- name: Checkout gh-pages
73+
uses: actions/checkout@v4
74+
with:
75+
ref: release-test
76+
path: gh-pages
77+
78+
- name: Update package index
79+
id: update-index
80+
env:
81+
VERSION: ${{ steps.version.outputs.version }}
82+
ARCHIVE_NAME: ${{ steps.archive.outputs.archive_name }}
83+
CHECKSUM: ${{ steps.archive.outputs.checksum }}
84+
SIZE: ${{ steps.archive.outputs.size }}
85+
run: |
86+
cd gh-pages
87+
88+
# Create Python script to update package index
89+
cat > update_index.py << 'EOF'
90+
import json
91+
import os
92+
import sys
93+
94+
version = os.environ.get('VERSION')
95+
archive_name = os.environ.get('ARCHIVE_NAME')
96+
checksum = os.environ.get('CHECKSUM')
97+
size = int(os.environ.get('SIZE'))
98+
99+
# Load existing package index
100+
with open('package_n-able_boards_index.json', 'r') as f:
101+
package_data = json.load(f)
102+
103+
# New platform entry
104+
new_platform = {
105+
"name": "Arm (Nim)BLE Boards",
106+
"architecture": "arm-ble",
107+
"version": version,
108+
"category": "Contributed",
109+
"help": {
110+
"online": "https://github.com/h2zero/n-able-Arduino/issues"
111+
},
112+
"url": f"https://github.com/h2zero/n-able-Arduino/archive/{version}.tar.gz",
113+
"archiveFileName": archive_name,
114+
"checksum": f"SHA-256:{checksum}",
115+
"size": str(size),
116+
"boards": [
117+
{"name": "Adafruit CLUE nRF52840"},
118+
{"name": "Adafruit Circuit Playground Bluefruit"},
119+
{"name": "Adafruit Feather nRF52832"},
120+
{"name": "Adafruit Feather nRF52840 Express"},
121+
{"name": "Adafruit Feather nRF52840 Sense"},
122+
{"name": "Adafruit ItsyBitsy nRF52840 Express"},
123+
{"name": "BBC micro:bit"},
124+
{"name": "BBC micro:bit v2"},
125+
{"name": "Bluz DK"},
126+
{"name": "Calliope mini"},
127+
{"name": "Ebyte E104-BT5032A-TB"},
128+
{"name": "Ebyte E104-BT5040UA Dongle"},
129+
{"name": "Electronut labs bluey"},
130+
{"name": "Electronut labs hackaBLE"},
131+
{"name": "Electronut labs hackaBLE v2"},
132+
{"name": "Generic nRF51822"},
133+
{"name": "Generic nRF52810"},
134+
{"name": "Generic nRF52832"},
135+
{"name": "Generic nRF52833"},
136+
{"name": "Generic nRF52840"},
137+
{"name": "ng-beacon"},
138+
{"name": "nRF51 Dongle"},
139+
{"name": "nRF51822 DK"},
140+
{"name": "nRF52832 DK"},
141+
{"name": "nRF52833 DK"},
142+
{"name": "nRF52840 DK"},
143+
{"name": "nRF52840 Dongle"},
144+
{"name": "Nordic Beacon Kit"},
145+
{"name": "OSHChip"},
146+
{"name": "RedBear BLE Nano"},
147+
{"name": "RedBear BLE Nano 2"},
148+
{"name": "RedBear Blend 2"},
149+
{"name": "RedBear nRF51822"},
150+
{"name": "Sino:bit"},
151+
{"name": "TinyBLE"},
152+
{"name": "Waveshare BLE400"},
153+
{"name": "Seeed XIAO nRF52840 Sense"}
154+
],
155+
"toolsDependencies": [
156+
{
157+
"packager": "h2zero",
158+
"name": "gcc-arm-none-eabi",
159+
"version": "9.3.1-1"
160+
},
161+
{
162+
"packager": "h2zero",
163+
"name": "openocd",
164+
"version": "0.11.0-4"
165+
}
166+
]
167+
}
168+
169+
# Check if version already exists and update or append
170+
found = False
171+
for platform in package_data['packages'][0]['platforms']:
172+
if platform['version'] == version:
173+
# Update existing version
174+
platform.update(new_platform)
175+
found = True
176+
break
177+
178+
if not found:
179+
# Append new version (maintaining reverse chronological order)
180+
package_data['packages'][0]['platforms'].insert(0, new_platform)
181+
182+
# Write updated package index
183+
with open('package_n-able_boards_index.json', 'w') as f:
184+
json.dump(package_data, f, indent=2)
185+
186+
print(f"Updated package index for version {version}")
187+
EOF
188+
189+
python update_index.py
190+
191+
- name: Commit and push to gh-pages
192+
working-directory: gh-pages
193+
env:
194+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
195+
run: |
196+
git config user.name "github-actions"
197+
git config user.email "github-actions@github.com"
198+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git
199+
git add package_n-able_boards_index.json
200+
git commit -m "Update package index for v${{ steps.version.outputs.version }}" || echo "No changes to commit"
201+
git push origin release-test

0 commit comments

Comments
 (0)