-
Notifications
You must be signed in to change notification settings - Fork 11
205 lines (175 loc) · 6.64 KB
/
build.yaml
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: ESPHome Build and Commit Manifest
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
jobs:
check-tag:
runs-on: ubuntu-latest
outputs:
tag_on_main: ${{ steps.check_tag.outputs.tag_on_main }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if tag is on main branch
id: check_tag
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
TAG_COMMIT=$(git rev-list -n 1 $TAG_NAME)
MAIN_COMMIT=$(git rev-parse origin/main)
if git merge-base --is-ancestor $TAG_COMMIT $MAIN_COMMIT; then
echo "tag_on_main=true" >> $GITHUB_OUTPUT
echo "Tag is on main branch"
else
echo "tag_on_main=false" >> $GITHUB_OUTPUT
echo "Tag is not on main branch"
fi
build:
needs: check-tag
if: needs.check-tag.outputs.tag_on_main == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
target: [esp32s2, esp32]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Get version from git tag
id: get_version
run: |
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create empty secrets file
run: |
touch firmware/secrets.yaml
touch firmware/conf.d/secrets.yaml
- name: Set git sha
run: echo "RELEASE_SUMMARY=$(git log -1 --pretty=%B)" >> $GITHUB_ENV
- name: Build ESPHome firmware
uses: esphome/[email protected]
with:
yaml-file: ${{ github.workspace }}/firmware/config-${{ matrix.target }}.yaml
release-summary: ${{ env.RELEASE_SUMMARY }}
#release-url: "https://raw.githubusercontent.com/spuder/OpenSpool/main/artifacts/openspool-${{ matrix.target }}/manifest.json"
complete-manifest: false
- name: ls
run: |
ls -la
ls openspool-${{ matrix.target }}/* || true
- name: Generate md5 checksum
run: |
mkdir -p artifacts/openspool-${{ matrix.target }}
mv -f openspool-${{ matrix.target }}/* artifacts/openspool-${{ matrix.target }}/
ls -la artifacts/openspool-${{ matrix.target }}
for file in artifacts/openspool-${{ matrix.target }}/*.bin; do
md5sum "$file" | awk '{print $1}' > "${file}.md5"
md5_length=$(wc -c < "${file}.md5")
if [ "$md5_length" -ne 33 ]; then
echo "MD5 generation failed for $file (length: $md5_length)"
exit 1
fi
ls -la artifacts/openspool-${{ matrix.target }}
done
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: openspool-${{ matrix.target }}
path: artifacts/openspool-${{ matrix.target }}
retention-days: 5
if-no-files-found: error
combine-manifests:
needs: [check-tag, build]
if: needs.check-tag.outputs.tag_on_main == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Get version from git tag
id: get_version
run: |
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: downloaded-artifacts
- name: Clean artifacts
run: |
rm -rf artifacts/manifest.json
rm -rf artfacts/openspool-*
cp downloaded-artifacts/manifest.json artifacts/
cp downloaded-artifacts/openspool-esp32/*.bin artifacts/
cp downloaded-artifacts/openspool-esp32/*.md5 artifacts/
cp downloaded-artifacts/openspool-esp32s2/*.bin artifacts/
cp downloaded-artifacts/openspool-esp32s2/*.md5 artifacts/
ls -al artifacts
- name: Combine manifests
run: |
python3 - <<EOF
import json
import sys
import os
print("Contents of downloaded-artifacts:")
for root, dirs, files in os.walk("downloaded-artifacts"):
for file in files:
print(os.path.join(root, file))
version = "${{ env.VERSION }}"
combined_manifest = {
"name": "OpenSpool",
"version": version,
"builds": [],
"new_install_prompt_erase": True
}
for target in ['esp32s2', 'esp32']:
try:
with open(f'downloaded-artifacts/openspool-{target}/manifest.json', 'r') as f:
manifest = json.load(f)
# Add the entire manifest to the builds array
combined_manifest['builds'].append(manifest)
except FileNotFoundError:
print(f"Warning: manifest for {target} not found")
except json.JSONDecodeError:
print(f"Error: Invalid JSON in manifest for {target}")
with open('artifacts/manifest.json', 'w') as f:
json.dump(combined_manifest, f, indent=2)
print(f"Combined manifest created with version: {version}")
print("Combined manifest content:")
print(json.dumps(combined_manifest, indent=2))
EOF
- name: Update manifest
run: |
# Stash all changes
git stash push -m "Stash before switching to main"
# Switch to the main branch
git checkout main
# Pull latest changes from main
git pull origin main
# Apply the stash
git stash apply
# Set Git username and email
git config user.name "GitHub Actions"
git config user.email "[email protected]"
# Add all changes in the artifacts/ folder
git add artifacts/
git diff --staged || true
# Commit changes if there are any
if git diff --staged --quiet; then
echo "No changes to commit"
exit 1
else
git commit -m "Update artifacts after stash"
# Push changes to main
git push origin main
fi
# Show final status
git status