-
Notifications
You must be signed in to change notification settings - Fork 2
160 lines (141 loc) · 4.85 KB
/
build.yml
File metadata and controls
160 lines (141 loc) · 4.85 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
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
name: TianShanOS Build
on:
push:
branches: [main, develop]
tags:
- 'v*' # 版本标签触发
paths-ignore:
- '**.md'
- 'docs/**'
- '.github/copilot-instructions.md'
pull_request:
branches: [main, develop]
paths-ignore:
- '**.md'
- 'docs/**'
workflow_dispatch: # 允许手动触发
env:
IDF_VERSION: v5.5
TARGET: esp32s3
jobs:
build:
name: Build ESP32-S3 Firmware
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # 完整历史用于版本号生成
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Cache ESP-IDF
uses: actions/cache@v4
id: cache-idf
with:
path: |
~/esp/esp-idf
~/.espressif
key: esp-idf-${{ env.IDF_VERSION }}-${{ runner.os }}
restore-keys: |
esp-idf-${{ env.IDF_VERSION }}-
- name: Install ESP-IDF
if: steps.cache-idf.outputs.cache-hit != 'true'
run: |
mkdir -p ~/esp
cd ~/esp
git clone -b ${{ env.IDF_VERSION }} --depth 1 --recursive https://github.com/espressif/esp-idf.git
cd esp-idf
./install.sh ${{ env.TARGET }}
- name: Setup ESP-IDF environment
run: |
source ~/esp/esp-idf/export.sh
echo "IDF_PATH=$IDF_PATH" >> $GITHUB_ENV
echo "$IDF_PATH/tools" >> $GITHUB_PATH
- name: Cache build directory
uses: actions/cache@v4
with:
path: build
key: build-${{ env.TARGET }}-${{ hashFiles('**/CMakeLists.txt', '**/Kconfig*', 'sdkconfig.defaults') }}
restore-keys: |
build-${{ env.TARGET }}-
- name: Set target
run: |
source ~/esp/esp-idf/export.sh
idf.py set-target ${{ env.TARGET }}
- name: Build firmware
run: |
source ~/esp/esp-idf/export.sh
# 使用 --fresh 确保版本号更新
rm -f build/CMakeCache.txt
idf.py build
- name: Get version info
id: version
run: |
if [ -f build/project_description.json ]; then
VERSION=$(grep -o '"project_version":[^,]*' build/project_description.json | cut -d'"' -f4)
fi
echo "version=${VERSION:-0.0.0}" >> $GITHUB_OUTPUT
echo "📦 Build version: ${VERSION:-0.0.0}"
- name: Print build size
run: |
source ~/esp/esp-idf/export.sh
idf.py size
- name: Upload firmware artifacts
uses: actions/upload-artifact@v4
with:
name: tianshanos-firmware-${{ steps.version.outputs.version || github.sha }}
path: |
build/*.bin
build/bootloader/bootloader.bin
build/partition_table/partition-table.bin
build/flasher_args.json
retention-days: 30
- name: Upload full build (for debugging)
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-debug-${{ github.sha }}
path: |
build/compile_commands.json
build/project_description.json
build/config/sdkconfig.h
retention-days: 7
# 编译成功后自动创建 Release:tag 推送 或 main 分支推送
release:
name: Create Release
needs: build
if: startsWith(github.ref, 'refs/tags/v') || (github.ref == 'refs/heads/main' && github.event_name == 'push')
runs-on: ubuntu-latest
permissions:
contents: write # 创建 Release 需要写权限
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: tianshanos-firmware-*
path: firmware
- name: Check if release already exists (main branch)
if: github.ref == 'refs/heads/main'
id: check
run: |
TAG="v${{ needs.build.outputs.version }}"
if gh release view "$TAG" 2>/dev/null; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "⏭️ Release $TAG already exists, skipping"
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Create Release
if: startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && steps.check.outputs.skip != 'true')
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || format('v{0}', needs.build.outputs.version) }}
name: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || format('v{0}', needs.build.outputs.version) }}
files: firmware/**/*.bin
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}