Skip to content

Commit

Permalink
new ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
luka6000 committed Mar 9, 2025
1 parent e596a60 commit 7f8dfb8
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 8 deletions.
152 changes: 152 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Build

on:
workflow_call:
inputs:
files:
description: Newline separated list of files to build
required: true
type: string
esphome-version:
description: Version of ESPHome to build with
required: false
type: string
default: latest
release-summary:
description: Summary of the release
required: false
type: string
default: ""
release-url:
description: URL to the release notes
required: false
type: string
default: ""
release-version:
description: Version of the release
required: false
type: string
default: ""
combined-name:
description: Combine all files into a single manifest under this name
required: false
type: string
default: ""

outputs:
version:
description: Version of the firmware generated
value: ${{ jobs.prepare.outputs.version }}

jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
files: ${{ steps.files-array.outputs.files }}
version: ${{ steps.version.outputs.version }}
artifact-prefix: ${{ steps.artifact-name.outputs.artifact-prefix }}
steps:
- name: Split files input into JSON array
id: files-array
run: |
files=$(echo "${{ inputs.files }}" | jq -RcSn '[inputs | select(length>0)]')
echo files=$files >> $GITHUB_OUTPUT
- name: Generate version
id: version
run: |
if [ -n "${{ inputs.release-version }}" ]; then
version=${{ inputs.release-version }}
else
version=dev-$(date +'%Y%m%d-%H%M')
fi
echo version=$version >> $GITHUB_OUTPUT
- name: Generated random artifact prefix
id: artifact-name
run: |
artifact_prefix=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 16; echo)
echo artifact-prefix=$artifact_prefix >> $GITHUB_OUTPUT
build:
name: ${{ matrix.file }}
needs: [prepare]
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 3
matrix:
file: ${{ fromJson(needs.prepare.outputs.files) }}
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Replace project version
run: |
sed -i "s/version: dev/version: ${{ needs.prepare.outputs.version }}/g" ${{ matrix.file }}
- name: Build Firmware
uses: esphome/[email protected]
id: esphome-build
with:
yaml-file: ${{ matrix.file }}
version: ${{ inputs.esphome-version }}
complete-manifest: true
release-summary: ${{ inputs.release-summary }}
release-url: ${{ inputs.release-url }}
- name: Move files for versioning
run: |
mkdir -p output/${{ needs.prepare.outputs.version }}
mv ${{ steps.esphome-build.outputs.name }}/* output/${{ needs.prepare.outputs.version }}/
- name: Upload artifact
uses: actions/[email protected]
with:
name: ${{ inputs.combined-name != '' && format('{0}-{1}', needs.prepare.outputs.artifact-prefix, steps.esphome-build.outputs.name) || steps.esphome-build.outputs.original-name }}
path: output

combine:
name: Combine manifests
needs:
- prepare
- build
runs-on: ubuntu-latest
if: inputs.combined-name != ''
steps:
- name: Download artifacts
uses: actions/[email protected]
with:
path: files
pattern: ${{ needs.prepare.outputs.artifact-prefix }}-*

- name: Get artifact names
id: artifacts
run: |
artifacts=$(ls --format=single-column files)
echo "artifacts<<EOF" >> $GITHUB_OUTPUT
echo "$artifacts" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Delete prefixed artifacts
uses: geekyeggo/[email protected]
with:
name: ${{ steps.artifacts.outputs.artifacts }}

- name: Combine all parts into a single manifest
run: |
version="${{ needs.prepare.outputs.version }}"
mkdir -p "output/$version"
pushd files
for device in *; do
pushd $device
pushd $version
cp * "../../../output/$version/"
cp manifest.json ../../../output/$version/manifest-`ls *.elf |cut -d. -f1`.json
popd
popd
done
popd
jq -s '(.[0] | del(.builds)) + {"builds": (reduce .[].builds as $b ([]; . + $b))}' files/*/$version/manifest.json > output/$version/manifest.json
- name: Upload artifact
uses: actions/[email protected]
with:
name: ${{ inputs.combined-name }}
path: output
39 changes: 39 additions & 0 deletions .github/workflows/publish-firmware.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish Firmware

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

permissions:
contents: write

jobs:
build-firmware:
name: Build Firmware
uses: ./.github/workflows/build.yaml
with:
#### Modify below here to match your project ####
files: |
tagtuner-D1-custom1.factory.yaml
tagtuner-atom-grove-ble.factory.yaml
tagtuner-for-tagreader.factory.yaml
esphome-version: stable
combined-name: tagtuner-firmware
#### Modify above here to match your project ####

release-summary: ${{ github.event.release.body }}
release-url: ${{ github.event.release.html_url }}
release-version: ${{ (github.event_name == 'release' && github.event.release.tag_name) || (github.event_name == 'workflow_dispatch' && inputs.version) || '' }}

