Skip to content

Merge pull request #34 from ApolloAutomation/Labels #68

Merge pull request #34 from ApolloAutomation/Labels

Merge pull request #34 from ApolloAutomation/Labels #68

Workflow file for this run

name: Publish
env:
DEVICE_NAME: air_test-1
on:
push:
branches:
- main
#workflow_dispatch:
# inputs:
# version:
# description: 'The version of the firmware to build'
# required: true
#release:
# types: [published]
jobs:
check-for-yaml:
name: Check for YAML Changes
runs-on: ubuntu-latest
outputs:
yaml_changed: ${{ steps.check.outputs.yaml_changed }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2 # Fetch enough history to access the previous commit
- name: Find .yaml Changes in Last PR Merge
id: check
run: |
BASE_COMMIT=$(git rev-parse HEAD^1)
MERGE_COMMIT=$(git rev-parse HEAD)
if git diff --name-only $BASE_COMMIT $MERGE_COMMIT | grep -q '\.yaml$'; then
echo "YAML files changed"
echo "yaml_changed=true" >> $GITHUB_OUTPUT
else
echo "No YAML files changed"
echo "yaml_changed=false" >> $GITHUB_OUTPUT
fi
build-firmware:
name: Build And Release
uses: esphome/workflows/.github/workflows/build.yml@main
needs:
- check-for-yaml
if: needs.check-for-yaml.outputs.yaml_changed == 'true'
with:
files: |
Integrations/ESPHome/PLT-1.yaml
esphome-version: stable
combined-name: firmware
release-summary: ${{ github.event_name == 'release' && github.event.release.body || '' }}
release-url: ${{ github.event_name == 'release' && github.event.release.html_url || '' }}
release-version: ${{ (github.event_name == 'release' && github.event.release.tag_name) || (github.event_name == 'workflow_dispatch' && inputs.version) || '' }}
build-firmware-b:
name: Build And Release
uses: esphome/workflows/.github/workflows/build.yml@main
needs:
- check-for-yaml
if: needs.check-for-yaml.outputs.yaml_changed == 'true'
with:
files: |
Integrations/ESPHome/PLT-1B.yaml
esphome-version: stable
combined-name: firmware-b
release-summary: ${{ github.event_name == 'release' && github.event.release.body || '' }}
release-url: ${{ github.event_name == 'release' && github.event.release.html_url || '' }}
release-version: ${{ (github.event_name == 'release' && github.event.release.tag_name) || (github.event_name == 'workflow_dispatch' && inputs.version) || '' }}
build-site:
name: Build Site
runs-on: ubuntu-latest
needs:
- check-for-yaml
- build-firmware
- build-firmware-b
if: needs.check-for-yaml.outputs.yaml_changed == 'true'
steps:
- name: Checkout source code
uses: actions/checkout@v4.1.7
- name: Build
uses: actions/jekyll-build-pages@v1.0.13
with:
source: ./static
destination: ./output
- name: Upload
uses: actions/upload-artifact@v4.3.6
with:
name: site
path: output
publish:
name: Publish to GitHub Pages
runs-on: ubuntu-latest
needs:
- build-site
if: needs.check-for-yaml.outputs.yaml_changed == 'true' && ${{ github.run_attempt == 1 }}
permissions:
contents: write
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout code
uses: actions/checkout@v3
# Get the last merged PR's body for the release notes
- name: Fetch Last Merged PR Body
id: last_pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_INFO=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/pulls?state=closed&sort=updated&direction=desc&per_page=1")
PR_BODY=$(echo "$PR_INFO" | jq -r '.[0].body')
echo "$PR_BODY" > pr_body.txt # Save to a file
- name: Set PR Body as Environment Variable
run: |
PR_BODY=$(<pr_body.txt)
echo "PR_BODY<<EOF" >> $GITHUB_ENV
echo "$PR_BODY" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Read version from YAML file
id: read_version
run: |
version=$(awk '/substitutions:/ {found=1} found && /version:/ {print $2; exit}' Integrations/ESPHome/Core.yaml | tr -d '"')
echo "project_version=$version" >> $GITHUB_ENV
echo "Detected version: $version"
shell: bash
- name: 🚀 Run Release Drafter
id: run-release-drafter
uses: release-drafter/release-drafter@v6
with:
version: ${{ env.project_version }}
publish: true
tag: ${{ env.project_version }}
name: Release ${{ env.project_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 3) Download artifacts from a previous build job
- name: Download Firmware
uses: actions/download-artifact@v4
with:
name: firmware
path: firmware
- name: Download Firmware-B
uses: actions/download-artifact@v4
with:
name: firmware-b
path: firmware-b
# 4) Zip up each firmware folder
- name: Zip firmware
run: |
zip -r firmware.zip firmware
zip -r firmware-b.zip firmware-b
# 5) Upload firmware.zip as an asset
- name: Upload firmware.zip
id: upload-firmware
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.run-release-drafter.outputs.upload_url }}
asset_path: firmware.zip
asset_name: firmware.zip
asset_content_type: application/zip
# 6) Upload firmware-b.zip as another asset
- name: Upload firmware-b.zip
id: upload-firmware-b
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.run-release-drafter.outputs.upload_url }}
asset_path: firmware-b.zip
asset_name: firmware-b.zip
asset_content_type: application/zip
- name: Copy firmware and manifest
run: |-
mkdir -p output/firmware
cp -r firmware/${{ needs.build-firmware.outputs.version }}/* output/firmware/
- name: Copy firmware and manifest
run: |-
mkdir -p output/firmware-b
cp -r firmware-b/${{ needs.build-firmware-b.outputs.version }}/* output/firmware-b/
- uses: actions/download-artifact@v4.1.8
with:
name: site
path: output
- uses: actions/upload-pages-artifact@v3.0.1
with:
path: output
retention-days: 1
- name: Setup Pages
uses: actions/configure-pages@v5.0.0
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4.0.5