-
Notifications
You must be signed in to change notification settings - Fork 41
130 lines (126 loc) · 4.57 KB
/
build_binaries.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
on:
push:
branches:
- "master"
pull_request:
branches:
- "master"
workflow_dispatch:
inputs:
deploy-pages:
type: boolean
description: Deploy pages
default: false
jobs:
get-envs:
name: Get environments
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install PlatformIO
run: pip install platformio
- name: Get default environments
id: envs
run: |
json=$(pio project config --json-output)
echo "environments=$( echo $json | jq -cr '[.. | arrays | select(.[0] | tostring | startswith("env:")) | .[0][4:]] | unique' )" >> $GITHUB_OUTPUT
echo "web_flasher_names=$( echo $json | jq -cr '[.. | arrays | select(.[0] == "custom_web_flasher_name") | .[1]] | unique' )" >> $GITHUB_OUTPUT
echo "tag=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/tags" | jq -r '.[0].name')" >> $GITHUB_OUTPUT
outputs:
environments: ${{ steps.envs.outputs.environments }}
web_flasher_names: ${{ steps.envs.outputs.web_flasher_names}}
tag: ${{ steps.envs.outputs.tag}}
build-binaries:
name: build ${{ matrix.environment }}
needs: get-envs
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
environment: ${{ fromJSON(needs.get-envs.outputs.environments) }}
steps:
- uses: actions/checkout@v4
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip
- name: Cache PlatformIO
uses: actions/cache@v3
with:
path: |
~/.platformio
./pio
key: ${{ runner.os }}-pio-${{ matrix.environment }}-${{ hashFiles('**/platformio.ini') }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install PlatformIO
run: pip install -r requirements.txt
- name: Build firmware
env:
PUBLISH: true
VERSION: ${{ needs.get-envs.outputs.tag }}
PLATFORMIO_BUILD_FLAGS: -DVERSION='"${{ needs.get-envs.outputs.tag }}"'
run: pio run -e ${{ matrix.environment }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.environment }}
path: publish/${{ matrix.environment }}
build-gh-pages:
name: Build gh pages
needs: [ get-envs, build-binaries ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: List environments for gh-pages
working-directory: ./gh-pages
run: |
mkdir -p ./_data
mkdir -p ./_site
echo '${{ needs.get-envs.outputs.web_flasher_names }}' | jq '[.[] | {name: ., path: ("publish/" + sub("(\\s)"; "_"; "g") + "_manifest.json")}]' > ./_data/manifests.json
- uses: actions/configure-pages@v4
- uses: actions/jekyll-build-pages@v1
with:
source: ./gh-pages
destination: ./gh-pages/_site
- uses: actions/download-artifact@v4
with:
path: ./gh-pages/_site/publish
- name: merge manifests
working-directory: ./gh-pages
run: |
echo "$(echo '${{ needs.get-envs.outputs.web_flasher_names }}' | jq -r '.[]')" | while read -r name; do
sanitized_name=$(echo \"$name\" | jq -r 'sub("(\\s)"; "_"; "g")')
jq -s --arg name "$name" '[.[] | select(.name == $name)] | (.[0] | with_entries(select(.key != "builds"))) + {builds: map(.builds) | add}' ./_site/publish/*/manifest.json > ./_site/publish/${sanitized_name}_manifest.json
done
- uses: actions/upload-pages-artifact@v3
with:
path: ./gh-pages/_site
deploy:
if: (github.ref == 'refs/heads/master' && github.event_name == 'push') || github.event.inputs.deploy-pages == 'true'
runs-on: ubuntu-latest
needs: build-gh-pages
permissions:
pages: write
id-token: write
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}