Skip to content

Commit

Permalink
Merge pull request #27 from ApolloAutomation/NewBuildAction
Browse files Browse the repository at this point in the history
New build action
  • Loading branch information
TrevorSchirmer authored Feb 21, 2025
2 parents fd9dfbd + 2035385 commit 74d7652
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 117 deletions.
179 changes: 68 additions & 111 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,142 +1,99 @@
name: Build
env:
DEVICE_NAME: msr-2
RELEASE_URL: ${{ github.server_url }}/${{ github.repository }}/releases/latest
name: Publish

on:
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'The version of the firmware to build'
required: true
release:
types: [published]

jobs:
build:
name: Build And Release
build-all-firmware:
name: Build And Release (All)
runs-on: ubuntu-latest

# We create a matrix of 4 "config" entries to build each firmware
strategy:
matrix:
config:
- name: firmware
files: Integrations/ESPHome/MSR-2_Factory.yaml
steps:
- uses: actions/checkout@v4

- name: Set uppercase DEVICE_NAME
run: |
echo "UPPERCASE_DEVICE_NAME=$(echo $DEVICE_NAME | tr '[:lower:]' '[:upper:]')" >> $GITHUB_ENV
- name: Build Firmware
uses: esphome/[email protected]
id: esphome-build
# Each matrix iteration calls the same ESPHome build workflow
- name: Build firmware for ${{ matrix.config.name }}
id: build
uses: esphome/workflows/.github/workflows/build.yml@main
with:
yaml_file: Integrations/ESPHome/${{ env.UPPERCASE_DEVICE_NAME }}.yaml
version: 'latest'
cache: true

- name: Read version from YAML file
id: read_version
run: |
version=$(awk '/substitutions:/ {found=1} found && /version:/ {print $2; exit}' Integrations/ESPHome/${{ env.UPPERCASE_DEVICE_NAME }}.yaml | tr -d '"')
echo "project_version=$version" >> $GITHUB_ENV
- name: Move generated files to output
run: |
mkdir -p output
mv ${{ steps.esphome-build.outputs.name }}/* output/
echo ${{ steps.esphome-build.outputs.version }} > output/version
# Extract MD5 checksum of firmware.ota.bin
MD5_CHECKSUM=$(jq -r '.ota.md5' output/manifest.json)
echo "MD5_CHECKSUM=$MD5_CHECKSUM" >> $GITHUB_ENV
# Create new manifest.json with jq
jq -n --arg name "${{ env.DEVICE_NAME }}" \
--arg version "${{ env.project_version }}" \
--arg md5 "$MD5_CHECKSUM" \
'{name: $name, version: $version, home_assistant_domain: "esphome", new_install_prompt_erase: false, builds: [{chipFamily: "ESP32-C3", parts: [{path: "apollo-${{ env.DEVICE_NAME }}-esp32c3.factory.bin", offset: 0}], ota: {path: "apollo-${{ env.DEVICE_NAME }}-esp32c3.ota.bin", md5: $md5}}]}' > output/manifest.json
- uses: actions/[email protected]
with:
path: output/
retention-days: 1

- name: Collect merge commits
id: collect_commits
run: |
MERGE_COMMITS=$(git log --merges --pretty=format:"%h %s" $(git describe --tags --abbrev=0 @^)..@)
echo "MERGE_COMMITS=$MERGE_COMMITS" >> $GITHUB_ENV
- name: Create Release
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
tag_name: ${{ env.project_version }}
release_name: "Release ${{ env.project_version }}"
body: Release of version ${{ env.project_version }}

draft: false
prerelease: false

- name: Upload firmware.factory.bin to Release
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: output/apollo-${{ env.DEVICE_NAME }}-esp32c3.factory.bin
asset_name: apollo-${{ env.DEVICE_NAME }}-esp32c3.factory.bin
asset_content_type: application/octet-stream

- name: Upload firmware.ota.bin to Release
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: output/apollo-${{ env.DEVICE_NAME }}-esp32c3.ota.bin
asset_name: apollo-${{ env.DEVICE_NAME }}-esp32c3.ota.bin
asset_content_type: application/octet-stream
- name: Upload firmware.ota.bin to Release
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: output/manifest.json
asset_name: manifest.json
asset_content_type: application/octet-stream

files: ${{ matrix.config.files }}
esphome-version: stable
combined-name: ${{ matrix.config.name }}
release-summary: ${{ github.event_name == 'release' && github.event.release.body || '' }}
release-url: ${{ github.event_name == 'release' && github.event.release.html_url || '' }}
release-version: ${{ (github.event_name == 'release' && github.event.release.tag_name)
|| (github.event_name == 'workflow_dispatch' && inputs.version)
|| '' }}

prep:
name: Consolidate firmwares
build-site:
name: Build Site
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
- name: Checkout source code
uses: actions/checkout@v4
- name: Build
uses: actions/[email protected]
with:
path: output
- run: cp -R static/* output/
- uses: actions/[email protected]
source: ./static
destination: ./output
- name: Upload
uses: actions/upload-artifact@v4
with:
name: site
path: output
retention-days: 1

deploy:
if: contains(fromJSON('["workflow_dispatch", "push", "schedule"]'), github.event_name) && github.ref == 'refs/heads/main'
name: Deploy to GitHub Pages
publish:
name: Publish to GitHub Pages
runs-on: ubuntu-latest
needs: prep
needs:
- build-all-firmware
- build-site
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
# Download each firmware artifact by its "combined-name" (matrix.config.name)
- uses: actions/download-artifact@v4
with:
name: firmware
path: firmware

- name: Copy firmware and manifest
run: |-
mkdir -p output/firmware
cp -r firmware/${{ needs.build-all-firmware.outputs.version }}/* output/firmware/
- uses: actions/download-artifact@v4
with:
name: site
path: output

- uses: actions/upload-pages-artifact@v3
with:
path: output
retention-days: 1

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4.0.5
uses: actions/deploy-pages@v4
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ jobs:
strategy:
matrix:
file:
- Integrations/ESPHome/MSR-2_Factory.yaml
- Integrations/ESPHome/MSR-2.yaml
- Integrations/ESPHome/MSR-2_BLE.yaml
- Integrations/ESPHome/MSR-2_Factory.yaml
esphome-version:
- stable
- beta
- dev
steps:
- name: Checkout source code
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion Integrations/ESPHome/Core.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
substitutions:
name: apollo-msr-2
version: "25.2.21.1"
version: "25.2.21.2"
device_description: ${name} made by Apollo Automation - version ${version}.

esp32:
Expand Down
10 changes: 6 additions & 4 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@
<div class="content">
<h1>Apollo MSR-2 Installer</h1>

<p class="button-row" align="center">
<esp-web-install-button manifest="./artifact/manifest.json">
</esp-web-install-button>
</p>
<div class="button-row" style="display: flex; justify-content: center; gap: 20px; align-items: center;">
<div>
<p>MSR-2 Firmware</p>
<esp-web-install-button manifest="./firmware/manifest.json"></esp-web-install-button>
</div>
</div>

<div class="footer">
<a href="https://github.com/ApolloAutomation/MSR-2"
Expand Down

0 comments on commit 74d7652

Please sign in to comment.