[ESPHome] New Configuration Request #94
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build ESPHome Firmware | |
on: | |
issues: | |
types: [opened, edited] | |
jobs: | |
build: | |
# if: contains(github.event.issue.labels.*.name, 'ESPHome') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.x | |
- name: Install ESPHome | |
run: | | |
python -m pip install setuptools esphome | |
- name: Parse issue form | |
id: parse_form | |
uses: onmax/[email protected] | |
with: | |
issue_number: ${{ github.event.issue.number }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract user input from form | |
id: user_input | |
run: | | |
device_name='${{ fromJson(steps.parse_form.outputs.payload).Device_Name }}' | |
static_ip='${{ fromJson(steps.parse_form.outputs.payload).Static_IP }}' | |
gateway='${{ fromJson(steps.parse_form.outputs.payload).Gateway }}' | |
subnet='${{ fromJson(steps.parse_form.outputs.payload).Subnet }}' | |
echo "Parsed values:" | |
echo "Device Name: $device_name" | |
echo "Static IP: $static_ip" | |
echo "Gateway: $gateway" | |
echo "Subnet: $subnet" | |
if [ -z "$device_name" ] || [ -z "$static_ip" ] || [ -z "$gateway" ] || [ -z "$subnet" ]; then | |
echo "Error: One or more required values are missing." | |
exit 1 | |
fi | |
echo "device_name=$device_name" >> $GITHUB_ENV | |
echo "static_ip=$static_ip" >> $GITHUB_ENV | |
echo "gateway=$gateway" >> $GITHUB_ENV | |
echo "subnet=$subnet" >> $GITHUB_ENV | |
- name: Update ESPHome YAML | |
run: | | |
device_yaml="esphome-config/${{ env.device_name }}.yaml" | |
sed -i "s/STATIC_IP/${{ env.static_ip }}/" $device_yaml | |
sed -i "s/GATEWAY/${{ env.gateway }}/" $device_yaml | |
sed -i "s/SUBNET/${{ env.subnet }}/" $device_yaml | |
- name: Compile ESPHome Firmware | |
run: | | |
device_yaml="esphome-config/${{ env.device_name }}.yaml" | |
esphome compile $device_yaml | |
# - name: List build directory contents | |
# run: | | |
# ls -Ra esphome-config/.esphome/build/ | |
- name: Upload Firmware | |
uses: actions/upload-artifact@v4 | |
with: | |
name: firmware | |
path: | | |
esphome-config/.esphome/build/${{ env.device_name }}/.pioenvs/${{ env.device_name }}/firmware.factory.bin | |
esphome-config/.esphome/build/${{ env.device_name }}/.pioenvs/${{ env.device_name }}/firmware.ota.bin | |
- name: Get artifact ID | |
id: get_artifact_id | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const artifacts = await github.rest.actions.listArtifactsForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
const artifact = artifacts.data.artifacts.find(artifact => artifact.name === 'firmware'); | |
if (!artifact) { | |
throw new Error('Artifact not found'); | |
} | |
core.setOutput('artifact_id', artifact.id); | |
- name: Create comment with firmware link | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const issue_number = ${{ github.event.issue.number }}; | |
const artifact_id = ${{ steps.get_artifact_id.outputs.artifact_id }}; | |
const firmwareArtifactUrl = `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${artifact_id}`; | |
const commentBody = ` | |
## Firmware Build Complete | |
The firmware build for your device \`${{ env.device_name }}\` is complete. You can download the firmware files from the link below: | |
[Download Firmware](${firmwareArtifactUrl}) | |
- Static IP: \`${{ env.static_ip }}\` | |
- Gateway: \`${{ env.gateway }}\` | |
- Subnet: \`${{ env.subnet }}\` | |
`; | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: commentBody | |
}); | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |