diff --git a/.gitea/workflows/lint-test-docker-pull.yaml b/.gitea/workflows/lint-test-docker-pull.yaml deleted file mode 100644 index 80d17875d..000000000 --- a/.gitea/workflows/lint-test-docker-pull.yaml +++ /dev/null @@ -1,86 +0,0 @@ -name: lint-test-docker - -on: - pull_request: - branches: - - main - paths: - - 'hosts/**' - -jobs: - docker-lint: - runs-on: ubuntu-js - steps: - - name: Checkout - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - name: Check Branch Exists - id: check-branch-exists - uses: GuillaumeFalourd/branch-exists@v1.1 - with: - branch: "${{ github.base_ref }}" - - - name: Branch Does Not Exist - if: steps.check-branch-exists.outputs.exists == 'false' - run: echo "Branch ${{ github.base_ref }} was not found, likely already merged" - - - name: Set up Node.js - if: steps.check-branch-exists.outputs.exists == 'true' - uses: actions/setup-node@v6 - with: - node-version: '24' - - - name: Lint Docker Compose - if: steps.check-branch-exists.outputs.exists == 'true' - run: | - set -e # Exit immediately if a command exits with a non-zero status. - - TARGET_BRANCH="origin/${{ github.base_ref }}" - echo ">> Target branch for diff is: $TARGET_BRANCH" - - CHANGED_FILES=$(git diff --name-only "$TARGET_BRANCH" -- 'hosts/**') - - echo ">> Found changed files:" - echo "$CHANGED_FILES" - - # For each changed file, find its parent chart directory (the one with compose.yaml). - # Then, create a unique list of those directories. - CHANGED_COMPOSE=$(echo "$CHANGED_FILES" | while read -r file; do - dir=$(dirname "$file") - while [[ "$dir" != "." && ! -f "$dir/compose.yaml" ]]; do - dir=$(dirname "$dir") - done - if [[ "$dir" != "." ]]; then - echo "$dir" - fi - done | sort -u) - - if [[ -z "$CHANGED_COMPOSE" ]]; then - echo ">> Could not determine changed compose files. This will happen if only files outside a compose file were changed." - exit 0 - fi - - echo ">> Running dclint on changed compose files:" - echo "$CHANGED_COMPOSE" - - echo "$CHANGED_COMPOSE" | while read -r compose; do - echo ">> Linting $compose ..." - npx dclint $compose - done - - - name: ntfy Failed - uses: niniyas/ntfy-action@master - if: failure() - with: - url: '${{ secrets.NTFY_URL }}' - topic: '${{ secrets.NTFY_TOPIC }}' - title: 'Test Failure - Infrastructure' - priority: 3 - headers: '{"Authorization": "Bearer ${{ secrets.NTFY_CRED }}"}' - tags: action,failed - details: 'Docker linting on Pull Request for Infrastructure has failed!' - icon: 'https://cdn.jsdelivr.net/gh/selfhst/icons/png/gitea.png' - actions: '[{"action": "view", "label": "Open Gitea", "url": "https://gitea.alexlebens.dev/alexlebens/infrastructure/actions?workflow=lint-test-docker-pull.yaml", "clear": true}]' - image: true diff --git a/.gitea/workflows/lint-test-docker-push.yaml b/.gitea/workflows/lint-test-docker-push.yaml deleted file mode 100644 index 5ec68a4a4..000000000 --- a/.gitea/workflows/lint-test-docker-push.yaml +++ /dev/null @@ -1,74 +0,0 @@ -name: lint-test-docker - -on: - push: - branches: - - main - paths: - - 'hosts/**' - -jobs: - docker-lint: - runs-on: ubuntu-js - steps: - - name: Checkout - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - name: Set up Node.js - uses: actions/setup-node@v6 - with: - node-version: '24' - - - name: Lint Docker Compose - run: | - set -e # Exit immediately if a command exits with a non-zero status. - - TARGET_BRANCH="origin/main" - echo ">> Target branch for diff is: $TARGET_BRANCH" - - CHANGED_FILES=$(git diff --name-only "$TARGET_BRANCH" -- 'hosts/**') - - echo ">> Found changed files:" - echo "$CHANGED_FILES" - - # For each changed file, find its parent chart directory (the one with compose.yaml). - # Then, create a unique list of those directories. - CHANGED_COMPOSE=$(echo "$CHANGED_FILES" | while read -r file; do - dir=$(dirname "$file") - while [[ "$dir" != "." && ! -f "$dir/compose.yaml" ]]; do - dir=$(dirname "$dir") - done - if [[ "$dir" != "." ]]; then - echo "$dir" - fi - done | sort -u) - - if [[ -z "$CHANGED_COMPOSE" ]]; then - echo ">> Could not determine changed compose files. This will happen if only files outside a compose file were changed." - exit 0 - fi - - echo ">> Running dclint on changed compose files:" - echo "$CHANGED_COMPOSE" - - echo "$CHANGED_COMPOSE" | while read -r compose; do - echo ">> Linting $compose ..." - npx dclint $compose - done - - - name: ntfy Failed - uses: niniyas/ntfy-action@master - if: failure() - with: - url: '${{ secrets.NTFY_URL }}' - topic: '${{ secrets.NTFY_TOPIC }}' - title: 'Test Failure - Infrastructure' - priority: 4 - headers: '{"Authorization": "Bearer ${{ secrets.NTFY_CRED }}"}' - tags: action,failed - details: 'Docker linting on Push for Infrastructure has failed!' - icon: 'https://cdn.jsdelivr.net/gh/selfhst/icons/png/gitea.png' - actions: '[{"action": "view", "label": "Open Gitea", "url": "https://gitea.alexlebens.dev/alexlebens/infrastructure/actions?workflow=lint-test-docker-push.yaml", "clear": true}]' - image: true diff --git a/.gitea/workflows/lint-test-docker.yaml b/.gitea/workflows/lint-test-docker.yaml new file mode 100644 index 000000000..55f52d6ed --- /dev/null +++ b/.gitea/workflows/lint-test-docker.yaml @@ -0,0 +1,127 @@ +name: lint-test-docker + +on: + pull_request: + branches: + - main + paths: + - 'hosts/**' + + push: + branches: + - main + paths: + - 'hosts/**' + +env: + BASE_BRANCH: "origin/${{ gitea.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: | + echo ">> Branch ${{ gitea.base_ref }} exists, will continue with linting" + + echo "----" + + echo "exists=true" >> $GITEA_OUTPUT + + - name: Set up Node.js + if: steps.check-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: | + CHANGED_COMPOSE=() + GIT_DIFF=() + + echo ">> Target branch for diff is: ${BASE_BRANCH}" + echo "" + + if [ "${{ github.event_name }}" == "pull_request" ]; then + echo "" + echo ">> Checking for changes in a pull request ..." + GIT_DIFF=$(git diff --name-only "${BASE_BRANCH}" | xargs -I {} dirname {} | sort -u | grep "hosts/*/**") + else + echo "" + echo ">> Checking for changes from a push ..." + GIT_DIFF=$(git diff --name-only ${{ gitea.event.before }}..HEAD | xargs -I {} dirname {} | sort -u | grep "hosts/*/**") + fi + + if [ -n "${GIT_DIFF}" ]; then + echo "" + echo ">> Changes detected:" + echo "$GIT_DIFF" + + for path in $GIT_DIFF; do + CHANGED_COMPOSE+=$(echo "$path") + done + + else + echo "" + echo ">> No changes detected" + + fi + + if [ -n "${CHANGED_COMPOSE}" ]; then + echo "" + echo ">> Compose to Lint:" + echo "$(echo "${CHANGED_COMPOSE[@]}" | sort -u)" + + echo "----" + + echo "changes-detected=true" >> $GITEA_OUTPUT + echo "compose-dir<> $GITEA_OUTPUT + echo "$(echo "${CHANGED_COMPOSE[@]}" | sort -u)" >> $GITEA_OUTPUT + echo "EOF" >> $GITEA_OUTPUT + else + echo "changes-detected=false" >> $GITEA_OUTPUT + fi + + - name: Lint Docker Compose + if: steps.check-branch-exists.outputs.exists == 'true' + env: + CHANGED_COMPOSE: ${{ steps.check-dir-changes.outputs.compose-dir }} + run: | + echo ">> Running dclint on changed compose files:" + echo "$CHANGED_COMPOSE" + + echo "$CHANGED_COMPOSE" | while read -r compose; do + echo ">> Linting $compose ..." + npx dclint $compose + done + + - name: ntfy Failed + uses: niniyas/ntfy-action@master + if: failure() + with: + url: '${{ secrets.NTFY_URL }}' + topic: '${{ secrets.NTFY_TOPIC }}' + title: 'Test Failure - Infrastructure' + priority: 3 + headers: '{"Authorization": "Bearer ${{ secrets.NTFY_CRED }}"}' + tags: action,failed + details: 'Docker linting on Pull Request for Infrastructure has failed!' + icon: 'https://cdn.jsdelivr.net/gh/selfhst/icons/png/gitea.png' + actions: '[{"action": "view", "label": "Open Gitea", "url": "https://gitea.alexlebens.dev/alexlebens/infrastructure/actions?workflow=lint-test-docker-pull.yaml", "clear": true}]' + image: true