Skip to content

Add release workflow #13

Add release workflow

Add release workflow #13

Workflow file for this run

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=.gitattributes \
--exclude=node_modules \
--exclude=build \
--exclude=dist \
--exclude='*.tar.gz' \
--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: Upload archive artifact
uses: actions/upload-artifact@v4
with:
name: n-able-Arduino-${{ steps.version.outputs.version }}
path: n-able-Arduino-${{ steps.version.outputs.version }}.tar.gz
retention-days: 7
- 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
python ../.github/scripts/update_package_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