mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-31 04:44:05 +02:00
update build logic
This commit is contained in:
129
.github/workflows/onpush_builder.yaml
vendored
129
.github/workflows/onpush_builder.yaml
vendored
@@ -1,6 +1,6 @@
|
|||||||
# yamllint disable rule:line-length
|
# yamllint disable rule:line-length
|
||||||
# inspired from https://github.com/Poeschl/Hassio-Addons
|
# Build all add-ons, continue matrix even if one fails
|
||||||
---
|
|
||||||
name: Builder
|
name: Builder
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@@ -15,70 +15,26 @@ on:
|
|||||||
- "**/config.*"
|
- "**/config.*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
correct_path_filters:
|
list-addons:
|
||||||
if: ${{ github.repository_owner == 'alexbelgium' && !contains(github.event.head_commit.message, 'nobuild') }}
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
|
||||||
- name: ↩️ Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Update path_filters
|
|
||||||
run: |
|
|
||||||
# Init
|
|
||||||
echo "Starting"
|
|
||||||
|
|
||||||
# Go through all folders, add to filters if not existing
|
|
||||||
for f in $( find -- * -maxdepth 0 -type d | sort -r ); do
|
|
||||||
if [ -f "$f"/config.json ]; then
|
|
||||||
|
|
||||||
# Add to file
|
|
||||||
if ! grep "$f:" ".github/paths-filter.yml"; then
|
|
||||||
echo "$f: $f/config.*" >> ".github/paths-filter.yml"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Identify addons with true images
|
|
||||||
if [ "$(jq '.image' "$f/config.json")" != null ]; then
|
|
||||||
sed -i "/$f/ s/ # Image : yes//g" ".github/paths-filter.yml"
|
|
||||||
sed -i "/$f/ s/$/ # Image : yes/" ".github/paths-filter.yml"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Sort yaml
|
|
||||||
sort -t= ".github/paths-filter.yml" -o ".github/paths-filter.yml"
|
|
||||||
- name: Commit if needed
|
|
||||||
uses: EndBug/add-and-commit@v9
|
|
||||||
with:
|
|
||||||
commit: -u
|
|
||||||
message: "GitHub bot : scripts executable"
|
|
||||||
default_author: github_actions
|
|
||||||
|
|
||||||
check-addon-changes:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [correct_path_filters]
|
|
||||||
outputs:
|
outputs:
|
||||||
changedAddons: ${{ steps.filter.outputs.changes }}
|
addons: ${{ steps.find_addons.outputs.addons }}
|
||||||
steps:
|
steps:
|
||||||
- name: ↩️ Checkout
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: 📂 Detect changed files
|
- id: find_addons
|
||||||
uses: dorny/paths-filter@v3
|
run: |
|
||||||
id: filter
|
# Find all folders (max depth 2) that have a config.json and output as JSON array
|
||||||
with:
|
ADDONS=$(find . -maxdepth 2 -type f -name "config.json" | sed 's|^\./||;s|/config.json||' | jq -R -s -c 'split("\n")[:-1]')
|
||||||
filters: .github/paths-filter.yml
|
echo "addons=$ADDONS" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
correct-CRLF:
|
|
||||||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
|
||||||
needs: check-addon-changes
|
|
||||||
uses: ./.github/workflows/weekly_crlftolf.yaml
|
|
||||||
|
|
||||||
make-executable:
|
make-executable:
|
||||||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
needs: list-addons
|
||||||
needs: [check-addon-changes, correct-CRLF]
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
|
addon: ${{ fromJSON(needs.list-addons.outputs.addons) }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -87,12 +43,7 @@ jobs:
|
|||||||
echo "Starting"
|
echo "Starting"
|
||||||
git pull origin master
|
git pull origin master
|
||||||
git config core.filemode true
|
git config core.filemode true
|
||||||
# shellcheck disable=SC2086,SC2046
|
chmod u+x $(find "${{ matrix.addon }}" -type f -iname "*.sh") || true
|
||||||
#git update-index --chmod=+x $(find "$path" -type f -iname "*.sh")
|
|
||||||
chmod u+x $(find "$path" -type f -iname "*.sh") || true
|
|
||||||
#git commit -am "fixing the script permissions..."
|
|
||||||
env:
|
|
||||||
path: "./${{ matrix.addon }}"
|
|
||||||
- name: Commit if needed
|
- name: Commit if needed
|
||||||
uses: EndBug/add-and-commit@v9
|
uses: EndBug/add-and-commit@v9
|
||||||
with:
|
with:
|
||||||
@@ -101,12 +52,12 @@ jobs:
|
|||||||
default_author: github_actions
|
default_author: github_actions
|
||||||
|
|
||||||
normalize-spaces:
|
normalize-spaces:
|
||||||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
needs: [list-addons, make-executable]
|
||||||
needs: [check-addon-changes, make-executable, correct-CRLF]
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
|
addon: ${{ fromJSON(needs.list-addons.outputs.addons) }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -114,11 +65,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
cd "${{ matrix.addon }}"
|
cd "${{ matrix.addon }}"
|
||||||
# Find all files (excluding .git)
|
|
||||||
find . -type f ! -path "./.git/*" | while read -r file; do
|
find . -type f ! -path "./.git/*" | while read -r file; do
|
||||||
# Replace all non-breaking spaces (U+00A0) with ASCII space
|
|
||||||
LC_ALL=C sed -i 's/\xC2\xA0/ /g' "$file"
|
LC_ALL=C sed -i 's/\xC2\xA0/ /g' "$file"
|
||||||
# Optionally, replace other weird unicode spaces if needed (can be added here)
|
|
||||||
done
|
done
|
||||||
- name: Commit if normalization was needed
|
- name: Commit if normalization was needed
|
||||||
uses: EndBug/add-and-commit@v9
|
uses: EndBug/add-and-commit@v9
|
||||||
@@ -128,29 +76,29 @@ jobs:
|
|||||||
default_author: github_actions
|
default_author: github_actions
|
||||||
|
|
||||||
lint_config:
|
lint_config:
|
||||||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
needs: [list-addons, normalize-spaces, make-executable]
|
||||||
needs: [check-addon-changes, normalize-spaces, correct-CRLF, make-executable, correct_path_filters]
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
|
addon: ${{ fromJSON(needs.list-addons.outputs.addons) }}
|
||||||
steps:
|
steps:
|
||||||
- name: ↩️ Checkout
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: 🔎 Run Home Assistant Add-on Lint
|
- name: Run Home Assistant Add-on Lint
|
||||||
uses: frenck/action-addon-linter@v2
|
uses: frenck/action-addon-linter@v2
|
||||||
with:
|
with:
|
||||||
path: "./${{ matrix.addon }}"
|
path: "./${{ matrix.addon }}"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
needs: [list-addons, lint_config]
|
||||||
needs: [check-addon-changes, lint_config]
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: CR_PAT
|
environment: CR_PAT
|
||||||
name: Build ${{ matrix.arch }} ${{ matrix.addon }} add-on
|
name: Build ${{ matrix.arch }} ${{ matrix.addon }} add-on
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
|
addon: ${{ fromJSON(needs.list-addons.outputs.addons) }}
|
||||||
arch: ["aarch64", "amd64", "armv7"]
|
arch: ["aarch64", "amd64", "armv7"]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -159,17 +107,13 @@ jobs:
|
|||||||
|
|
||||||
- name: Resolve Symlinks
|
- name: Resolve Symlinks
|
||||||
run: |
|
run: |
|
||||||
# Find all symlinks and replace them with the real files or directories
|
|
||||||
find . -type l | while read -r link; do
|
find . -type l | while read -r link; do
|
||||||
target="$(readlink -f "$link")"
|
target="$(readlink -f "$link")"
|
||||||
if [ -z "$target" ]; then
|
if [ -z "$target" ]; then
|
||||||
echo "Skipping broken symlink: $link"
|
echo "Skipping broken symlink: $link"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm "$link"
|
rm "$link"
|
||||||
|
|
||||||
# If target is directory, copy contents into link's parent directory
|
|
||||||
if [ -d "$target" ]; then
|
if [ -d "$target" ]; then
|
||||||
mkdir -p "$link"
|
mkdir -p "$link"
|
||||||
cp -a "$target/." "$link/"
|
cp -a "$target/." "$link/"
|
||||||
@@ -189,19 +133,14 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
HEAD: "${{ github.head_ref }}"
|
HEAD: "${{ github.head_ref }}"
|
||||||
run: |
|
run: |
|
||||||
# shellcheck disable=SC2157,SC2086
|
|
||||||
if [[ "${{ steps.info.outputs.architectures }}" =~ ${{ matrix.arch }} ]]; then
|
if [[ "${{ steps.info.outputs.architectures }}" =~ ${{ matrix.arch }} ]]; then
|
||||||
# shellcheck disable=SC2129
|
|
||||||
echo "build_arch=true" >> $GITHUB_OUTPUT;
|
echo "build_arch=true" >> $GITHUB_OUTPUT;
|
||||||
# shellcheck disable=SC2129
|
|
||||||
echo "image=$(echo ${{ steps.info.outputs.image }} | cut -d'/' -f3)" >> $GITHUB_OUTPUT;
|
echo "image=$(echo ${{ steps.info.outputs.image }} | cut -d'/' -f3)" >> $GITHUB_OUTPUT;
|
||||||
if [[ -z "$HEAD" ]] && [[ "${{ github.event_name }}" == "push" ]]; then
|
if [[ -z "$HEAD" ]] && [[ "${{ github.event_name }}" == "push" ]]; then
|
||||||
# shellcheck disable=SC2129
|
|
||||||
echo "BUILD_ARGS=" >> $GITHUB_ENV;
|
echo "BUILD_ARGS=" >> $GITHUB_ENV;
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "${{ matrix.arch }} is not a valid arch for ${{ matrix.addon }}, skipping build";
|
echo "${{ matrix.arch }} is not a valid arch for ${{ matrix.addon }}, skipping build";
|
||||||
# shellcheck disable=SC2129
|
|
||||||
echo "build_arch=false" >> $GITHUB_OUTPUT;
|
echo "build_arch=false" >> $GITHUB_OUTPUT;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -219,6 +158,7 @@ jobs:
|
|||||||
- name: Build ${{ matrix.addon }} add-on
|
- name: Build ${{ matrix.addon }} add-on
|
||||||
id: builderstep
|
id: builderstep
|
||||||
if: steps.check.outputs.build_arch == 'true'
|
if: steps.check.outputs.build_arch == 'true'
|
||||||
|
continue-on-error: true # <-- This makes the matrix continue if a build fails
|
||||||
uses: home-assistant/builder@2025.03.0
|
uses: home-assistant/builder@2025.03.0
|
||||||
env:
|
env:
|
||||||
CAS_API_KEY: ${{ secrets.CAS_API_KEY }}
|
CAS_API_KEY: ${{ secrets.CAS_API_KEY }}
|
||||||
@@ -232,22 +172,20 @@ jobs:
|
|||||||
--addon
|
--addon
|
||||||
|
|
||||||
make-changelog:
|
make-changelog:
|
||||||
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
|
needs: [list-addons, build]
|
||||||
needs: [check-addon-changes, build]
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
|
addon: ${{ fromJSON(needs.list-addons.outputs.addons) }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Update changelog for minor versions
|
- name: Update changelog for minor versions
|
||||||
run: |
|
run: |
|
||||||
echo "Starting"
|
echo "Starting"
|
||||||
# Git pull
|
|
||||||
git pull || true
|
git pull || true
|
||||||
cd "$path"
|
cd "${{ matrix.addon }}"
|
||||||
# Get version
|
|
||||||
if [ -f config.yaml ]; then
|
if [ -f config.yaml ]; then
|
||||||
version="$(sed -e '/version/!d' -e 's/.*version: //' config.yaml)"
|
version="$(sed -e '/version/!d' -e 's/.*version: //' config.yaml)"
|
||||||
elif [ -f config.json ]; then
|
elif [ -f config.json ]; then
|
||||||
@@ -256,22 +194,15 @@ jobs:
|
|||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# Exit if test
|
|
||||||
if [[ "$version" == *"test"* ]]; then exit 0; fi
|
if [[ "$version" == *"test"* ]]; then exit 0; fi
|
||||||
# Create changelog
|
|
||||||
touch CHANGELOG.md
|
touch CHANGELOG.md
|
||||||
# If the version does not exist
|
|
||||||
if ! grep -q "$version" CHANGELOG.md; then
|
if ! grep -q "$version" CHANGELOG.md; then
|
||||||
first_line="$(sed -n '/./p' CHANGELOG.md | head -n 1)"
|
first_line="$(sed -n '/./p' CHANGELOG.md | head -n 1)"
|
||||||
# If the first line does not start with -
|
|
||||||
if [[ "$first_line" != "-"* ]]; then
|
if [[ "$first_line" != "-"* ]]; then
|
||||||
sed -i "1i\- Minor bugs fixed" CHANGELOG.md
|
sed -i "1i\- Minor bugs fixed" CHANGELOG.md
|
||||||
fi
|
fi
|
||||||
sed -i "1i\## $version ($(date '+%d-%m-%Y'))" CHANGELOG.md
|
sed -i "1i\## $version ($(date '+%d-%m-%Y'))" CHANGELOG.md
|
||||||
#fi
|
|
||||||
fi
|
fi
|
||||||
env:
|
|
||||||
path: "./${{ matrix.addon }}"
|
|
||||||
- name: Commit if needed
|
- name: Commit if needed
|
||||||
uses: EndBug/add-and-commit@v9
|
uses: EndBug/add-and-commit@v9
|
||||||
with:
|
with:
|
||||||
|
|||||||
Reference in New Issue
Block a user