-
-
Notifications
You must be signed in to change notification settings - Fork 26
191 lines (164 loc) · 6.31 KB
/
build_fw.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
190
191
name: Build, release, push firmware
permissions:
contents: write
on:
workflow_dispatch:
push:
tags:
- "*"
jobs:
build_release_push:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
with:
submodules: "recursive"
fetch-depth: 0
- name: Get Release tag
id: get_tag
shell: bash
run: |
value=${GITHUB_REF#refs/tags/}
echo "tag=$value" >> $GITHUB_OUTPUT
- name: Display src/version.h before update
run: cat src/version.h
- name: Update version in source code
run: |
sed -i 's/#define VERSION.*/#define VERSION "${{ steps.get_tag.outputs.tag }}"/' src/version.h
- name: Display src/version.h after update
run: cat src/version.h
- name: Install Node JS
uses: actions/setup-node@v3
with:
node-version: 18
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install PlatformIO Core
run: pip install --upgrade platformio==6.1.15
- name: Build PlatformIO Project
run: pio run
- name: Get last commit message
id: get_commit_message
run: |
currentTag=${{ steps.get_tag.outputs.tag }}
badgeText="![GitHub Downloads](https://img.shields.io/github/downloads/xyzroe/XZG/${currentTag}/total)"
printf -v badgeTextWithNewlines "%s\n\n" "$badgeText"
commitMessage=$(git log -1 --pretty=%B | tail -n +2)
fullCommitMessage="${badgeTextWithNewlines}${commitMessage}"
echo "releaseMessage<<EOF" >> $GITHUB_ENV
printf "%s\n" "$fullCommitMessage" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "commitMessage<<EOF" >> $GITHUB_ENV
printf "%s\n" "$commitMessage" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
env:
GITHUB_REF: ${{ github.ref }}
- name: Create manifest.json for ESP Web Tools
run: |
cat << EOF > manifest.json
{
"name": "XZG Firmware",
"version": "${{ steps.get_tag.outputs.tag }}",
"builds": [
{
"chipFamily": "ESP32",
"improv": false,
"parts": [
{
"path": "https://raw.githubusercontent.com/${{ github.repository }}/releases/${{ steps.get_tag.outputs.tag }}/XZG_${{ steps.get_tag.outputs.tag }}.full.bin",
"offset": 0
}
]
}
]
}
EOF
echo "Manifest file created."
- name: Get the latest commit SHA for the whole project
id: get_fw_commit_sha
run: echo "::set-output name=fw_commit_sha::$(git log -n 1 --pretty=format:%h)"
- name: Get the latest commit SHA in src/websrc
id: get_fs_commit_sha
run: echo "::set-output name=fs_commit_sha::$(git log -n 1 --pretty=format:%h -- src/websrc)"
- name: Create xzg.json for firmware update
run: |
cat << EOF > xzg.json
{
"name": "XZG Firmware",
"version": "${{ steps.get_tag.outputs.tag }}",
"fw_sha": "${{ steps.get_fw_commit_sha.outputs.fw_commit_sha }}",
"fs_sha": "${{ steps.get_fs_commit_sha.outputs.fs_commit_sha }}"
}
EOF
echo "xzg.json file created."
- name: Display xzg.json
run: cat xzg.json
- name: Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: false
name: "${{ steps.get_tag.outputs.tag }}"
body: ${{ env.releaseMessage }}
files: |
bin/XZG_${{ steps.get_tag.outputs.tag }}.ota.bin
bin/XZG_${{ steps.get_tag.outputs.tag }}.full.bin
bin/XZG_${{ steps.get_tag.outputs.tag }}.fs.bin
- name: Checkout releases branch
uses: actions/checkout@v3
with:
ref: releases
path: releases
- name: Copy files to releases directory
run: |
mkdir -p releases/${{ steps.get_tag.outputs.tag }}
cp ./bin/XZG_${{ steps.get_tag.outputs.tag }}.full.bin releases/${{ steps.get_tag.outputs.tag }}/
cp manifest.json releases/${{ steps.get_tag.outputs.tag }}/
echo "Files copied to releases directory."
- name: Prepare latest release directory
run: |
if [ -d releases/latest ]; then
rm -rf releases/latest
fi
mkdir -p releases/latest
- name: Copy file to latest release directory
run: |
cp xzg.json releases/latest/
# cp ./bin/XZG_${{ steps.get_tag.outputs.tag }}.ota.bin releases/latest/XZG.ota.bin
# cp ./bin/XZG_${{ steps.get_tag.outputs.tag }}.fs.bin releases/latest/XZG.fs.bin
echo "File copied to latest release directory."
- name: Commit and push files to releases branch
run: |
cd releases
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
if [[ -n $(git status --porcelain) ]]; then
git add .
git commit -m "${{ steps.get_tag.outputs.tag }}"
git push origin releases
else
echo "No changes to commit"
fi
- name: Send Telegram Notification about release
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
format: markdown
message: |
${{ env.commitMessage }}
[${{ steps.get_tag.outputs.tag }}](https://github.com/${{ github.repository }}/releases/tag/${{ steps.get_tag.outputs.tag }})
- name: Send Discord Notification about release
run: |
json_payload=$(jq -n --arg content "https://github.com/${{ github.repository }}/releases/tag/${{ steps.get_tag.outputs.tag }}" '{content: $content}')
curl -H "Content-Type: application/json" \
-d "$json_payload" \
${{ secrets.DISCORD_WEBHOOK }}