Skip to content

Merge pull request #36 from RTGS-Lab/feature/international-build #25

Merge pull request #36 from RTGS-Lab/feature/international-build

Merge pull request #36 from RTGS-Lab/feature/international-build #25

name: Release Workflow
on:
# Runs on direct push to master, but we'll check if it's from a PR merge in the job condition
push:
branches:
- master # or 'main' depending on your main branch
# Removed pull_request trigger to avoid duplicate runs
# Allows manual triggering from the Actions tab
workflow_dispatch:
inputs:
version_increment:
description: 'Force version increment (yes/no)'
required: false
default: 'no'
release_notes:
description: 'Custom release notes'
required: false
jobs:
release:
name: Compile and Release
# Run this job if:
# 1. Any push to master (including PR merges)
# 2. Manually triggered
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
outputs:
firmware-version: ${{ steps.compile-bsom.outputs.firmware-version }}
firmware-version-updated: ${{ steps.compile-bsom.outputs.firmware-version-updated }}
release-url: ${{ steps.release.outputs.html_url }}
strategy:
matrix:
platform: ['bsom', 'b5som']
steps:
# Generate a GitHub App token using the official action - UNCONDITIONALLY
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
# Explicitly specify contents write permission to push changes
permission-contents: write
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Compile application for BSOM
id: compile-bsom
if: matrix.platform == 'bsom'
uses: particle-iot/compile-action@9dbe1eb567c6268f1baa7458217d5d6e5553850d
with:
particle-platform-name: 'bsom'
auto-version: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.version_increment != 'no' }}
device-os-version: 6.2.1
- name: Compile application for B5SOM
id: compile-b5som
if: matrix.platform == 'b5som'
uses: particle-iot/compile-action@9dbe1eb567c6268f1baa7458217d5d6e5553850d
with:
particle-platform-name: 'b5som'
auto-version: false
device-os-version: 6.2.1
- name: Upload BSOM artifacts
if: matrix.platform == 'bsom'
uses: actions/upload-artifact@v4
with:
name: bsom-release-artifacts
path: |
${{ steps.compile-bsom.outputs.firmware-path }}
${{ steps.compile-bsom.outputs.target-path }}
- name: Upload B5SOM artifacts
if: matrix.platform == 'b5som'
uses: actions/upload-artifact@v4
with:
name: b5som-release-artifacts
path: |
${{ steps.compile-b5som.outputs.firmware-path }}
${{ steps.compile-b5som.outputs.target-path }}
- name: Commit updated version file
id: commit
if: matrix.platform == 'bsom' && steps.compile-bsom.outputs.firmware-version-updated == 'true'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git commit -m "Update firmware version" -a
echo "updated-version-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
# When a GitHub Action pushes commits or tags, it does not trigger a new GitHub Action job
- name: Push changes
if: matrix.platform == 'bsom' && steps.compile-bsom.outputs.firmware-version-updated == 'true'
run: |
git push origin HEAD:${{ github.ref_name }}
- name: Create archive and rename firmware files for BSOM
if: matrix.platform == 'bsom' && steps.compile-bsom.outputs.firmware-version-updated == 'true'
run: |
tar -czf debug-objects-bsom.tar.gz ${{ steps.compile-bsom.outputs.target-path }}
# Copy firmware binary with version in filename
cp ${{ steps.compile-bsom.outputs.firmware-path }} firmware-bsom-${{ steps.compile-bsom.outputs.firmware-version }}.bin
- name: Create archive and rename firmware files for B5SOM
if: matrix.platform == 'b5som'
run: |
tar -czf debug-objects-b5som.tar.gz ${{ steps.compile-b5som.outputs.target-path }}
# Copy firmware binary with version in filename
VERSION=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name' | sed 's/^v//')
if [ "$VERSION" == "null" ] || [ -z "$VERSION" ]; then
VERSION="0.0.1"
fi
cp ${{ steps.compile-b5som.outputs.firmware-path }} firmware-b5som-$VERSION.bin
- name: Upload versioned firmware artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-versioned-firmware
path: |
firmware-${{ matrix.platform }}-*.bin
debug-objects-${{ matrix.platform }}.tar.gz
create-release:
name: Create GitHub Release
needs: release
runs-on: ubuntu-latest
if: needs.release.outputs.firmware-version-updated == 'true'
outputs:
release-url: ${{ steps.release.outputs.html_url }}
steps:
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-contents: write
- name: Download all versioned firmware artifacts
uses: actions/download-artifact@v4
with:
path: ./release-files
- name: Prepare release artifacts
run: |
find ./release-files -name "*.bin" -o -name "*.tar.gz" | head -10
ls -la ./release-files/
- name: Create GitHub release
id: release
uses: ncipollo/release-action@v1
with:
artifacts: ./release-files/**/*
generateReleaseNotes: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.release_notes == '' }}
body: ${{ github.event.inputs.release_notes }}
name: "Firmware v${{ needs.release.outputs.firmware-version }}"
tag: "v${{ needs.release.outputs.firmware-version }}"
token: ${{ steps.app-token.outputs.token }}
upload-bsom-to-particle:
name: Upload BSOM to Particle Projects
needs: [release, create-release]
runs-on: ubuntu-latest
# Only run if release job has completed and the firmware version was updated
if: needs.release.outputs.firmware-version-updated == 'true'
strategy:
matrix:
project:
- name: "GEMS Demo"
product_id_secret: "PARTICLE_GEMS_DEMO_PRODUCT_ID"
- name: "Runk Lab (B SoM)"
product_id_secret: "PARTICLE_RUNCK_LAB_BSOM_PRODUCT_ID"
- name: "WinterTurf - v3"
product_id_secret: "PARTICLE_WINTERTURF_PRODUCT_ID"
- name: "Plant Pathways"
product_id_secret: "PARTICLE_PLANT_PATHWAYS_PRODUCT_ID"
- name: "LCCMR Irrigation"
product_id_secret: "PARTICLE_LCCMR_IRRIGATION_PRODUCT_ID"
- name: "Roadside Turf"
product_id_secret: "PARTICLE_ROADSIDE_TURF_PRODUCT_ID"
- name: "PepsiCo"
product_id_secret: "PARTICLE_PEPSICO_PRODUCT_ID"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download BSOM release artifacts
uses: actions/download-artifact@v4
with:
name: bsom-release-artifacts
path: ./bsom-release
- name: Find BSOM firmware binary
id: find_binary
run: |
FIRMWARE=$(find ./bsom-release -name "*.bin" -type f | head -n 1)
# Create a properly named firmware file
cp "$FIRMWARE" "firmware-bsom-${{ needs.release.outputs.firmware-version }}.bin"
echo "firmware-path=firmware-bsom-${{ needs.release.outputs.firmware-version }}.bin" >> $GITHUB_OUTPUT
- name: Upload BSOM firmware to ${{ matrix.project.name }}
uses: particle-iot/firmware-upload-action@v1
with:
particle-access-token: ${{ secrets.PARTICLE_ACCESS_TOKEN }}
firmware-path: ${{ steps.find_binary.outputs.firmware-path }}
firmware-version: ${{ needs.release.outputs.firmware-version }}
product-id: ${{ secrets[matrix.project.product_id_secret] }}
title: 'Firmware v${{ needs.release.outputs.firmware-version }}'
description: '[Firmware v${{ needs.release.outputs.firmware-version }} GitHub Release](${{ needs.create-release.outputs.release-url }})'
- name: Log upload success
run: |
echo "✅ Successfully uploaded BSOM firmware v${{ needs.release.outputs.firmware-version }} to ${{ matrix.project.name }}"
upload-b5som-to-particle:
name: Upload B5SOM to Particle Projects
needs: [release, create-release]
runs-on: ubuntu-latest
# Only run if release job has completed and the firmware version was updated
if: needs.release.outputs.firmware-version-updated == 'true'
strategy:
matrix:
project:
- name: "WinterTurf - v3 International"
product_id_secret: "PARTICLE_WINTERTURF_INTERNATIONAL_PRODUCT_ID"
- name: "Stellenbosch"
product_id_secret: "PARTICLE_STELLENBOSCH_PRODUCT_ID"
- name: "Runk Lab (B5 SoM)"
product_id_secret: "PARTICLE_RUNCK_LAB_B5SOM_PRODUCT_ID"
- name: "LCCMR Irrigation Sensing"
product_id_secret: "PARTICLE_LCCMR_IRRIGATION_SENSING_PRODUCT_ID"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download B5SOM release artifacts
uses: actions/download-artifact@v4
with:
name: b5som-release-artifacts
path: ./b5som-release
- name: Find B5SOM firmware binary
id: find_binary
run: |
FIRMWARE=$(find ./b5som-release -name "*.bin" -type f | head -n 1)
# Create a properly named firmware file
cp "$FIRMWARE" "firmware-b5som-${{ needs.release.outputs.firmware-version }}.bin"
echo "firmware-path=firmware-b5som-${{ needs.release.outputs.firmware-version }}.bin" >> $GITHUB_OUTPUT
- name: Upload B5SOM firmware to ${{ matrix.project.name }}
uses: particle-iot/firmware-upload-action@v1
with:
particle-access-token: ${{ secrets.PARTICLE_ACCESS_TOKEN }}
firmware-path: ${{ steps.find_binary.outputs.firmware-path }}
firmware-version: ${{ needs.release.outputs.firmware-version }}
product-id: ${{ secrets[matrix.project.product_id_secret] }}
title: 'Firmware v${{ needs.release.outputs.firmware-version }}'
description: '[Firmware v${{ needs.release.outputs.firmware-version }} GitHub Release](${{ needs.create-release.outputs.release-url }})'
- name: Log upload success
run: |
echo "✅ Successfully uploaded B5SOM firmware v${{ needs.release.outputs.firmware-version }} to ${{ matrix.project.name }}"