-
Notifications
You must be signed in to change notification settings - Fork 9
116 lines (107 loc) · 4.6 KB
/
build-firmware.yml
File metadata and controls
116 lines (107 loc) · 4.6 KB
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
name: Build & Release Firmware
# Triggered when the upstream sync workflow
# pushes a tag here. Per the per-binary tag scheme in RELEASES.md:
#
# rx-v* → builds firmware/Receiver-ESP32-DevKit/ for ESP32
# tx-v* → builds firmware/Transmitter-IDF/ for ESP32-C3
# rxc3-v* → builds firmware/Receiver-ESP32-C3/ for ESP32-C3
#
# Only ONE binary is built per tag (matches the tag prefix). The result is
# attached to a GitHub Release on this public repo with notes generated
# from the tag annotation that was written on private.
on:
push:
tags:
- 'rx-v*'
- 'tx-v*'
- 'rxc3-v*'
jobs:
build:
name: Build firmware for ${{ github.ref_name }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # need full history so `git tag -l --format` reads annotation
- name: Identify target from tag
id: meta
run: |
TAG="${GITHUB_REF_NAME}"
case "${TAG}" in
rx-v*)
echo "kind=receiver" >> "$GITHUB_OUTPUT"
echo "path=firmware/Receiver-ESP32-DevKit" >> "$GITHUB_OUTPUT"
echo "target=esp32" >> "$GITHUB_OUTPUT"
echo "binary=tanksync_receiver.bin" >> "$GITHUB_OUTPUT"
echo "asset=tanksync-receiver-${TAG}.bin" >> "$GITHUB_OUTPUT"
;;
tx-v*)
echo "kind=transmitter" >> "$GITHUB_OUTPUT"
echo "path=firmware/Transmitter-IDF" >> "$GITHUB_OUTPUT"
echo "target=esp32c3" >> "$GITHUB_OUTPUT"
echo "binary=tanksync_transmitter.bin" >> "$GITHUB_OUTPUT"
echo "asset=tanksync-transmitter-${TAG}.bin" >> "$GITHUB_OUTPUT"
;;
rxc3-v*)
echo "kind=receiver-c3" >> "$GITHUB_OUTPUT"
echo "path=firmware/Receiver-ESP32-C3" >> "$GITHUB_OUTPUT"
echo "target=esp32c3" >> "$GITHUB_OUTPUT"
echo "binary=tanksync_receiver.bin" >> "$GITHUB_OUTPUT"
echo "asset=tanksync-receiver-c3-${TAG}.bin" >> "$GITHUB_OUTPUT"
;;
esac
- name: Build with ESP-IDF
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.4
target: ${{ steps.meta.outputs.target }}
path: ${{ steps.meta.outputs.path }}
- name: Rename binary for release
run: |
cp "${{ steps.meta.outputs.path }}/build/${{ steps.meta.outputs.binary }}" \
"${{ steps.meta.outputs.asset }}"
ls -la "${{ steps.meta.outputs.asset }}"
- name: Read tag annotation as release body
id: notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Read annotation via GitHub REST API instead of `git tag -l --format`.
# actions/checkout@v4 with fetch-depth:0 sometimes leaves annotated tags
# as lightweight refs locally, in which case %(contents) returns the
# commit subject (e.g. "sync(rx): rx-v2.8.6") instead of the annotated
# body. The REST API path always returns the true annotation message.
OBJ_SHA=$(gh api "repos/${GITHUB_REPOSITORY}/git/refs/tags/${GITHUB_REF_NAME}" --jq '.object.sha')
OBJ_TYPE=$(gh api "repos/${GITHUB_REPOSITORY}/git/refs/tags/${GITHUB_REF_NAME}" --jq '.object.type')
if [ "$OBJ_TYPE" = "tag" ]; then
BODY=$(gh api "repos/${GITHUB_REPOSITORY}/git/tags/${OBJ_SHA}" --jq '.message')
else
# Lightweight tag — fall back to the commit subject so we don't fail.
BODY=$(gh api "repos/${GITHUB_REPOSITORY}/git/commits/${OBJ_SHA}" --jq '.message')
fi
{
echo "body<<__END_OF_BODY__"
echo "$BODY"
echo ""
echo "---"
echo ""
echo "### Flashing"
echo ''
echo '```bash'
echo "esptool.py --chip ${{ steps.meta.outputs.target }} -b 460800 \\"
echo " write_flash 0x10000 ${{ steps.meta.outputs.asset }}"
echo '```'
echo ""
echo "Or use the [browser flasher](https://tanksync.smartghar.org/firmware) for a one-click install."
echo "__END_OF_BODY__"
} >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: ${{ steps.meta.outputs.asset }}
body: ${{ steps.notes.outputs.body }}
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}