Add release workflow #8
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| branches: | |
| - release-wf | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Release tag (e.g., 0.3.0)' | |
| required: true | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| - name: Set version | |
| id: version | |
| run: | | |
| if [ "${{ github.event_name }}" == "release" ]; then | |
| VERSION=${{ github.event.release.tag_name }} | |
| elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| VERSION=${{ github.event.inputs.tag }} | |
| else | |
| # For push events, use a test version | |
| VERSION="0.3.1-test" | |
| fi | |
| # Remove 'v' prefix if present | |
| VERSION=${VERSION#v} | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| - name: Create source archive | |
| id: archive | |
| run: | | |
| VERSION=${{ steps.version.outputs.version }} | |
| ARCHIVE_NAME="n-able-Arduino-${VERSION}.tar.gz" | |
| echo "Creating archive: ${ARCHIVE_NAME}" | |
| # Temporarily disable exit on error for tar (it may return 1 if files change during archiving) | |
| set +e | |
| tar --warning=no-file-changed -czf "${ARCHIVE_NAME}" \ | |
| --exclude=.git \ | |
| --exclude=.github \ | |
| --exclude=.gitignore \ | |
| --exclude=node_modules \ | |
| --exclude=build \ | |
| --exclude=dist \ | |
| --transform="s,^,n-able-Arduino-${VERSION}/," \ | |
| . | |
| TAR_EXIT=$? | |
| set -e | |
| # Tar exit codes: 0 = success, 1 = some files changed during archiving (but archive created) | |
| if [ $TAR_EXIT -gt 1 ]; then | |
| echo "Tar failed with exit code $TAR_EXIT" | |
| ls -la | |
| exit 1 | |
| fi | |
| # Calculate checksum and size | |
| echo "Files in directory:" | |
| ls -lh "${ARCHIVE_NAME}" | |
| CHECKSUM=$(sha256sum "${ARCHIVE_NAME}" | cut -d ' ' -f 1) | |
| if [ -f "${ARCHIVE_NAME}" ]; then | |
| SIZE=$(stat -c%s "${ARCHIVE_NAME}") | |
| else | |
| echo "Archive not created!" | |
| exit 1 | |
| fi | |
| echo "archive_name=${ARCHIVE_NAME}" >> $GITHUB_OUTPUT | |
| echo "checksum=${CHECKSUM}" >> $GITHUB_OUTPUT | |
| echo "size=${SIZE}" >> $GITHUB_OUTPUT | |
| - name: Checkout gh-pages | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: release-test | |
| path: gh-pages | |
| - name: Update package index | |
| id: update-index | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| ARCHIVE_NAME: ${{ steps.archive.outputs.archive_name }} | |
| CHECKSUM: ${{ steps.archive.outputs.checksum }} | |
| SIZE: ${{ steps.archive.outputs.size }} | |
| run: | | |
| cd gh-pages | |
| # Create Python script to update package index | |
| cat > update_index.py << 'EOF' | |
| import json | |
| import os | |
| import sys | |
| version = os.environ.get('VERSION') | |
| archive_name = os.environ.get('ARCHIVE_NAME') | |
| checksum = os.environ.get('CHECKSUM') | |
| size = int(os.environ.get('SIZE')) | |
| # Load existing package index | |
| with open('package_n-able_boards_index.json', 'r') as f: | |
| package_data = json.load(f) | |
| # New platform entry | |
| new_platform = { | |
| "name": "Arm (Nim)BLE Boards", | |
| "architecture": "arm-ble", | |
| "version": version, | |
| "category": "Contributed", | |
| "help": { | |
| "online": "https://github.com/h2zero/n-able-Arduino/issues" | |
| }, | |
| "url": f"https://github.com/h2zero/n-able-Arduino/archive/{version}.tar.gz", | |
| "archiveFileName": archive_name, | |
| "checksum": f"SHA-256:{checksum}", | |
| "size": str(size), | |
| "boards": [ | |
| {"name": "Adafruit CLUE nRF52840"}, | |
| {"name": "Adafruit Circuit Playground Bluefruit"}, | |
| {"name": "Adafruit Feather nRF52832"}, | |
| {"name": "Adafruit Feather nRF52840 Express"}, | |
| {"name": "Adafruit Feather nRF52840 Sense"}, | |
| {"name": "Adafruit ItsyBitsy nRF52840 Express"}, | |
| {"name": "BBC micro:bit"}, | |
| {"name": "BBC micro:bit v2"}, | |
| {"name": "Bluz DK"}, | |
| {"name": "Calliope mini"}, | |
| {"name": "Ebyte E104-BT5032A-TB"}, | |
| {"name": "Ebyte E104-BT5040UA Dongle"}, | |
| {"name": "Electronut labs bluey"}, | |
| {"name": "Electronut labs hackaBLE"}, | |
| {"name": "Electronut labs hackaBLE v2"}, | |
| {"name": "Generic nRF51822"}, | |
| {"name": "Generic nRF52810"}, | |
| {"name": "Generic nRF52832"}, | |
| {"name": "Generic nRF52833"}, | |
| {"name": "Generic nRF52840"}, | |
| {"name": "ng-beacon"}, | |
| {"name": "nRF51 Dongle"}, | |
| {"name": "nRF51822 DK"}, | |
| {"name": "nRF52832 DK"}, | |
| {"name": "nRF52833 DK"}, | |
| {"name": "nRF52840 DK"}, | |
| {"name": "nRF52840 Dongle"}, | |
| {"name": "Nordic Beacon Kit"}, | |
| {"name": "OSHChip"}, | |
| {"name": "RedBear BLE Nano"}, | |
| {"name": "RedBear BLE Nano 2"}, | |
| {"name": "RedBear Blend 2"}, | |
| {"name": "RedBear nRF51822"}, | |
| {"name": "Sino:bit"}, | |
| {"name": "TinyBLE"}, | |
| {"name": "Waveshare BLE400"}, | |
| {"name": "Seeed XIAO nRF52840 Sense"} | |
| ], | |
| "toolsDependencies": [ | |
| { | |
| "packager": "h2zero", | |
| "name": "gcc-arm-none-eabi", | |
| "version": "9.3.1-1" | |
| }, | |
| { | |
| "packager": "h2zero", | |
| "name": "openocd", | |
| "version": "0.11.0-4" | |
| } | |
| ] | |
| } | |
| # Check if version already exists and update or append | |
| found = False | |
| for platform in package_data['packages'][0]['platforms']: | |
| if platform['version'] == version: | |
| # Update existing version | |
| platform.update(new_platform) | |
| found = True | |
| break | |
| if not found: | |
| # Append new version (maintaining reverse chronological order) | |
| package_data['packages'][0]['platforms'].insert(0, new_platform) | |
| # Write updated package index | |
| with open('package_n-able_boards_index.json', 'w') as f: | |
| json.dump(package_data, f, indent=2) | |
| print(f"Updated package index for version {version}") | |
| EOF | |
| python update_index.py | |
| - name: Commit and push to gh-pages | |
| working-directory: gh-pages | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github.com" | |
| git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git | |
| git add package_n-able_boards_index.json | |
| git commit -m "Update package index for v${{ steps.version.outputs.version }}" || echo "No changes to commit" | |
| git push origin release-test |