Build and Push Releases #601
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 and Push Releases | |
| on: | |
| push: | |
| # branches: | |
| # - main | |
| 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: "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",} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - id: build | |
| name: setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.x" | |
| - 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 | |
| js_content="{\"name\":\"${{ matrix.board.env }}\",\"new_install_prompt_erase\": true,\"builds\":[{\"chipFamily\":\"${{ matrix.board.family }}\",\"improv\":false,\"parts\":[{\"path\":\"Bruce-${{ matrix.board.env }}.bin\",\"offset\":0}]}]}" | |
| echo "$js_content" > "./Bruce-${{ matrix.board.env }}.json" | |
| - name: Upload ${{ matrix.board.env }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Bruce-${{ matrix.board.env }} | |
| path: Bruce-*.* | |
| retention-days: 5 | |
| 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 | |
| - 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: 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@v1 | |
| with: | |
| name: betaRelease commit (${{ github.sha }}) | |
| tag_name: betaRelease | |
| prerelease: true | |
| files: "*.*" | |
| 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@v1 | |
| if: github.ref_type == 'tag' | |
| with: | |
| name: lastRelease commit (${{ github.sha }}) | |
| tag_name: lastRelease | |
| prerelease: true | |
| files: "*.*" | |
| fail_on_unmatched_files: false | |
| make_latest: false | |
| generate_release_notes: false | |
| deploy_webpage: | |
| name: Deploy WebPage | |
| runs-on: ubuntu-latest | |
| needs: post_compile_steps | |
| if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') || github.ref_type == 'tag' | |
| steps: | |
| - name: Checkout WebPage branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: WebPageLight | |
| fetch-depth: 1 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 18 | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Download release assets for website | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| rm -rf BetaRelease LastRelease | |
| mkdir -p BetaRelease LastRelease | |
| gh release download betaRelease --dir ./BetaRelease --clobber | |
| gh release download lastRelease --dir ./LastRelease --clobber | |
| echo "Files are now available on release tag [lastRelease](https://github.com/pr3y/Bruce/releases/tag/lastRelease)" > LastRelease/README.md | |
| echo "Files are now available on release tag [betaRelease](https://github.com/pr3y/Bruce/releases/tag/betaRelease)" > BetaRelease/README.md | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v5 | |
| with: | |
| static_site_generator: sveltekit | |
| - name: Build website | |
| run: npm run build | |
| - name: Upload Artifacts | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| # this should match the `pages` option in your adapter-static options | |
| path: 'build/' | |
| deploy: | |
| needs: deploy_webpage | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Deploy | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| 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 |