name: Build on: workflow_dispatch: push: paths-ignore: - "assets/**" - "**/*.md" - "LICENSE" pull_request: paths-ignore: - "assets/**" - "**/*.md" - "LICENSE" concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true permissions: contents: read env: # Keep Python within the versions supported by pioarduino. PYTHON_VERSION: "3.13" jobs: prepare: name: Prepare (get envs) # A push already builds updates to PRs from this repository. if: >- github.event.action != 'synchronize' || github.event.pull_request.head.repo.full_name != github.repository runs-on: ubuntu-latest outputs: envs: ${{ steps.envs.outputs.envs }} env_titles: ${{ steps.envs.outputs.env_titles }} release_branch: ${{ steps.release_branch.outputs.branch }} steps: - name: Checkout uses: actions/checkout@v6 with: # A new tag needs branch history to determine whether its commit is on master. fetch-depth: ${{ startsWith(github.ref, 'refs/tags/v') && github.event.created && '0' || '1' }} - name: Python uses: actions/setup-python@v6 with: python-version: ${{ env.PYTHON_VERSION }} - name: Check tagged commit on master id: release_branch if: github.event_name == 'push' && github.event.created && startsWith(github.ref, 'refs/tags/v') run: | branch=$(git branch --remotes --contains HEAD --list origin/master --format='%(refname:short)') echo "branch=$branch" >> "$GITHUB_OUTPUT" - name: Install PlatformIO Core run: | python -m pip install --upgrade pip pip install --upgrade platformio pip install --upgrade intelhex - name: Get environments id: envs shell: bash run: | pio project config --json-output \ | jq -r ' [ .[] | select(type == "array") | select(.[0] | startswith("env:")) | { name: (.[0] | sub("^env:"; "")), title: ([.[1][] | select(.[0] == "custom_title") | .[1]][0]) } ] as $envs | { envs: ($envs | map(.name)), env_titles: ($envs | map({key: .name, value: .title}) | from_entries) } | to_entries[] | "\(.key)=\(.value | tojson)" ' | tee -a "$GITHUB_OUTPUT" build: name: Build ${{ matrix.env }} runs-on: ubuntu-latest needs: prepare strategy: fail-fast: false matrix: env: ${{ fromJson(needs.prepare.outputs.envs) }} steps: - name: Checkout uses: actions/checkout@v6 - name: Python uses: actions/setup-python@v6 with: python-version: ${{ env.PYTHON_VERSION }} - name: Install Node.js uses: actions/setup-node@v5 with: node-version: "22" - name: Install PlatformIO Core run: | python -m pip install --upgrade pip pip install --upgrade platformio pip install --upgrade intelhex - name: Set firmware version from tag if: startsWith(github.ref, 'refs/tags/v') && !github.event.deleted run: | version="${GITHUB_REF_NAME#v}" if [[ ! $version =~ ^[0-9][a-zA-Z0-9.+-]*$ ]]; then echo "::error::Expected a version tag such as v2.0.0 or v2.0.0-rc.1." exit 1 fi sed -i -E "s/^custom_version[[:blank:]]*=.*/custom_version = $version/" platformio.ini echo "RELEASE_VERSION=$version" >> "$GITHUB_ENV" - name: Full clean run: | pio run -e ${{ matrix.env }} -t fullclean - name: Build firmware & filesystem env: PIOENV: ${{ matrix.env }} run: | pio run -e ${{ matrix.env }} - name: Check release files if: env.RELEASE_VERSION != '' working-directory: build env: BOARD: ${{ matrix.env }} run: | files=( "firmware_${BOARD}_${RELEASE_VERSION}.bin" "firmware_${BOARD}_${RELEASE_VERSION}.factory.bin" "firmware_${BOARD}_${RELEASE_VERSION}.elf" "filesystem_${BOARD}_${RELEASE_VERSION}.bin" ) for file in "${files[@]}"; do if [[ ! -s "$file" ]]; then echo "::error::Release file missing or empty: $file" exit 1 fi done - name: Upload artifacts uses: actions/upload-artifact@v7 with: name: ${{ matrix.env }} if-no-files-found: error path: | build/*.bin build/*.elf release: name: Release runs-on: ubuntu-latest needs: [prepare, build] if: >- github.repository_owner == 'Laxilef' && github.event_name == 'push' && (github.ref == 'refs/heads/dev' || needs.prepare.outputs.release_branch == 'origin/master') permissions: contents: write steps: - name: Checkout uses: actions/checkout@v6 with: fetch-depth: 0 - name: Move unstable tag if: github.ref == 'refs/heads/dev' run: | git fetch --tags git tag -f unstable git push origin refs/tags/unstable --force - name: Download artifacts uses: actions/download-artifact@v5 with: path: artifacts merge-multiple: true - name: Generate Web Flasher manifest env: ENVS: ${{ needs.prepare.outputs.envs }} ENV_TITLES: ${{ needs.prepare.outputs.env_titles }} run: python3 tools/generate_webflasher.py --envs "$ENVS" --titles "$ENV_TITLES" - name: Delete old release assets if: github.ref == 'refs/heads/dev' uses: mknejp/delete-release-assets@v1 with: token: ${{ secrets.GITHUB_TOKEN }} tag: unstable fail-if-no-assets: false fail-if-no-release: false assets: | *.bin *.elf webflasher.json - name: Clear release body if: github.ref == 'refs/heads/dev' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh release edit unstable --notes "" - name: Publish Unstable release if: github.ref == 'refs/heads/dev' uses: softprops/action-gh-release@v3 with: tag_name: unstable target_commitish: ${{ github.sha }} name: Unstable prerelease: true make_latest: false generate_release_notes: true fail_on_unmatched_files: true files: | artifacts/*.bin artifacts/*.elf artifacts/webflasher.json - name: Publish new release if: github.ref_type == 'tag' uses: softprops/action-gh-release@v3 with: draft: true prerelease: false make_latest: true generate_release_notes: true fail_on_unmatched_files: true files: | artifacts/*.bin artifacts/*.elf artifacts/webflasher.json