Skip to content

Commit aeb0ba8

Browse files
committed
ci: support multiple variants per board
1 parent ef4bdd7 commit aeb0ba8

File tree

2 files changed

+223
-119
lines changed

2 files changed

+223
-119
lines changed

.github/workflows/build.yml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ permissions:
1414

1515
jobs:
1616
prepare:
17-
name: Determine boards to build
17+
name: Determine variants to build
1818
runs-on: ubuntu-latest
1919
outputs:
20-
boards: ${{ steps.select.outputs.boards }}
20+
variants: ${{ steps.select.outputs.variants }}
2121
steps:
2222
- name: Checkout
2323
uses: actions/checkout@v4
@@ -28,30 +28,30 @@ jobs:
2828
run: sudo apt-get update && sudo apt-get install -y jq
2929

3030
- id: list
31-
name: Get all board list
31+
name: Get all variant list
3232
run: |
33-
echo "all_boards=$(python scripts/release.py --list-boards --json)" >> $GITHUB_OUTPUT
33+
echo "all_variants=$(python scripts/release.py --list-boards --json)" >> $GITHUB_OUTPUT
3434
3535
- id: select
36-
name: Select boards based on changes
36+
name: Select variants based on changes
3737
env:
38-
ALL_BOARDS: ${{ steps.list.outputs.all_boards }}
38+
ALL_VARIANTS: ${{ steps.list.outputs.all_variants }}
3939
run: |
4040
EVENT_NAME="${{ github.event_name }}"
4141
42-
# For push to main branch, build all boards
42+
# push main 分支,编译全部变体
4343
if [[ "$EVENT_NAME" == "push" ]]; then
44-
echo "boards=$ALL_BOARDS" >> $GITHUB_OUTPUT
44+
echo "variants=$ALL_VARIANTS" >> $GITHUB_OUTPUT
4545
exit 0
4646
fi
4747
48-
# For pull_request
48+
# pull_request 场景
4949
BASE_SHA="${{ github.event.pull_request.base.sha }}"
5050
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
5151
echo "Base: $BASE_SHA, Head: $HEAD_SHA"
5252
5353
CHANGED=$(git diff --name-only $BASE_SHA $HEAD_SHA || true)
54-
echo "Changed files:\n$CHANGED"
54+
echo -e "Changed files:\n$CHANGED"
5555
5656
NEED_ALL=0
5757
declare -A AFFECTED
@@ -67,40 +67,41 @@ jobs:
6767
done <<< "$CHANGED"
6868
6969
if [[ "$NEED_ALL" -eq 1 ]]; then
70-
echo "boards=$ALL_BOARDS" >> $GITHUB_OUTPUT
70+
echo "variants=$ALL_VARIANTS" >> $GITHUB_OUTPUT
7171
else
7272
if [[ ${#AFFECTED[@]} -eq 0 ]]; then
73-
echo "boards=[]" >> $GITHUB_OUTPUT
73+
echo "variants=[]" >> $GITHUB_OUTPUT
7474
else
75-
JSON=$(printf '%s\n' "${!AFFECTED[@]}" | sort -u | jq -R -s -c 'split("\n")[:-1]')
76-
echo "boards=$JSON" >> $GITHUB_OUTPUT
75+
BOARDS_JSON=$(printf '%s\n' "${!AFFECTED[@]}" | sort -u | jq -R -s -c 'split("\n")[:-1]')
76+
FILTERED=$(echo "$ALL_VARIANTS" | jq -c --argjson boards "$BOARDS_JSON" 'map(select(.board as $b | $boards | index($b)))')
77+
echo "variants=$FILTERED" >> $GITHUB_OUTPUT
7778
fi
7879
fi
7980
8081
build:
81-
name: Build ${{ matrix.board }}
82+
name: Build ${{ matrix.name }}
8283
needs: prepare
83-
if: ${{ needs.prepare.outputs.boards != '[]' }}
84+
if: ${{ needs.prepare.outputs.variants != '[]' }}
8485
strategy:
85-
fail-fast: false # 单个 board 失败不影响其它 board
86+
fail-fast: false # 单个变体失败不影响其它变体
8687
matrix:
87-
board: ${{ fromJson(needs.prepare.outputs.boards) }}
88+
include: ${{ fromJson(needs.prepare.outputs.variants) }}
8889
runs-on: ubuntu-latest
8990
container:
9091
image: espressif/idf:release-v5.4
9192
steps:
9293
- name: Checkout
9394
uses: actions/checkout@v4
9495

95-
- name: Build current board
96+
- name: Build current variant
9697
shell: bash
9798
run: |
9899
source $IDF_PATH/export.sh
99-
python scripts/release.py ${{ matrix.board }}
100+
python scripts/release.py ${{ matrix.board }} --name ${{ matrix.name }}
100101
101102
- name: Upload artifacts
102103
uses: actions/upload-artifact@v4
103104
with:
104-
name: xiaozhi_${{ matrix.board }}_${{ github.sha }}.bin
105+
name: xiaozhi_${{ matrix.name }}_${{ github.sha }}.bin
105106
path: build/merged-binary.bin
106-
if-no-files-found: error
107+
if-no-files-found: error

0 commit comments

Comments
 (0)