Skip to content

Commit dce4882

Browse files
committed
Added PR workflow that creates a comment with firmware zip
1 parent 0b48846 commit dce4882

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

.github/workflows/pr-build-env.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: PR build with env
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
env:
7+
description: 'The environment to build for'
8+
required: true
9+
type: string
10+
is_esp32:
11+
description: 'Whether the build is for ESP32 based firmware'
12+
required: false
13+
type: boolean
14+
default: true
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Check out code from repo
21+
uses: actions/checkout@v4
22+
23+
- name: Cache Python dependencies
24+
uses: actions/cache@v4
25+
with:
26+
path: ~/.cache/pip
27+
key: ${{ runner.os }}-pip-${{ hashFiles('platformio.ini') }}
28+
29+
- name: Cache PlatformIO dependencies
30+
uses: actions/cache@v4
31+
with:
32+
path: ~/.pio/libdeps
33+
key: ${{ runner.os }}-pio-${{ hashFiles('platformio.ini') }}
34+
35+
- name: Set up Python 3.9
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: 3.9
39+
40+
- name: Inject secrets into ini file
41+
run: |
42+
sed -i 's/NO_AMS2MQTT_PRICE_KEY/AMS2MQTT_PRICE_KEY="${{secrets.AMS2MQTT_PRICE_KEY}}"/g' platformio.ini
43+
sed -i 's/NO_AMS2MQTT_PRICE_AUTHENTICATION/AMS2MQTT_PRICE_AUTHENTICATION="${{secrets.AMS2MQTT_PRICE_AUTHENTICATION}}"/g' platformio.ini
44+
sed -i 's/NO_AMS2MQTT_SC_KEY/AMS2MQTT_SC_KEY=\\"${{secrets.AMS2MQTT_SC_KEY}}\\"/g' platformio.ini
45+
sed -i 's/NO_ENERGY_SPEEDOMETER_USER/ENERGY_SPEEDOMETER_USER=\\"${{secrets.ENERGY_SPEEDOMETER_USER}}\\"/g' platformio.ini
46+
sed -i 's/NO_ENERGY_SPEEDOMETER_PASS/ENERGY_SPEEDOMETER_PASS=\\"${{secrets.ENERGY_SPEEDOMETER_PASS}}\\"/g' platformio.ini
47+
48+
- name: Install dependencies
49+
run: |
50+
python -m pip install --upgrade pip
51+
pip install -U platformio css_html_js_minify
52+
53+
- name: Set up node
54+
uses: actions/setup-node@v4
55+
with:
56+
node-version: '19.x'
57+
58+
- name: Build with node
59+
run: |
60+
cd lib/SvelteUi/app
61+
npm ci
62+
npm run build
63+
cd -
64+
env:
65+
CI: false
66+
67+
- name: PlatformIO lib install
68+
run: pio lib install
69+
70+
- name: Build firmware
71+
run: pio run -e ${{ inputs.env }}
72+
73+
- name: Create zip file
74+
run: /bin/sh scripts/${{ inputs.env }}/mkzip.sh
75+
76+
- name: Upload zip as artifact
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: ${{ inputs.env }}
80+
path: ${{ inputs.env }}.zip
81+
retention-days: 7

.github/workflows/pull-request.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Pull Request build
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
build-esp32s2:
9+
uses: ./.github/workflows/pr-build-env.yml
10+
secrets: inherit
11+
with:
12+
env: esp32s2
13+
is_esp32: true
14+
15+
build-esp32s3:
16+
uses: ./.github/workflows/pr-build-env.yml
17+
secrets: inherit
18+
with:
19+
env: esp32s3
20+
is_esp32: true
21+
22+
build-esp32c3:
23+
uses: ./.github/workflows/pr-build-env.yml
24+
secrets: inherit
25+
with:
26+
env: esp32c3
27+
is_esp32: true
28+
29+
build-esp32:
30+
uses: ./.github/workflows/pr-build-env.yml
31+
secrets: inherit
32+
with:
33+
env: esp32
34+
is_esp32: true
35+
36+
build-esp32solo:
37+
uses: ./.github/workflows/pr-build-env.yml
38+
secrets: inherit
39+
with:
40+
env: esp32solo
41+
is_esp32: true
42+
43+
build-esp8266:
44+
uses: ./.github/workflows/pr-build-env.yml
45+
secrets: inherit
46+
with:
47+
env: esp8266
48+
is_esp32: false
49+
50+
comment:
51+
needs:
52+
- build-esp32s2
53+
- build-esp32s3
54+
- build-esp32c3
55+
- build-esp32
56+
- build-esp32solo
57+
- build-esp8266
58+
runs-on: ubuntu-latest
59+
permissions:
60+
pull-requests: write
61+
steps:
62+
- name: Download all artifacts
63+
uses: actions/download-artifact@v4
64+
with:
65+
path: artifacts
66+
67+
- name: Post PR comment with download links
68+
uses: actions/github-script@v7
69+
with:
70+
script: |
71+
const { owner, repo } = context.repo;
72+
const prNumber = context.payload.pull_request.number;
73+
const runId = context.runId;
74+
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
75+
76+
const envs = ['esp32s2', 'esp32s3', 'esp32c3', 'esp32', 'esp32solo', 'esp8266'];
77+
const lines = envs.map(env =>
78+
`- **${env}**: [${env}.zip](${runUrl}/artifacts) (see artifacts on the [workflow run](${runUrl}))`
79+
);
80+
81+
const body = [
82+
'## 🔧 PR Build Artifacts',
83+
'',
84+
'All environments built successfully. Download the zip files from the workflow run artifacts:',
85+
'',
86+
...lines,
87+
'',
88+
`> [View all artifacts on the workflow run](${runUrl})`,
89+
].join('\n');
90+
91+
// Find and delete any previous bot comment to keep the PR clean
92+
const comments = await github.rest.issues.listComments({ owner, repo, issue_number: prNumber });
93+
for (const comment of comments.data) {
94+
if (comment.user.type === 'Bot' && comment.body.includes('PR Build Artifacts')) {
95+
await github.rest.issues.deleteComment({ owner, repo, comment_id: comment.id });
96+
}
97+
}
98+
99+
await github.rest.issues.createComment({ owner, repo, issue_number: prNumber, body });

0 commit comments

Comments
 (0)