Skip to content

Commit 7f8dfb8

Browse files
committed
new ci/cd
1 parent e596a60 commit 7f8dfb8

10 files changed

+312
-8
lines changed

.github/workflows/build.yaml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
name: Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
files:
7+
description: Newline separated list of files to build
8+
required: true
9+
type: string
10+
esphome-version:
11+
description: Version of ESPHome to build with
12+
required: false
13+
type: string
14+
default: latest
15+
release-summary:
16+
description: Summary of the release
17+
required: false
18+
type: string
19+
default: ""
20+
release-url:
21+
description: URL to the release notes
22+
required: false
23+
type: string
24+
default: ""
25+
release-version:
26+
description: Version of the release
27+
required: false
28+
type: string
29+
default: ""
30+
combined-name:
31+
description: Combine all files into a single manifest under this name
32+
required: false
33+
type: string
34+
default: ""
35+
36+
outputs:
37+
version:
38+
description: Version of the firmware generated
39+
value: ${{ jobs.prepare.outputs.version }}
40+
41+
jobs:
42+
prepare:
43+
name: Prepare
44+
runs-on: ubuntu-latest
45+
outputs:
46+
files: ${{ steps.files-array.outputs.files }}
47+
version: ${{ steps.version.outputs.version }}
48+
artifact-prefix: ${{ steps.artifact-name.outputs.artifact-prefix }}
49+
steps:
50+
- name: Split files input into JSON array
51+
id: files-array
52+
run: |
53+
files=$(echo "${{ inputs.files }}" | jq -RcSn '[inputs | select(length>0)]')
54+
echo files=$files >> $GITHUB_OUTPUT
55+
- name: Generate version
56+
id: version
57+
run: |
58+
if [ -n "${{ inputs.release-version }}" ]; then
59+
version=${{ inputs.release-version }}
60+
else
61+
version=dev-$(date +'%Y%m%d-%H%M')
62+
fi
63+
64+
echo version=$version >> $GITHUB_OUTPUT
65+
- name: Generated random artifact prefix
66+
id: artifact-name
67+
run: |
68+
artifact_prefix=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 16; echo)
69+
echo artifact-prefix=$artifact_prefix >> $GITHUB_OUTPUT
70+
71+
build:
72+
name: ${{ matrix.file }}
73+
needs: [prepare]
74+
runs-on: ubuntu-latest
75+
strategy:
76+
fail-fast: false
77+
max-parallel: 3
78+
matrix:
79+
file: ${{ fromJson(needs.prepare.outputs.files) }}
80+
steps:
81+
- name: Checkout code
82+
uses: actions/[email protected]
83+
- name: Replace project version
84+
run: |
85+
sed -i "s/version: dev/version: ${{ needs.prepare.outputs.version }}/g" ${{ matrix.file }}
86+
- name: Build Firmware
87+
uses: esphome/[email protected]
88+
id: esphome-build
89+
with:
90+
yaml-file: ${{ matrix.file }}
91+
version: ${{ inputs.esphome-version }}
92+
complete-manifest: true
93+
release-summary: ${{ inputs.release-summary }}
94+
release-url: ${{ inputs.release-url }}
95+
- name: Move files for versioning
96+
run: |
97+
mkdir -p output/${{ needs.prepare.outputs.version }}
98+
mv ${{ steps.esphome-build.outputs.name }}/* output/${{ needs.prepare.outputs.version }}/
99+
- name: Upload artifact
100+
uses: actions/[email protected]
101+
with:
102+
name: ${{ inputs.combined-name != '' && format('{0}-{1}', needs.prepare.outputs.artifact-prefix, steps.esphome-build.outputs.name) || steps.esphome-build.outputs.original-name }}
103+
path: output
104+
105+
combine:
106+
name: Combine manifests
107+
needs:
108+
- prepare
109+
- build
110+
runs-on: ubuntu-latest
111+
if: inputs.combined-name != ''
112+
steps:
113+
- name: Download artifacts
114+
uses: actions/[email protected]
115+
with:
116+
path: files
117+
pattern: ${{ needs.prepare.outputs.artifact-prefix }}-*
118+
119+
- name: Get artifact names
120+
id: artifacts
121+
run: |
122+
artifacts=$(ls --format=single-column files)
123+
echo "artifacts<<EOF" >> $GITHUB_OUTPUT
124+
echo "$artifacts" >> $GITHUB_OUTPUT
125+
echo "EOF" >> $GITHUB_OUTPUT
126+
127+
- name: Delete prefixed artifacts
128+
uses: geekyeggo/[email protected]
129+
with:
130+
name: ${{ steps.artifacts.outputs.artifacts }}
131+
132+
- name: Combine all parts into a single manifest
133+
run: |
134+
version="${{ needs.prepare.outputs.version }}"
135+
mkdir -p "output/$version"
136+
pushd files
137+
for device in *; do
138+
pushd $device
139+
pushd $version
140+
cp * "../../../output/$version/"
141+
cp manifest.json ../../../output/$version/manifest-`ls *.elf |cut -d. -f1`.json
142+
popd
143+
popd
144+
done
145+
popd
146+
jq -s '(.[0] | del(.builds)) + {"builds": (reduce .[].builds as $b ([]; . + $b))}' files/*/$version/manifest.json > output/$version/manifest.json
147+
148+
- name: Upload artifact
149+
uses: actions/[email protected]
150+
with:
151+
name: ${{ inputs.combined-name }}
152+
path: output
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Publish Firmware
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'The version of the firmware to build'
8+
required: true
9+
release:
10+
types: [published]
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
build-firmware:
17+
name: Build Firmware
18+
uses: ./.github/workflows/build.yaml
19+
with:
20+
#### Modify below here to match your project ####
21+
files: |
22+
tagtuner-D1-custom1.factory.yaml
23+
tagtuner-atom-grove-ble.factory.yaml
24+
tagtuner-for-tagreader.factory.yaml
25+
esphome-version: stable
26+
combined-name: tagtuner-firmware
27+
#### Modify above here to match your project ####
28+
29+
release-summary: ${{ github.event.release.body }}
30+
release-url: ${{ github.event.release.html_url }}
31+
release-version: ${{ (github.event_name == 'release' && github.event.release.tag_name) || (github.event_name == 'workflow_dispatch' && inputs.version) || '' }}
32+
33+
upload-to-release:
34+
name: Upload to Release
35+
uses: ./.github/workflows/upload-to-gh-release.yml
36+
needs:
37+
- build-firmware
38+
with:
39+
version: ${{ (github.event_name == 'release' && github.event.release.tag_name) || (github.event_name == 'workflow_dispatch' && inputs.version) || '' }}

