Build, release, push firmware #5
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: Build, release, push firmware | |
| permissions: | |
| contents: write | |
| on: | |
| workflow_dispatch: | |
| push: | |
| tags: | |
| - "*" | |
| jobs: | |
| build_release_push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Clone repository | |
| uses: actions/checkout@v3 | |
| with: | |
| submodules: "recursive" | |
| - name: Get Release tag | |
| id: get_tag | |
| shell: bash | |
| run: | | |
| value=${GITHUB_REF#refs/tags/} | |
| clean_tag=${value:1} | |
| echo "tag=$value" >> $GITHUB_OUTPUT | |
| echo "file_tag=$clean_tag" >> $GITHUB_OUTPUT | |
| - name: Display src/version.h before update | |
| run: cat src/version.h | |
| - name: Update version in source code | |
| run: | | |
| sed -i 's/#define VERSION.*/#define VERSION "${{ steps.get_tag.outputs.tag }}"/' src/version.h | |
| - name: Display src/version.h after update | |
| run: cat src/version.h | |
| - name: Install Node JS | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 18 | |
| - uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cache/pip | |
| ~/.platformio/.cache | |
| key: ${{ runner.os }}-pio | |
| - name: Install Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.9" | |
| - name: Install PlatformIO Core | |
| run: pip install --upgrade platformio==6.1.11 | |
| - name: Build PlatformIO Project | |
| run: pio run | |
| - name: Get last commit message | |
| id: get_commit_message | |
| run: | | |
| currentTag=${{ steps.get_tag.outputs.tag }} | |
| printf -v badgeTextWithNewlines "%s\n\n" "$badgeText" | |
| commitMessage=$(git log -1 --pretty=%B | tail -n +2) | |
| fullCommitMessage="${badgeTextWithNewlines}${commitMessage}" | |
| echo "releaseMessage<<EOF" >> $GITHUB_ENV | |
| printf "%s\n" "$fullCommitMessage" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| echo "commitMessage<<EOF" >> $GITHUB_ENV | |
| printf "%s\n" "$commitMessage" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| env: | |
| GITHUB_REF: ${{ github.ref }} | |
| - name: Create manifest.json for ESP Web Tools | |
| run: | | |
| cat << EOF > manifest.json | |
| { | |
| "name": "CZC Firmware", | |
| "version": "${{ steps.get_tag.outputs.tag }}", | |
| "builds": [ | |
| { | |
| "chipFamily": "ESP32", | |
| "improv": false, | |
| "parts": [ | |
| { | |
| "path": "https://raw.githubusercontent.com/${{ github.repository }}/releases/${{ steps.get_tag.outputs.tag }}/czc_fw_${{ steps.get_tag.outputs.tag }}.full.bin", | |
| "offset": 0 | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| EOF | |
| echo "Manifest file created." | |
| - name: Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| generate_release_notes: false | |
| name: "${{ steps.get_tag.outputs.tag }}" | |
| body: ${{ env.releaseMessage }} | |
| files: | | |
| bin/czc_fw_${{ steps.get_tag.outputs.file_tag }}.ota.bin | |
| bin/czc_fw_${{ steps.get_tag.outputs.file_tag }}.full.bin | |
| - name: Checkout releases branch | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: releases | |
| path: releases | |
| - name: Copy files to releases directory | |
| run: | | |
| TAG=${{ steps.get_tag.outputs.tag }} | |
| CLEAN_TAG=${TAG:1} | |
| echo "Listing bin directory:" | |
| ls -la ./bin | |
| mkdir -p releases/$TAG | |
| cp ./bin/czc_fw_$CLEAN_TAG.full.bin releases/$TAG/ | |
| cp manifest.json releases/$TAG/ | |
| echo "Files copied to releases directory." | |
| - name: Commit and push files to releases branch | |
| run: | | |
| cd releases | |
| git config --local user.email "[email protected]" | |
| git config --local user.name "GitHub Action" | |
| if [[ -n $(git status --porcelain) ]]; then | |
| git add . | |
| git commit -m "Add firmware and manifest for version ${{ steps.get_tag.outputs.tag }}" | |
| git push origin releases | |
| else | |
| echo "No changes to commit" | |
| fi |