Skip to content

Merge pull request #213 from FutureProofHomes/develop #90

Merge pull request #213 from FutureProofHomes/develop

Merge pull request #213 from FutureProofHomes/develop #90

name: Build-and-Release-Satellite-Firmware
on:
push:
branches:
- main
- staging
workflow_dispatch:
inputs:
tag:
description: 'Tag for the release (optional). If not provided, it will be auto-generated.'
required: false
env:
DEFAULT_PYTHON: "3.9"
permissions:
contents: write
pull-requests: read
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
commit_id: ${{ steps.dump.outputs.commit }}
previous_tag: ${{ steps.dump.outputs.previous_tag }}
next_tag: ${{ steps.set_release_tag.outputs.release_tag }}
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Set Manual Tag (if provided)
id: set_tag
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag != '' }}
run: echo "manual_tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
- name: Bump version
# if manual tag is provided, use it
if: ${{ !steps.set_tag.outputs.manual_tag }}
uses: anothrNick/[email protected]
id: bump
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# To create a major bump add #major to commit message
DEFAULT_BUMP: 'patch'
WITH_V: true
PRERELEASE: ${{ github.ref_name != 'main' }}
PRERELEASE_SUFFIX: ${{ github.ref_name == 'staging' && 'beta' || 'alpha' }}
DRY_RUN: true # Prevent action from pushing the tag.
INITIAL_VERSION: 0.0.0
- name: Set tag for release
if: ${{ steps.set_tag.outputs.manual_tag || steps.bump.outputs.tag }}
id: set_release_tag
run: |
if [ -z "${{ steps.set_tag.outputs.manual_tag }}" ]; then
echo "release_tag=${{ steps.bump.outputs.tag }}" >> $GITHUB_OUTPUT
else
echo "release_tag=${{ steps.set_tag.outputs.manual_tag }}" >> $GITHUB_OUTPUT
fi
- id: dump
name: Set outputs
run: |
echo "gh_env=${{ github.ref_name == 'main' && 'production' || github.ref_name == 'staging' && 'beta' || 'alpha' }}" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "long_version=${{ steps.set_release_tag.outputs.release_tag }}_$(date +%Y-%m-%d)_$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "label_version=$(echo "${{ steps.set_release_tag.outputs.release_tag }}" | sed 's/\./dot/g' | sed 's/-/dash/g')" >> $GITHUB_OUTPUT
echo "previous_tag=$(git describe --abbrev=0 --tags)" >> $GITHUB_OUTPUT
echo "files=$(ls config/satellite*.factory.yaml | jq --slurp --raw-input )" >> $GITHUB_OUTPUT
- name: Update YAML files
run: |
files=$(echo ${{ steps.dump.outputs.files }} \
| sed 's/^"//' \
| sed 's/"$//' \
| sed 's/\\n/\n/g')
tag="${{ steps.set_release_tag.outputs.release_tag }}"
for file in $files; do
echo "Updating $file"
# Use sed to match the esp32_fw_version line and replace its value
sed -i "s/^\(\s*esp32_fw_version:\s*\).*/\1\"${tag}\"/" "$file"
done
build-firmware:
name: Build Firmware
needs:
- prepare
uses: esphome/workflows/.github/workflows/build.yml@main
with:
files: |
config/satellite1.factory.yaml
esphome-version: 2024.11.2
release-version: ${{ needs.prepare.outputs.next_tag }}
push-tag:
name: Push tag to repository and build changelog.
needs:
- prepare
- build-firmware
runs-on: ubuntu-latest
outputs:
changelog: ${{ steps.changelog.outputs.changelog }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Bump version and push tag
if: ${{ !github.event.inputs.tag }}
uses: anothrNick/[email protected]
id: bump
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# To create a major bump add #major to commit message
DEFAULT_BUMP: 'patch'
WITH_V: true
PRERELEASE: ${{ github.ref_name != 'main' }}
PRERELEASE_SUFFIX: ${{ github.ref_name == 'staging' && 'beta' || 'alpha' }}
DRY_RUN: false # Set the tag to the commit.
INITIAL_VERSION: 0.0.0
- name: Release Changelog Builder
id: changelog
uses: mikepenz/release-changelog-builder-action@v5
with:
fromTag: ${{ needs.prepare.outputs.previous_tag }}
create_release:
name: Create Release
# only build release for staging and main branches
# if: github.ref_name == 'main' || github.ref_name == 'staging'
needs:
- push-tag
- prepare
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: files
- name: Create zip files
run: |
mkdir -p build
echo "Copying all files to build directory"
find files -name "*.bin" -exec cp {} build/ \;
- name: Create release
uses: softprops/action-gh-release@v2
with:
files: build/*.bin
generate_release_notes: true
append_body: true
body: ${{ needs.push-tag.outputs.changelog }}
tag_name: ${{ needs.prepare.outputs.next_tag }}
- name: Update Documentation
run: |
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.SECOND_REPO_PAT }}" \
https://api.github.com/repos/FutureProofHomes/Documentation/actions/workflows/update-binaries-esp32.yaml/dispatches \
-d '{"ref":"main", "inputs": {"esphome_release_tag": "${{ needs.prepare.outputs.next_tag }}"}}'
env:
SECOND_REPO_PAT: ${{ secrets.SECOND_REPO_PAT }}