upload-to-release:
name: Upload to Release
uses: ./.github/workflows/upload-to-gh-release.yml
needs:
- build-firmware
with:
version: ${{ (github.event_name == 'release' && github.event.release.tag_name) || (github.event_name == 'workflow_dispatch' && inputs.version) || '' }}
67 changes: 67 additions & 0 deletions .github/workflows/publish-pages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Publish Pages

on:
push:
branches:
- main
paths:
- 'static/**'
- '.github/workflows/publish-pages.yml'
workflow_run:
workflows:
- Publish Firmware
types:
- completed

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/[email protected]

- run: mkdir -p output/firmware

- name: Build
uses: actions/[email protected]
with:
source: ./static
destination: ./output

- name: Fetch firmware files
uses: robinraju/[email protected]
with:
latest: true
fileName: '*'
out-file-path: output/firmware

- name: Upload artifact
uses: actions/[email protected]
with:
path: output
retention-days: 1

publish:
if: github.event_name != 'pull_request'
name: Publish
runs-on: ubuntu-latest
needs:
- build
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Setup Pages
uses: actions/[email protected]

- name: Deploy to GitHub Pages
id: deployment
uses: actions/[email protected]
46 changes: 46 additions & 0 deletions .github/workflows/upload-to-gh-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Upload firmware to GitHub Release

on:
workflow_call:
inputs:
version:
description: Version of the release
required: true
type: string

jobs:
upload:
name: Upload
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download Artifact
uses: actions/[email protected]
with:
path: files

- name: Copy files to output
run: |-
shopt -s nullglob
mkdir output
version="${{ inputs.version }}"
pushd files
for device in *; do
pushd $device
pushd $version
cp manifest*.json ../../../output/
for bin in *.{bin,elf}; do
md5sum $bin | head -c 32 > ../../../output/$bin.md5
cp $bin ../../../output/
done
popd
popd
done
popd
- name: Upload files to release
uses: softprops/[email protected]
with:
files: output/*
tag_name: ${{ inputs.version }}
2 changes: 1 addition & 1 deletion static/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Check out also the [TagTuner on HA Voice PE version](https://github.com/luka6000
You can use the button below to install the pre-built firmware directly to your device via USB from the browser. \
This works for ESP32 Atom and ESP8266 tagreader.

<esp-web-install-button manifest="./firmware/manifest.json"></esp-web-install-button>
<esp-web-install-button manifest="./firmware/tagtuner-firmware.manifest.json"></esp-web-install-button>

<script type="module" src="https://unpkg.com/esp-web-tools@9/dist/web/install-button.js?module"></script>

Expand Down
4 changes: 2 additions & 2 deletions tagtuner-D1-custom1.factory.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These substitutions allow the end user to override certain values
substitutions:
name: "tagtuner"
name: "tagtuner-d1"
friendly_name: "TagTuner"

packages:
Expand All @@ -20,7 +20,7 @@ esphome:
name_add_mac_suffix: true

project:
name: LukaGra.TagTuner
name: LukaGra.TagTuner-D1
version: dev

# This should point to the public location of this yaml file.
Expand Down
4 changes: 2 additions & 2 deletions tagtuner-atom-grove-ble.factory.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These substitutions allow the end user to override certain values
substitutions:
name: "tagtuner"
name: "tagtuner-atom"
friendly_name: "TagTuner"

packages:
Expand All @@ -20,7 +20,7 @@ esphome:
name_add_mac_suffix: true

project:
name: LukaGra.TagTuner
name: LukaGra.TagTuner-Atom
version: dev

# This should point to the public location of this yaml file.
Expand Down
2 changes: 1 addition & 1 deletion tagtuner-for-tagreader.factory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ esphome:
name_add_mac_suffix: true

project:
name: LukaGra.TagTuner
name: LukaGra.TagTuner-8266
version: dev

# This should point to the public location of this yaml file.
Expand Down
2 changes: 1 addition & 1 deletion tagtuner-for-tagreader.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These substitutions allow the end user to override certain values
substitutions:
name: "tagtuner"
name: "tagtuner-for-tagreader"
friendly_name: "TagTuner"
d1_mini: d1_mini
buzpin: D7
Expand Down
2 changes: 1 addition & 1 deletion tagtuner-on-ha-voice-pe.factory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ esphome:
name_add_mac_suffix: true

project:
name: LukaGra.TagTuner on Home Assistant Voice PE
name: LukaGra.TagTuner-on-Home-Assistant-Voice-PE
version: dev

# This should point to the public location of this yaml file.
Expand Down

0 comments on commit 7f8dfb8

Please sign in to comment.