Skip to content

Commit b487f12

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

File tree

2 files changed

+223
-1
lines changed

2 files changed

+223
-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: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
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+
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+
109+
# Create Python script to update package index
110+
cat > update_index.py << 'EOF'
111+
import json
112+
import os
113+
import sys
114+
115+
version = os.environ.get('VERSION')
116+
archive_name = os.environ.get('ARCHIVE_NAME')
117+
checksum = os.environ.get('CHECKSUM')
118+
size = int(os.environ.get('SIZE'))
119+
120+
# Load existing package index
121+
with open('package_n-able_boards_index.json', 'r') as f:
122+
package_data = json.load(f)
123+
124+
# New platform entry
125+
new_platform = {
126+
"name": "Arm (Nim)BLE Boards",
127+
"architecture": "arm-ble",
128+
"version": version,
129+
"category": "Contributed",
130+
"help": {
131+
"online": "https://github.com/h2zero/n-able-Arduino/issues"
132+
},
133+
"url": f"https://github.com/h2zero/n-able-Arduino/archive/{version}.tar.gz",
134+
"archiveFileName": archive_name,
135+
"checksum": f"SHA-256:{checksum}",
136+
"size": str(size),
137+
"boards": [
138+
{"name": "Adafruit CLUE nRF52840"},
139+
{"name": "Adafruit Circuit Playground Bluefruit"},
140+
{"name": "Adafruit Feather nRF52832"},
141+
{"name": "Adafruit Feather nRF52840 Express"},
142+
{"name": "Adafruit Feather nRF52840 Sense"},
143+
{"name": "Adafruit ItsyBitsy nRF52840 Express"},
144+
{"name": "BBC micro:bit"},
145+
{"name": "BBC micro:bit v2"},
146+
{"name": "Bluz DK"},
147+
{"name": "Calliope mini"},
148+
{"name": "Ebyte E104-BT5032A-TB"},
149+
{"name": "Ebyte E104-BT5040UA Dongle"},
150+
{"name": "Electronut labs bluey"},
151+
{"name": "Electronut labs hackaBLE"},
152+
{"name": "Electronut labs hackaBLE v2"},
153+
{"name": "Generic nRF51822"},
154+
{"name": "Generic nRF52810"},
155+
{"name": "Generic nRF52832"},
156+
{"name": "Generic nRF52833"},
157+
{"name": "Generic nRF52840"},
158+
{"name": "ng-beacon"},
159+
{"name": "nRF51 Dongle"},
160+
{"name": "nRF51822 DK"},
161+
{"name": "nRF52832 DK"},
162+
{"name": "nRF52833 DK"},
163+
{"name": "nRF52840 DK"},
164+
{"name": "nRF52840 Dongle"},
165+
{"name": "Nordic Beacon Kit"},
166+
{"name": "OSHChip"},
167+
{"name": "RedBear BLE Nano"},
168+
{"name": "RedBear BLE Nano 2"},
169+
{"name": "RedBear Blend 2"},
170+
{"name": "RedBear nRF51822"},
171+
{"name": "Sino:bit"},
172+
{"name": "TinyBLE"},
173+
{"name": "Waveshare BLE400"},
174+
{"name": "Seeed XIAO nRF52840 Sense"}
175+
],
176+
"toolsDependencies": [
177+
{
178+
"packager": "h2zero",
179+
"name": "gcc-arm-none-eabi",
180+
"version": "9.3.1-1"
181+
},
182+
{
183+
"packager": "h2zero",
184+
"name": "openocd",
185+
"version": "0.11.0-4"
186+
}
187+
]
188+
}
189+
190+
# Check if version already exists and update or append
191+
found = False
192+
for platform in package_data['packages'][0]['platforms']:
193+
if platform['version'] == version:
194+
# Update existing version
195+
platform.update(new_platform)
196+
found = True
197+
break
198+
199+
if not found:
200+
# Append new version (maintaining reverse chronological order)
201+
package_data['packages'][0]['platforms'].insert(0, new_platform)
202+
203+
# Write updated package index
204+
with open('package_n-able_boards_index.json', 'w') as f:
205+
json.dump(package_data, f, indent=2)
206+
207+
print(f"Updated package index for version {version}")
208+
EOF
209+
210+
python update_index.py
211+
212+
- name: Commit and push to gh-pages
213+
working-directory: gh-pages
214+
env:
215+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
216+
run: |
217+
git config user.name "github-actions"
218+
git config user.email "github-actions@github.com"
219+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git
220+
git add package_n-able_boards_index.json
221+
git commit -m "Update package index for v${{ steps.version.outputs.version }}" || echo "No changes to commit"
222+
git push origin release-test

0 commit comments

Comments
 (0)