Skip to content

2 Releases

2 Releases #18

Workflow file for this run

name: Build ESPHome
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: write
actions: read
checks: write
jobs:
check-tag:
runs-on: ubuntu-latest
outputs:
tag_on_main: ${{ steps.check_tag.outputs.tag_on_main }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if tag is on main branch
id: check_tag
run: |
TAG_COMMIT=$(git rev-list -n 1 ${{ github.ref_name }})
MAIN_COMMIT=$(git rev-parse origin/main)
if git merge-base --is-ancestor $TAG_COMMIT $MAIN_COMMIT; then
echo "tag_on_main=true" >> $GITHUB_OUTPUT
echo "Tag is on main branch"
else
echo "tag_on_main=false" >> $GITHUB_OUTPUT
echo "Tag is not on main branch"
fi
build:
needs: check-tag
if: needs.check-tag.outputs.tag_on_main == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
target: [esp32s2]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 0
- name: Create empty secrets file
run: |
touch firmware/secrets.yaml
touch firmware/conf.d/secrets.yaml
- name: Setup yq
uses: vegardit/gha-setup-yq@v1
- name: Set git sha
run: |
SUMMARY=$(git log -1 --pretty=%B)
SUMMARY="${SUMMARY//'%'/'%25'}"
SUMMARY="${SUMMARY//$'\n'/'%0A'}"
SUMMARY="${SUMMARY//$'\r'/'%0D'}"
echo "RELEASE_SUMMARY=$SUMMARY" >> $GITHUB_ENV
- name: Modify version.yaml
run: |
yq -i '.substitutions.version = "${{ github.ref_name }}"' firmware/conf.d/version.yaml
cat firmware/conf.d/version.yaml
- name: Build ESPHome firmware
uses: esphome/[email protected]
with:
yaml-file: ${{ github.workspace }}/firmware/config-solo.yaml
release-summary: ${{ env.RELEASE_SUMMARY }}
complete-manifest: false
- name: ls
run: |
ls -la
ls openspool-${{ matrix.target }}/* || true
- name: Generate md5 checksum
run: |
mkdir -p artifacts/openspool-${{ matrix.target }}
mv -f openspool-${{ matrix.target }}/* artifacts/openspool-${{ matrix.target }}/
ls -la artifacts/openspool-${{ matrix.target }}
for file in artifacts/openspool-${{ matrix.target }}/*.bin; do
md5sum "$file" | awk '{print $1}' > "${file}.md5"
md5_length=$(wc -c < "${file}.md5")
if [ "$md5_length" -ne 33 ]; then
echo "MD5 generation failed for $file (length: $md5_length)"
exit 1
fi
ls -la artifacts/openspool-${{ matrix.target }}
done
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: openspool-${{ matrix.target }}
path: artifacts/openspool-${{ matrix.target }}
retention-days: 5
if-no-files-found: error
combine-manifests:
needs: [check-tag, build]
if: needs.check-tag.outputs.tag_on_main == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: downloaded-artifacts
- name: Clean artifacts
run: |
mkdir -p artifacts || true
rm -rf artifacts/manifest.json || true
rm -rf artfacts/openspool-* || true
cp downloaded-artifacts/openspool-esp32s2/*.bin artifacts/
cp downloaded-artifacts/openspool-esp32s2/*.md5 artifacts/
ls -al artifacts
- name: Combine manifests
run: |
python3 - <<EOF
import json
import sys
import os
print("Contents of downloaded-artifacts:")
for root, dirs, files in os.walk("downloaded-artifacts"):
for file in files:
print(os.path.join(root, file))
version = "${{ github.ref_name }}"
combined_manifest = {
"name": "OpenSpool",
"version": version,
"builds": [],
"new_install_prompt_erase": True
}
for target in ['esp32s2']:
try:
with open(f'downloaded-artifacts/openspool-{target}/manifest.json', 'r') as f:
manifest = json.load(f)
# Add the entire manifest to the builds array
combined_manifest['builds'].append(manifest)
except FileNotFoundError:
print(f"Warning: manifest for {target} not found")
except json.JSONDecodeError:
print(f"Error: Invalid JSON in manifest for {target}")
with open('artifacts/manifest.json', 'w') as f:
json.dump(combined_manifest, f, indent=2)
print(f"Combined manifest created with version: {version}")
print("Combined manifest content:")
print(json.dumps(combined_manifest, indent=2))
EOF
- name: Setup yq
uses: vegardit/gha-setup-yq@v1
- name: Modify version.yaml
run: |
yq -i '.substitutions.version = "${{ github.ref_name }}"' firmware/conf.d/version.yaml
cat firmware/conf.d/version.yaml
- name: Update manifest
run: |
git stash push -m "Stash before switching to main"
git checkout main
git pull origin main
git stash apply
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add firmware/conf.d/version.yaml
git diff --staged || true
if git diff --staged --quiet; then
echo "No changes to commit"
exit 1
else
git commit -m "Update version to ${{ github.ref_name }}"
git push origin main
fi
git status
- name: Release ${{ github.ref_name }}
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{ github.ref_name }}"
prerelease: false
files: |
artifacts/**/*
- name: Release Latest
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: false
files: |
artifacts/**/*