name: lint-test-docker on: pull_request: branches: - main paths: - 'hosts/**' push: branches: - main paths: - 'hosts/**' env: BASE_BRANCH: "origin/${{ github.base_ref }}" jobs: lint-docker-compose: runs-on: ubuntu-js steps: - name: Checkout uses: actions/checkout@v6 with: fetch-depth: 0 - name: Check Branch Exists id: check-branch-exists if: github.event_name == 'pull_request' uses: GuillaumeFalourd/branch-exists@v1.1 with: branch: "${{ github.base_ref }}" - name: Report Branch Exists id: branch-exists if: github.event_name == 'push' || steps.check-branch-exists.outputs.exists == 'true' && github.event_name == 'pull_request' run: | if [ "${{ github.event_name }}" == "push" ]; then echo ">> Action is from a push event, will continue with linting" else echo ">> Branch ${{ github.base_ref }} exists, will continue with linting" fi echo "" echo "----" echo "exists=true" >> $GITHUB_OUTPUT - name: Set Up Node.js if: steps.branch-exists.outputs.exists == 'true' uses: actions/setup-node@v6 with: node-version: '24' - name: Check Directories for Changes id: check-dir-changes if: steps.branch-exists.outputs.exists == 'true' run: | echo ">> Target branch for diff is: ${BASE_BRANCH}" if [ "${{ github.event_name }}" == "pull_request" ]; then DIFF_TARGET="${BASE_BRANCH}" echo "" echo ">> Checking for changes in a pull request ..." else DIFF_TARGET="${{ github.event.before }}..HEAD" echo "" echo ">> Checking for changes from a push ..." fi CHANGED_COMPOSE=$(git diff --name-only "${DIFF_TARGET}" | grep -E "^hosts/[^/]+/[^/]+/" | cut -d/ -f1,2,3 | sort -u || true) if [ -n "${CHANGED_COMPOSE}" ]; then echo "" echo ">> Compose to Lint:" echo "" echo "${CHANGED_COMPOSE}" CHANGED_COMPOSE_CSV=$(echo "$CHANGED_COMPOSE" | paste -sd ',' -) echo "" echo "----" echo "changes-detected=true" >> $GITHUB_OUTPUT echo "compose-dir-csv=${CHANGED_COMPOSE_CSV}" >> $GITHUB_OUTPUT echo "compose-dir<> $GITHUB_OUTPUT echo "${CHANGED_COMPOSE}" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT else echo "" echo ">> Did not find any docker compose files to lint" echo "" echo "----" echo "changes-detected=false" >> $GITHUB_OUTPUT fi - name: Lint Docker Compose if: steps.check-dir-changes.outputs.changes-detected == 'true' env: CHANGED_COMPOSE: ${{ steps.check-dir-changes.outputs.compose-dir }} run: | echo ">> Running dclint on changed compose files ..." for COMPOSE in $CHANGED_COMPOSE; do echo ">> Linting ${COMPOSE} ..." npx dclint ${COMPOSE} done echo "" echo "----" - name: ntfy Failed uses: niniyas/ntfy-action@master if: failure() with: url: '${{ secrets.NTFY_URL }}' topic: '${{ secrets.NTFY_TOPIC }}' title: 'Docker Compose Test Failure' priority: 3 headers: '{"Authorization": "Bearer ${{ secrets.NTFY_CRED }}"}' tags: action,failed details: "Docker linting for compose dirs: ${{ steps.check-dir-changes.outputs.compose-dir-csv }}" icon: 'https://cdn.jsdelivr.net/gh/selfhst/icons/png/gitea.png' actions: '[{"action": "view", "label": "View Logs", "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", "clear": true}]'