# yamllint disable rule:line-length # inspired from https://github.com/Poeschl/Hassio-Addons --- name: Builder env: BUILD_ARGS: "" on: workflow_call: push: branches: - master paths: - "**/config.*" jobs: # Step 1: Find changed addon folders from config file changes detect-changed-addons: if: ${{ github.repository_owner == 'alexbelgium' && !contains(github.event.head_commit.message, 'nobuild') }} runs-on: ubuntu-latest outputs: changedAddons: ${{ steps.find_addons.outputs.changed_addons }} steps: - name: Checkout Repo uses: actions/checkout@v4 - name: Find changed addon directories id: find_addons run: | echo "Finding changed addons from config.* files" # Get changed files between this and previous commit # Works for push and PR, but you might want to tweak if you use merge commits, etc. git fetch origin ${{ github.event.before }} || true # Get list of changed config files changed_config_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '^[^/]+/config\.(json|ya?ml)$' || true) # For debugging echo "Changed config files:" echo "$changed_config_files" # Get the unique top-level addon directories (by extracting the folder names) changed_addons=$(echo "$changed_config_files" | awk -F/ '{print $1}' | sort -u | jq -R -s -c 'split("\n")[:-1]') echo "Changed addons: $changed_addons" echo "changed_addons=$changed_addons" >> "$GITHUB_OUTPUT" shell: bash # All jobs after this use the changedAddons output from above as matrix correct-CRLF: if: ${{ needs.detect-changed-addons.outputs.changedAddons != '' && needs.detect-changed-addons.outputs.changedAddons != '[]' }} needs: detect-changed-addons uses: ./.github/workflows/weekly_crlftolf.yaml make-executable: if: ${{ needs.detect-changed-addons.outputs.changedAddons != '' && needs.detect-changed-addons.outputs.changedAddons != '[]' }} needs: [detect-changed-addons, correct-CRLF] runs-on: ubuntu-latest strategy: fail-fast: false matrix: addon: ${{ fromJSON(needs.detect-changed-addons.outputs.changedAddons) }} steps: - name: Checkout Repo uses: actions/checkout@v4 - name: Make scripts executable run: | echo "Starting" git pull origin master git config core.filemode true chmod u+x $(find "${{ matrix.addon }}" -type f -iname "*.sh") || true - name: Commit if needed uses: EndBug/add-and-commit@v9 with: commit: -u message: "GitHub bot : scripts executable" default_author: github_actions normalize-spaces: if: ${{ needs.detect-changed-addons.outputs.changedAddons != '' && needs.detect-changed-addons.outputs.changedAddons != '[]' }} needs: [detect-changed-addons, make-executable, correct-CRLF] runs-on: ubuntu-latest strategy: matrix: addon: ${{ fromJSON(needs.detect-changed-addons.outputs.changedAddons) }} steps: - name: Checkout Repo uses: actions/checkout@v4 - name: Normalize all non-breaking spaces to regular spaces run: | set -e cd "${{ matrix.addon }}" find . -type f ! -path "./.git/*" | while read -r file; do LC_ALL=C sed -i 's/\xC2\xA0/ /g' "$file" done - name: Commit if normalization was needed uses: EndBug/add-and-commit@v9 with: commit: -u message: "GitHub bot : normalize unicode spaces" default_author: github_actions lint_config: if: ${{ needs.detect-changed-addons.outputs.changedAddons != '' && needs.detect-changed-addons.outputs.changedAddons != '[]' }} needs: [detect-changed-addons, normalize-spaces, correct-CRLF, make-executable] runs-on: ubuntu-latest strategy: matrix: addon: ${{ fromJSON(needs.detect-changed-addons.outputs.changedAddons) }} steps: - name: Checkout Repo uses: actions/checkout@v4 - name: Run Home Assistant Add-on Lint uses: frenck/action-addon-linter@v2 with: path: "./${{ matrix.addon }}" build: if: ${{ needs.detect-changed-addons.outputs.changedAddons != '' && needs.detect-changed-addons.outputs.changedAddons != '[]' }} needs: [detect-changed-addons, lint_config] runs-on: ubuntu-latest environment: CR_PAT name: Build ${{ matrix.arch }} ${{ matrix.addon }} add-on strategy: matrix: addon: ${{ fromJSON(needs.detect-changed-addons.outputs.changedAddons) }} arch: ["aarch64", "amd64", "armv7"] steps: - name: Check out repository uses: actions/checkout@v4 - name: Resolve Symlinks run: | find . -type l | while read -r link; do target="$(readlink -f "$link")" if [ -z "$target" ]; then echo "Skipping broken symlink: $link" continue fi rm "$link" if [ -d "$target" ]; then mkdir -p "$link" cp -a "$target/." "$link/" else cp "$target" "$link" fi done - name: Get information id: info uses: home-assistant/actions/helpers/info@master with: path: "./${{ matrix.addon }}" - name: Check if add-on should be built id: check env: HEAD: "${{ github.head_ref }}" run: | if [[ "${{ steps.info.outputs.architectures }}" =~ ${{ matrix.arch }} ]]; then echo "build_arch=true" >> $GITHUB_OUTPUT; echo "image=$(echo ${{ steps.info.outputs.image }} | cut -d'/' -f3)" >> $GITHUB_OUTPUT; if [[ -z "$HEAD" ]] && [[ "${{ github.event_name }}" == "push" ]]; then echo "BUILD_ARGS=" >> $GITHUB_ENV; fi else echo "${{ matrix.arch }} is not a valid arch for ${{ matrix.addon }}, skipping build"; echo "build_arch=false" >> $GITHUB_OUTPUT; fi - name: Use action to check for mixed line endings (CRLF and LF) uses: ymwymw/check-mixed-line-endings@v2 - name: Login to GitHub Container Registry if: env.BUILD_ARGS != '--test' uses: docker/login-action@v3.1.0 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build ${{ matrix.addon }} add-on id: builderstep if: steps.check.outputs.build_arch == 'true' uses: home-assistant/builder@2025.03.0 env: CAS_API_KEY: ${{ secrets.CAS_API_KEY }} with: args: | ${{ env.BUILD_ARGS }} \ --${{ matrix.arch }} \ --target /data/${{ matrix.addon }} \ --image "${{ steps.check.outputs.image }}" \ --docker-hub "ghcr.io/${{ github.repository_owner }}" \ --addon make-changelog: if: ${{ needs.detect-changed-addons.outputs.changedAddons != '' && needs.detect-changed-addons.outputs.changedAddons != '[]' }} needs: [detect-changed-addons, build] runs-on: ubuntu-latest strategy: matrix: addon: ${{ fromJSON(needs.detect-changed-addons.outputs.changedAddons) }} steps: - name: Checkout Repo uses: actions/checkout@v4 - name: Update changelog for minor versions run: | echo "Starting" git pull || true cd "${{ matrix.addon }}" if [ -f config.yaml ]; then version="$(sed -e '/version/!d' -e 's/.*version: //' config.yaml)" elif [ -f config.json ]; then version="$(sed -e '/version/!d' -e 's/.*[^"]*"\([^"]*\)"/\1/' config.json)" version="${version//,}" else exit 1 fi if [[ "$version" == *"test"* ]]; then exit 0; fi touch CHANGELOG.md if ! grep -q "$version" CHANGELOG.md; then first_line="$(sed -n '/./p' CHANGELOG.md | head -n 1)" if [[ "$first_line" != "-"* ]]; then sed -i "1i\- Minor bugs fixed" CHANGELOG.md fi sed -i "1i\## $version ($(date '+%d-%m-%Y'))" CHANGELOG.md fi - name: Commit if needed uses: EndBug/add-and-commit@v9 with: commit: -u message: "GitHub bot : changelog" default_author: github_actions fetch: --force push: --force