Build and Push Releases #942
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 and Push Releases | |
| on: | |
| push: | |
| branches: | |
| - main, workflow | |
| tags: | |
| - "*" | |
| workflow_dispatch: | |
| jobs: | |
| compile_sketch: | |
| name: Build ${{ matrix.board.env }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| board: | |
| - { env: "m5stack-cardputer", family: "ESP32-S3",} | |
| - { env: "m5stack-cplus2", family: "ESP32",} | |
| - { env: "m5stack-cplus1_1", family: "ESP32",} | |
| - { env: "LAUNCHER_m5stack-cplus1_1", family: "ESP32",} | |
| - { env: "m5stack-core2", family: "ESP32",} | |
| - { env: "m5stack-core16mb", family: "ESP32",} | |
| - { env: "m5stack-core4mb", family: "ESP32",} | |
| - { env: "m5stack-cores3", family: "ESP32-S3",} | |
| - { env: "esp32-s3-devkitc-1", family: "ESP32-S3",} | |
| - { env: "esp32-c5", family: "ESP32-C5",} | |
| - { env: "esp32-c5-tft", family: "ESP32-C5",} | |
| - { env: "CYD-2432S028", family: "ESP32",} | |
| - { env: "CYD-2USB", family: "ESP32",} | |
| - { env: "CYD-2432W328C", family: "ESP32",} | |
| - { env: "CYD-2432W328C_2", family: "ESP32",} | |
| - { env: "CYD-2432W328R-or-S024R", family: "ESP32",} | |
| - { env: "LAUNCHER_CYD-2432W328R-or-S024R", family: "ESP32",} | |
| - { env: "LAUNCHER_CYD-2432S028", family: "ESP32",} | |
| - { env: "LAUNCHER_CYD-2USB", family: "ESP32",} | |
| - { env: "LAUNCHER_CYD-2432W328C", family: "ESP32",} | |
| - { env: "lilygo-t-embed-cc1101", family: "ESP32-S3",} | |
| - { env: "lilygo-t-embed", family: "ESP32-S3",} | |
| - { env: "lilygo-t-deck", family: "ESP32-S3",} | |
| - { env: "lilygo-t-watch-s3", family: "ESP32-S3",} | |
| - { env: "lilygo-t-deck-pro", family: "ESP32-S3",} | |
| - { env: "lilygo-t-display-s3", family: "ESP32-S3",} | |
| - { env: "lilygo-t-display-s3-touch", family: "ESP32-S3",} | |
| - { env: "lilygo-t-display-s3-mmc", family: "ESP32-S3",} | |
| - { env: "lilygo-t-display-s3-touch-mmc", family: "ESP32-S3",} | |
| - { env: "lilygo-t-display-S3-pro", family: "ESP32-S3",} | |
| - { env: "lilygo-t-display-ttgo", family: "ESP32",} | |
| - { env: "lilygo-t-hmi", family: "ESP32-S3",} | |
| - { env: "lilygo-t-lora-pager", family: "ESP32-S3",} | |
| - { env: "smoochiee-board", family: "ESP32-S3",} | |
| - { env: "Phantom_S024R", family: "ESP32",} | |
| - { env: "LAUNCHER_Phantom_S024R", family: "ESP32",} | |
| - { env: "Marauder-Mini", family: "ESP32",} | |
| - { env: "LAUNCHER_Marauder-Mini", family: "ESP32",} | |
| - { env: "Awok-Mini", family: "ESP32",} | |
| - { env: "Marauder-v7", family: "ESP32",} | |
| - { env: "LAUNCHER_Marauder-v7", family: "ESP32",} | |
| - { env: "Marauder-V4-V6", family: "ESP32",} | |
| - { env: "Marauder-v61", family: "ESP32",} | |
| - { env: "LAUNCHER_Marauder-V4-V6", family: "ESP32",} | |
| - { env: "LAUNCHER_Marauder-v61", family: "ESP32",} | |
| - { env: "Awok-Touch", family: "ESP32",} | |
| - { env: "WaveSentry-R1", family: "ESP32",} | |
| - { env: "LAUNCHER_WaveSentry-R1", family: "ESP32",} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - id: build | |
| name: setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| # - name: Cache pip | |
| # uses: actions/cache@v4 | |
| # with: | |
| # path: ~/.cache/pip | |
| # key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
| # restore-keys: | | |
| # ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| run: | | |
| pip install requests esptool intelhex | |
| # - name: Cache PlatformIO | |
| # uses: actions/cache@v4 | |
| # with: | |
| # path: | | |
| # ~/.platformio | |
| # key: Bruce-platformio-${{ hashFiles('**/platformio.ini') }} | |
| # restore-keys: Bruce-platformio- | |
| # - name: Restore PIO | |
| # uses: actions/cache/restore@v4 | |
| # with: | |
| # path: | | |
| # ${{ github.workspace }}/.pio | |
| # key: Bruce-pio-${{ matrix.board.env }}-${{ github.run_id }}-${{ github.run_attempt }} | |
| # restore-keys: | | |
| # Bruce-pio-${{ matrix.board.env }}- | |
| - name: Install PlatformIO Core | |
| run: | | |
| pip install platformio | |
| if [[ "${{ github.ref_type }}" == "tag" ]]; then | |
| version=${{ github.ref_name }} | |
| else | |
| version="${GITHUB_SHA::7}" | |
| fi | |
| sed -i "s/-DBRUCE_VERSION=/-DBRUCE_VERSION='\"$version\"' ; /g" ./platformio.ini | |
| sed -i "s/-DGIT_COMMIT_HASH='\"Homebrew\"'/\!echo '-DGIT_COMMIT_HASH=\\\\\\\\\"'\$\(git describe --always --dirty)'\\\\\\\\\"'/g" ./platformio.ini | |
| cat ./platformio.ini | |
| - name: Run Compile | |
| run: | | |
| platformio run -e ${{ matrix.board.env }} | |
| # - name: Cache PIO | |
| # uses: actions/cache/save@v4 | |
| # with: | |
| # path: | | |
| # ${{ github.workspace }}/.pio | |
| # key: Bruce-pio-${{ matrix.board.env }}-${{ github.run_id }}-${{ github.run_attempt }} | |
| - name: Merge files | |
| run: | | |
| # pio run -e ${{ matrix.board.env }} -t build-firmware | |
| # Files are merged after build | |
| - name: Upload ${{ matrix.board.env }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Bruce-${{ matrix.board.env }} | |
| path: Bruce-*.* | |
| retention-days: 1 | |
| if-no-files-found: error | |
| post_compile_steps: | |
| name: Update Placeholders | |
| runs-on: ubuntu-latest | |
| environment: github_release | |
| needs: compile_sketch | |
| if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') || github.ref_type == 'tag' | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: '*' | |
| merge-multiple: true | |
| path: artifacts | |
| - name: Ensure releases exist and get IDs | |
| id: get_release | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const ensureByTag = async (tag, prerelease=true) => { | |
| try { | |
| const { data } = await github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag | |
| }); | |
| return data.id; | |
| } catch (e) { | |
| if (e.status !== 404) throw e; | |
| const { data } = await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: tag, | |
| name: tag, | |
| prerelease | |
| }); | |
| return data.id; | |
| } | |
| }; | |
| const betaId = await ensureByTag('betaRelease'); | |
| const lastId = await ensureByTag('lastRelease'); | |
| core.setOutput('beta', String(betaId)); | |
| core.setOutput('last', String(lastId)); | |
| - name: Get current sha | |
| id: get_sha | |
| run: | | |
| echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
| - name: Delete old betaRelease assets | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const release_id = ${{ steps.get_release.outputs.beta }}; | |
| const assets = await github.rest.repos.listReleaseAssets({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: release_id | |
| }); | |
| for (const asset of assets.data) { | |
| await github.rest.repos.deleteReleaseAsset({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| asset_id: asset.id | |
| }); | |
| } | |
| - name: Upload new betaRelease asset | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: betaRelease commit (${{ steps.get_sha.outputs.GITHUB_SHA_SHORT }}) | |
| tag_name: betaRelease | |
| prerelease: true | |
| files: artifacts/** | |
| fail_on_unmatched_files: false | |
| make_latest: false | |
| generate_release_notes: false | |
| - name: Delete old lastRelease assets | |
| uses: actions/github-script@v6 | |
| if: github.ref_type == 'tag' | |
| with: | |
| script: | | |
| const release_id = ${{ steps.get_release.outputs.last }}; | |
| const assets = await github.rest.repos.listReleaseAssets({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: release_id | |
| }); | |
| for (const asset of assets.data) { | |
| await github.rest.repos.deleteReleaseAsset({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| asset_id: asset.id | |
| }); | |
| } | |
| - name: Upload new lastRelease asset | |
| uses: softprops/action-gh-release@v2 | |
| if: github.ref_type == 'tag' | |
| with: | |
| name: lastRelease commit (${{ steps.get_sha.outputs.GITHUB_SHA_SHORT }}) | |
| tag_name: lastRelease | |
| prerelease: true | |
| files: artifacts/** | |
| fail_on_unmatched_files: false | |
| make_latest: false | |
| generate_release_notes: false | |
| - name: Checkout main to trigger WebPage deploy | |
| if: ${{ success() }} | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| fetch-depth: 1 | |
| - name: Trigger WebPage deploy (workflow_dispatch) | |
| if: ${{ success() }} | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh workflow list | |
| gh workflow run .github/workflows/deploy.yml --ref WebPage | |
| create_release: | |
| runs-on: ubuntu-latest | |
| environment: github_release | |
| needs: [compile_sketch] | |
| if: github.ref_type == 'tag' | |
| steps: | |
| - id: bruce_version | |
| name: Get Version | |
| run: | | |
| set -x | |
| if [[ "${{ github.ref_type }}" == "tag" ]]; then | |
| version=${{ github.ref_name }} | |
| else | |
| version="${GITHUB_SHA::7}" | |
| fi | |
| echo "version=${version}" > $GITHUB_OUTPUT | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| merge-multiple: true | |
| - name: List all files | |
| if: always() | |
| run: | | |
| set -x | |
| pwd | |
| ls -all | |
| tree | |
| - name: Create Release ${{ steps.bruce_version.outputs.version }} | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: Bruce Release ${{ steps.bruce_version.outputs.version }} | |
| tag_name: ${{ steps.bruce_version.outputs.version }} | |
| generate_release_notes: true | |
| files: | | |
| Bruce-*.bin |