-
Notifications
You must be signed in to change notification settings - Fork 1
189 lines (173 loc) · 6.23 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Publish
on:
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'The version of the firmware to build'
required: true
release:
types: [published]
jobs:
check-for-yaml:
name: Check for YAML Changes
runs-on: ubuntu-latest
outputs:
yaml_changed: ${{ steps.check.outputs.yaml_changed }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2 # Fetch enough history to access the previous commit
- name: Find .yaml Changes in Last PR Merge
id: check
run: |
# Get the commit hash of the first parent (pre-merge) and the merge commit
BASE_COMMIT=$(git rev-parse HEAD^1)
MERGE_COMMIT=$(git rev-parse HEAD)
# Check if there were any .yaml file changes between the pre-merge and merge commits
if git diff --name-only $BASE_COMMIT $MERGE_COMMIT | grep -q '\.yaml$'; then
echo "YAML files changed"
echo "::set-output name=yaml_changed::true"
else
echo "No YAML files changed"
echo "::set-output name=yaml_changed::false"
fi
read-version:
name: Read Version from YAML
runs-on: ubuntu-latest
needs: check-for-yaml
if: needs.check-for-yaml.outputs.yaml_changed == 'true'
outputs:
project_version: ${{ steps.read_version.outputs.project_version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Read version from YAML file
id: read_version
run: |
version=$(awk '/substitutions:/ {found=1} found && /version:/ {print $2; exit}' Integrations/ESPHome/Core.yaml | tr -d '"')
echo "project_version=$version" >> $GITHUB_ENV
shell: bash
build-firmware:
name: Build And Release
uses: esphome/workflows/.github/workflows/build.yml@main
needs:
- check-for-yaml
- read-version
if: needs.check-for-yaml.outputs.yaml_changed == 'true'
with:
files: |
Integrations/ESPHome/PLT-1.yaml
esphome-version: stable
combined-name: firmware
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) || '' }}
build-firmware-b:
name: Build And Release
uses: esphome/workflows/.github/workflows/build.yml@main
needs:
- check-for-yaml
- read-version
if: needs.check-for-yaml.outputs.yaml_changed == 'true'
with:
files: |
Integrations/ESPHome/PLT-1B.yaml
esphome-version: stable
combined-name: firmware-b
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) || '' }}
build-site:
name: Build Site
runs-on: ubuntu-latest
needs:
- check-for-yaml
- read-version
- build-firmware
- build-firmware-b
if: needs.check-for-yaml.outputs.yaml_changed == 'true'
steps:
- name: Checkout source code
uses: actions/[email protected]
- name: Build
uses: actions/[email protected]
with:
source: ./static
destination: ./output
- name: Upload
uses: actions/[email protected]
with:
name: site
path: output
publish:
name: Publish to GitHub Pages and Create Release
runs-on: ubuntu-latest
needs:
- build-site
- build-firmware
- build-firmware-b
if: needs.check-for-yaml.outputs.yaml_changed == 'true' && ${{ github.run_attempt == 1 }}
permissions:
contents: write
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/[email protected]
with:
name: firmware
path: ./consolidated_artifacts/firmware
- uses: actions/[email protected]
with:
name: firmware-b
path: ./consolidated_artifacts/firmware-b
# Get the last merged PR's body for the release notes
- name: Fetch Last Merged PR Body
id: last_pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_INFO=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/pulls?state=closed&sort=updated&direction=desc&per_page=1")
PR_BODY=$(echo "$PR_INFO" | jq -r '.[0].body')
echo "::set-output name=body::$PR_BODY"
# Create GitHub Release using the last PR's body
- name: Create Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: "${{ needs.read-version.outputs.project_version }}"
release_name: "Firmware Release ${{ needs.read-version.outputs.project_version }}"
body: "${{ steps.last_pr.outputs.body }}"
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Upload each file in firmware folder
- name: Upload Firmware Files to Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
for file in $(find ./consolidated_artifacts -type f); do
echo "Uploading $(basename "$file")"
gh release upload "${{ steps.create_release.outputs.upload_url }}" "$file" --clobber --repo ${{ github.repository }}
done
- uses: actions/[email protected]
with:
name: site
path: output
- uses: actions/[email protected]
with:
path: output
retention-days: 1
- name: Setup Pages
uses: actions/[email protected]
- name: Deploy to GitHub Pages
id: deployment
uses: actions/[email protected]