11name : Publish
22env :
33 DEVICE_NAME : air_test-1
4+
45on :
56 push :
67 branches :
78 - main
8- # workflow_dispatch:
9- # inputs:
10- # version:
11- # description: 'The version of the firmware to build'
12- # required: true
13- # release:
14- # types: [published]
9+ # Uncomment if needed:
10+ # workflow_dispatch:
11+ # inputs:
12+ # version:
13+ # description: 'The version of the firmware to build'
14+ # required: true
15+ # release:
16+ # types: [published]
1517
1618jobs :
1719 check-for-yaml :
2325 - name : Checkout code
2426 uses : actions/checkout@v3
2527 with :
26- fetch-depth : 2 # Fetch enough history to access the previous commit
28+ fetch-depth : 2 # So we can diff the previous commit
2729
2830 - name : Find .yaml Changes in Last PR Merge
2931 id : check
@@ -32,42 +34,86 @@ jobs:
3234 MERGE_COMMIT=$(git rev-parse HEAD)
3335
3436 if git diff --name-only $BASE_COMMIT $MERGE_COMMIT | grep -q '\.yaml$'; then
35- echo "YAML files changed"
3637 echo "yaml_changed=true" >> $GITHUB_OUTPUT
3738 else
38- echo "No YAML files changed"
3939 echo "yaml_changed=false" >> $GITHUB_OUTPUT
4040 fi
4141
42+ set-version :
43+ name : Set Version
44+ runs-on : ubuntu-latest
45+ needs : [check-for-yaml]
46+ if : needs.check-for-yaml.outputs.yaml_changed == 'true'
47+
48+ # Expose job-level outputs so other jobs can access them
49+ outputs :
50+ version : ${{ steps.read_version.outputs.version }}
51+ upload_url : ${{ steps.run-release-drafter.outputs.upload_url }}
52+ body : ${{ steps.run-release-drafter.outputs.body }}
53+ html_url : ${{ steps.run-release-drafter.outputs.html_url }}
54+
55+ steps :
56+ - name : Checkout code
57+ uses : actions/checkout@v3
58+
59+ - name : Read version from YAML file
60+ id : read_version
61+ run : |
62+ version=$(awk '/substitutions:/ {found=1} found && /version:/ {print $2; exit}' Integrations/ESPHome/Core.yaml | tr -d '"')
63+ echo "version=$version" >> $GITHUB_OUTPUT
64+ echo "Detected version: $version"
65+
66+ - name : Fetch Last Merged PR Body
67+ id : last_pr
68+ env :
69+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
70+ run : |
71+ PR_INFO=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
72+ "https://api.github.com/repos/${{ github.repository }}/pulls?state=closed&sort=updated&direction=desc&per_page=1")
73+ PR_BODY=$(echo "$PR_INFO" | jq -r '.[0].body')
74+ echo "$PR_BODY" > pr_body.txt
75+
76+ - name : 🚀 Run Release Drafter
77+ id : run-release-drafter
78+ uses : release-drafter/release-drafter@v6
79+ with :
80+ version : ${{ steps.read_version.outputs.version }}
81+ publish : true
82+ tag : ${{ steps.read_version.outputs.version }}
83+ name : Release ${{ steps.read_version.outputs.version }}
84+ env :
85+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
86+
4287 build-firmware :
43- name : Build And Release
88+ name : Build And Release (Firmware)
4489 uses : esphome/workflows/.github/workflows/build.yml@main
4590 needs :
4691 - check-for-yaml
92+ - set-version
4793 if : needs.check-for-yaml.outputs.yaml_changed == 'true'
4894 with :
4995 files : |
5096 Integrations/ESPHome/PLT-1.yaml
5197 esphome-version : stable
5298 combined-name : firmware
53- release-summary : ${{ github.event_name == 'release' && github.event.release.body || '' }}
54- release-url : ${{ github.event_name == 'release' && github.event.release.html_url || '' }}
55- release-version : ${{ (github.event_name == 'release' && github.event.release.tag_name) || (github.event_name == 'workflow_dispatch' && inputs.version) || '' }}
56-
99+ release-summary : ${{ needs.set-version.outputs.body }}
100+ release-version : ${{ needs.set-version.outputs.version }}
101+
57102 build-firmware-b :
58- name : Build And Release
103+ name : Build And Release (Firmware B)
59104 uses : esphome/workflows/.github/workflows/build.yml@main
60105 needs :
61106 - check-for-yaml
107+ - set-version
62108 if : needs.check-for-yaml.outputs.yaml_changed == 'true'
63109 with :
64110 files : |
65111 Integrations/ESPHome/PLT-1B.yaml
66112 esphome-version : stable
67113 combined-name : firmware-b
68- release-summary : ${{ github.event_name == 'release' && github.event.release. body || '' }}
69- release-url : ${{ github.event_name == 'release' && github.event.release. html_url || '' }}
70- release-version : ${{ (github.event_name == 'release' && github.event.release.tag_name) || (github.event_name == 'workflow_dispatch' && inputs. version) || '' }}
114+ release-summary : ${{ needs.set-version.outputs. body }}
115+ release-url : ${{ needs.set-version.outputs. html_url }}
116+ release-version : ${{ needs.set-version.outputs. version }}
71117
72118 build-site :
73119 name : Build Site
@@ -76,17 +122,20 @@ jobs:
76122 - check-for-yaml
77123 - build-firmware
78124 - build-firmware-b
125+ - set-version
79126 if : needs.check-for-yaml.outputs.yaml_changed == 'true'
80127 steps :
81128 - name : Checkout source code
82- 129+ uses : actions/checkout@v4
130+
83131 - name : Build
8413285133 with :
86134 source : ./static
87135 destination : ./output
136+
88137 - name : Upload
89- uses : actions/upload-artifact@v4.3.6
138+ uses : actions/upload-artifact@v4
90139 with :
91140 name : site
92141 path : output
@@ -98,95 +147,56 @@ jobs:
98147 - build-site
99148 - build-firmware
100149 - build-firmware-b
150+ - set-version
101151 if : needs.check-for-yaml.outputs.yaml_changed == 'true' && ${{ github.run_attempt == 1 }}
102152 permissions :
103153 contents : write
104154 pages : write
105155 id-token : write
106- environment :
107- name : github-pages
108- url : ${{ steps.deployment.outputs.page_url }}
109156 steps :
110157 - name : Checkout code
111158 uses : actions/checkout@v3
112159
113- # Get the last merged PR's body for the release notes
114- - name : Fetch Last Merged PR Body
115- id : last_pr
116- env :
117- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
118- run : |
119- PR_INFO=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
120- "https://api.github.com/repos/${{ github.repository }}/pulls?state=closed&sort=updated&direction=desc&per_page=1")
121- PR_BODY=$(echo "$PR_INFO" | jq -r '.[0].body')
122- echo "$PR_BODY" > pr_body.txt # Save to a file
123-
124- - name : Set PR Body as Environment Variable
125- run : |
126- PR_BODY=$(<pr_body.txt)
127- echo "PR_BODY<<EOF" >> $GITHUB_ENV
128- echo "$PR_BODY" >> $GITHUB_ENV
129- echo "EOF" >> $GITHUB_ENV
130-
131- - name : Read version from YAML file
132- id : read_version
133- run : |
134- version=$(awk '/substitutions:/ {found=1} found && /version:/ {print $2; exit}' Integrations/ESPHome/Core.yaml | tr -d '"')
135- echo "project_version=$version" >> $GITHUB_ENV
136- echo "Detected version: $version"
137- shell : bash
138-
139- - name : 🚀 Run Release Drafter
140- id : run-release-drafter
141- uses : release-drafter/release-drafter@v6
142- with :
143- version : ${{ env.project_version }}
144- publish : true
145- tag : ${{ env.project_version }}
146- name : Release ${{ env.project_version }}
147- env :
148- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
149-
150-
151- # 3) Download artifacts from a previous build job
152- - name : Download Firmware
153- uses : actions/download-artifact@v4
160+ # 1) Download Firmware
161+ - uses : actions/download-artifact@v4
154162 with :
155163 name : firmware
156164 path : firmware
157165
158- - name : Download Firmware-B
159- uses : actions/download-artifact@v4
166+ # 2) Download Firmware-B
167+ - uses : actions/download-artifact@v4
160168 with :
161169 name : firmware-b
162170 path : firmware-b
163171
164- # 4 ) Zip up each firmware folder
172+ # 3 ) Zip them up
165173 - name : Zip firmware
166174 run : |
167175 zip -r firmware.zip firmware
168176 zip -r firmware-b.zip firmware-b
169177
170- # 5 ) Upload firmware.zip as an asset
178+ # 4 ) Upload firmware.zip as an asset
171179 - name : Upload firmware.zip
172180 id : upload-firmware
173181 uses : actions/upload-release-asset@v1
174182 env :
175183 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
176184 with :
177- upload_url : ${{ steps.run-release-drafter.outputs.upload_url }}
185+ # Use the job-level output from set-version:
186+ upload_url : ${{ needs.set-version.outputs.upload_url }}
178187 asset_path : firmware.zip
179188 asset_name : firmware.zip
180189 asset_content_type : application/zip
181190
182- # 6 ) Upload firmware-b.zip as another asset
191+ # 5 ) Upload firmware-b.zip
183192 - name : Upload firmware-b.zip
184193 id : upload-firmware-b
185194 uses : actions/upload-release-asset@v1
186195 env :
187196 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
188197 with :
189- upload_url : ${{ steps.run-release-drafter.outputs.upload_url }}
198+ # Use the job-level output from set-version:
199+ upload_url : ${{ needs.set-version.outputs.upload_url }}
190200 asset_path : firmware-b.zip
191201 asset_name : firmware-b.zip
192202 asset_content_type : application/zip
@@ -195,24 +205,25 @@ jobs:
195205 run : |-
196206 mkdir -p output/firmware
197207 cp -r firmware/${{ needs.build-firmware.outputs.version }}/* output/firmware/
208+
198209 - name : Copy firmware and manifest
199210 run : |-
200211 mkdir -p output/firmware-b
201212 cp -r firmware-b/${{ needs.build-firmware-b.outputs.version }}/* output/firmware-b/
202213
203- - uses : actions/download-artifact@v4.1.8
214+ - uses : actions/download-artifact@v4
204215 with :
205216 name : site
206217 path : output
207218
208- - uses : actions/upload-pages-artifact@v3.0.1
219+ - uses : actions/upload-pages-artifact@v3
209220 with :
210221 path : output
211222 retention-days : 1
212223
213224 - name : Setup Pages
214- uses : actions/configure-pages@v5.0.0
225+ uses : actions/configure-pages@v5
215226
216227 - name : Deploy to GitHub Pages
217228 id : deployment
218- uses : actions/deploy-pages@v4.0.5
229+ uses : actions/deploy-pages@v4
0 commit comments