Merge pull request #14 from ApolloAutomation/V9 #18
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: Publish | |
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: | | |
# Get the commit hash of the first parent (pre-merge) and the merge commit | |
BASE_COMMIT=$(git rev-parse HEAD^1) | |
MERGE_COMMIT=$(git rev-parse HEAD) | |
# Check if there were any .yaml file changes between the pre-merge and merge commits | |
if git diff --name-only $BASE_COMMIT $MERGE_COMMIT | grep -q '\.yaml$'; then | |
echo "YAML files changed" | |
echo "::set-output name=yaml_changed::true" | |
else | |
echo "No YAML files changed" | |
echo "::set-output name=yaml_changed::false" | |
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 and Create Release | |
runs-on: ubuntu-latest | |
needs: | |
- build-site | |
- build-firmware | |
- build-firmware-b | |
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 | |
- uses: actions/download-artifact@v4.1.8 | |
with: | |
name: firmware | |
path: firmware | |
- uses: actions/download-artifact@v4.1.8 | |
with: | |
name: firmware-b | |
path: firmware-b | |
# 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: 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 | |
shell: bash | |
# Create GitHub Release using the last PR's body | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: "${{ env.project_version }}" | |
release_name: "Firmware Release ${{ env.project_version }}" | |
body: "$(cat pr_body.txt)" | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload Firmware Files to Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
for file in $(find firmware -type f); do | |
filename=$(basename "$file") | |
echo "Uploading $filename from firmware directory" | |
gh release upload "${{ steps.create_release.outputs.upload_url }}" "$file" --clobber --repo ${{ github.repository }} --name "$filename" | |
done | |
# Upload each file in firmware-b folder | |
- name: Upload Firmware-B Files to Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
for file in $(find firmware-b -type f); do | |
filename=$(basename "$file") | |
echo "Uploading $filename from firmware-b directory" | |
gh release upload "${{ steps.create_release.outputs.upload_url }}" "$file" --clobber --repo ${{ github.repository }} --name "$filename" | |
done | |
- 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 |