.github/workflows/publish-pages.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'static/**'
9+
- '.github/workflows/publish-pages.yml'
10+
workflow_run:
11+
workflows:
12+
- Publish Firmware
13+
types:
14+
- completed
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
build:
22+
name: Build
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout source code
26+
uses: actions/[email protected]
27+
28+
- run: mkdir -p output/firmware
29+
30+
- name: Build
31+
uses: actions/[email protected]
32+
with:
33+
source: ./static
34+
destination: ./output
35+
36+
- name: Fetch firmware files
37+
uses: robinraju/[email protected]
38+
with:
39+
latest: true
40+
fileName: '*'
41+
out-file-path: output/firmware
42+
43+
- name: Upload artifact
44+
uses: actions/[email protected]
45+
with:
46+
path: output
47+
retention-days: 1
48+
49+
publish:
50+
if: github.event_name != 'pull_request'
51+
name: Publish
52+
runs-on: ubuntu-latest
53+
needs:
54+
- build
55+
permissions:
56+
pages: write
57+
id-token: write
58+
environment:
59+
name: github-pages
60+
url: ${{ steps.deployment.outputs.page_url }}
61+
steps:
62+
- name: Setup Pages
63+
uses: actions/[email protected]
64+
65+
- name: Deploy to GitHub Pages
66+
id: deployment
67+
uses: actions/[email protected]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Upload firmware to GitHub Release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
description: Version of the release
8+
required: true
9+
type: string
10+
11+
jobs:
12+
upload:
13+
name: Upload
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
steps:
18+
- name: Download Artifact
19+
uses: actions/[email protected]
20+
with:
21+
path: files
22+
23+
- name: Copy files to output
24+
run: |-
25+
shopt -s nullglob
26+
mkdir output
27+
version="${{ inputs.version }}"
28+
pushd files
29+
for device in *; do
30+
pushd $device
31+
pushd $version
32+
cp manifest*.json ../../../output/
33+
for bin in *.{bin,elf}; do
34+
md5sum $bin | head -c 32 > ../../../output/$bin.md5
35+
cp $bin ../../../output/
36+
done
37+
popd
38+
popd
39+
done
40+
popd
41+
42+
- name: Upload files to release
43+
uses: softprops/[email protected]
44+
with:
45+
files: output/*
46+
tag_name: ${{ inputs.version }}

static/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Check out also the [TagTuner on HA Voice PE version](https://github.com/luka6000
3636
You can use the button below to install the pre-built firmware directly to your device via USB from the browser. \
3737
This works for ESP32 Atom and ESP8266 tagreader.
3838

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

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

tagtuner-D1-custom1.factory.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These substitutions allow the end user to override certain values
22
substitutions:
3-
name: "tagtuner"
3+
name: "tagtuner-d1"
44
friendly_name: "TagTuner"
55

66
packages:
@@ -20,7 +20,7 @@ esphome:
2020
name_add_mac_suffix: true
2121

2222
project:
23-
name: LukaGra.TagTuner
23+
name: LukaGra.TagTuner-D1
2424
version: dev
2525

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

tagtuner-atom-grove-ble.factory.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These substitutions allow the end user to override certain values
22
substitutions:
3-
name: "tagtuner"
3+
name: "tagtuner-atom"
44
friendly_name: "TagTuner"
55

66
packages:
@@ -20,7 +20,7 @@ esphome:
2020
name_add_mac_suffix: true
2121

2222
project:
23-
name: LukaGra.TagTuner
23+
name: LukaGra.TagTuner-Atom
2424
version: dev
2525

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

tagtuner-for-tagreader.factory.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ esphome:
99
name_add_mac_suffix: true
1010

1111
project:
12-
name: LukaGra.TagTuner
12+
name: LukaGra.TagTuner-8266
1313
version: dev
1414

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

tagtuner-for-tagreader.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These substitutions allow the end user to override certain values
22
substitutions:
3-
name: "tagtuner"
3+
name: "tagtuner-for-tagreader"
44
friendly_name: "TagTuner"
55
d1_mini: d1_mini
66
buzpin: D7

tagtuner-on-ha-voice-pe.factory.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ esphome:
2929
name_add_mac_suffix: true
3030

3131
project:
32-
name: LukaGra.TagTuner on Home Assistant Voice PE
32+
name: LukaGra.TagTuner-on-Home-Assistant-Voice-PE
3333
version: dev
3434

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

0 commit comments

Comments
 (0)