-
Notifications
You must be signed in to change notification settings - Fork 2
142 lines (125 loc) · 5.08 KB
/
build.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
name: Build
env:
DEVICE_NAME: mtr-1
RELEASE_URL: ${{ github.server_url }}/${{ github.repository }}/releases/latest
on:
push:
branches:
- main
jobs:
build:
name: Build And Release
runs-on: ubuntu-latest
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
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
prep:
name: Consolidate firmwares
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
path: output
- run: cp -R static/* output/
- uses: actions/[email protected]
with:
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
runs-on: ubuntu-latest
needs: prep
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Deploy to GitHub Pages
id: deployment
uses: actions/[email protected]