mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-03-09 20:38:56 +00:00
Added PR workflow that creates a comment with firmware zip
This commit is contained in:
81
.github/workflows/pr-build-env.yml
vendored
Normal file
81
.github/workflows/pr-build-env.yml
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
name: PR build with env
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
env:
|
||||
description: 'The environment to build for'
|
||||
required: true
|
||||
type: string
|
||||
is_esp32:
|
||||
description: 'Whether the build is for ESP32 based firmware'
|
||||
required: false
|
||||
type: boolean
|
||||
default: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code from repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Cache Python dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('platformio.ini') }}
|
||||
|
||||
- name: Cache PlatformIO dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.pio/libdeps
|
||||
key: ${{ runner.os }}-pio-${{ hashFiles('platformio.ini') }}
|
||||
|
||||
- name: Set up Python 3.9
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.9
|
||||
|
||||
- name: Inject secrets into ini file
|
||||
run: |
|
||||
sed -i 's/NO_AMS2MQTT_PRICE_KEY/AMS2MQTT_PRICE_KEY="${{secrets.AMS2MQTT_PRICE_KEY}}"/g' platformio.ini
|
||||
sed -i 's/NO_AMS2MQTT_PRICE_AUTHENTICATION/AMS2MQTT_PRICE_AUTHENTICATION="${{secrets.AMS2MQTT_PRICE_AUTHENTICATION}}"/g' platformio.ini
|
||||
sed -i 's/NO_AMS2MQTT_SC_KEY/AMS2MQTT_SC_KEY=\\"${{secrets.AMS2MQTT_SC_KEY}}\\"/g' platformio.ini
|
||||
sed -i 's/NO_ENERGY_SPEEDOMETER_USER/ENERGY_SPEEDOMETER_USER=\\"${{secrets.ENERGY_SPEEDOMETER_USER}}\\"/g' platformio.ini
|
||||
sed -i 's/NO_ENERGY_SPEEDOMETER_PASS/ENERGY_SPEEDOMETER_PASS=\\"${{secrets.ENERGY_SPEEDOMETER_PASS}}\\"/g' platformio.ini
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -U platformio css_html_js_minify
|
||||
|
||||
- name: Set up node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '19.x'
|
||||
|
||||
- name: Build with node
|
||||
run: |
|
||||
cd lib/SvelteUi/app
|
||||
npm ci
|
||||
npm run build
|
||||
cd -
|
||||
env:
|
||||
CI: false
|
||||
|
||||
- name: PlatformIO lib install
|
||||
run: pio lib install
|
||||
|
||||
- name: Build firmware
|
||||
run: pio run -e ${{ inputs.env }}
|
||||
|
||||
- name: Create zip file
|
||||
run: /bin/sh scripts/${{ inputs.env }}/mkzip.sh
|
||||
|
||||
- name: Upload zip as artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ inputs.env }}
|
||||
path: ${{ inputs.env }}.zip
|
||||
retention-days: 7
|
||||
99
.github/workflows/pull-request.yml
vendored
Normal file
99
.github/workflows/pull-request.yml
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
name: Pull Request build
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
build-esp32s2:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp32s2
|
||||
is_esp32: true
|
||||
|
||||
build-esp32s3:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp32s3
|
||||
is_esp32: true
|
||||
|
||||
build-esp32c3:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp32c3
|
||||
is_esp32: true
|
||||
|
||||
build-esp32:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp32
|
||||
is_esp32: true
|
||||
|
||||
build-esp32solo:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp32solo
|
||||
is_esp32: true
|
||||
|
||||
build-esp8266:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp8266
|
||||
is_esp32: false
|
||||
|
||||
comment:
|
||||
needs:
|
||||
- build-esp32s2
|
||||
- build-esp32s3
|
||||
- build-esp32c3
|
||||
- build-esp32
|
||||
- build-esp32solo
|
||||
- build-esp8266
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: write
|
||||
steps:
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
|
||||
- name: Post PR comment with download links
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
const prNumber = context.payload.pull_request.number;
|
||||
const runId = context.runId;
|
||||
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
|
||||
|
||||
const envs = ['esp32s2', 'esp32s3', 'esp32c3', 'esp32', 'esp32solo', 'esp8266'];
|
||||
const lines = envs.map(env =>
|
||||
`- **${env}**: [${env}.zip](${runUrl}/artifacts) (see artifacts on the [workflow run](${runUrl}))`
|
||||
);
|
||||
|
||||
const body = [
|
||||
'## 🔧 PR Build Artifacts',
|
||||
'',
|
||||
'All environments built successfully. Download the zip files from the workflow run artifacts:',
|
||||
'',
|
||||
...lines,
|
||||
'',
|
||||
`> [View all artifacts on the workflow run](${runUrl})`,
|
||||
].join('\n');
|
||||
|
||||
// Find and delete any previous bot comment to keep the PR clean
|
||||
const comments = await github.rest.issues.listComments({ owner, repo, issue_number: prNumber });
|
||||
for (const comment of comments.data) {
|
||||
if (comment.user.type === 'Bot' && comment.body.includes('PR Build Artifacts')) {
|
||||
await github.rest.issues.deleteComment({ owner, repo, comment_id: comment.id });
|
||||
}
|
||||
}
|
||||
|
||||
await github.rest.issues.createComment({ owner, repo, issue_number: prNumber, body });
|
||||
Reference in New Issue
Block a user