diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml index a3400d0..872d9b8 100644 --- a/.github/workflows/commit-check.yml +++ b/.github/workflows/commit-check.yml @@ -14,17 +14,32 @@ jobs: with: bun-version: latest - - name: Install commitlint + - name: Check for commitlint config and install dependencies + id: commitlint-config + run: | + if [ -f .commitlintrc.json ] || [ -f .commitlintrc.js ] || [ -f .commitlintrc.yml ] || [ -f .commitlintrc.yaml ] || grep -q '"commitlint"' "package.json" 2>/dev/null; then + echo "has-config=true" >> $GITHUB_OUTPUT + else + echo "has-config=false" >> $GITHUB_OUTPUT + fi + + - name: Install dependencies if config exists + if: steps.commitlint-config.outputs.has-config == 'true' + run: | + bun i -g @commitlint/cli + bun i + + - name: Install commitlint globally if no config + if: steps.commitlint-config.outputs.has-config == 'false' run: | bun i -g @commitlint/cli bun i -D @commitlint/config-conventional - name: Create commitlint config if missing + if: steps.commitlint-config.outputs.has-config == 'false' run: | - if [ ! -f .commitlintrc.json ] && [ ! -f .commitlintrc.js ] && [ ! -f .commitlintrc.yml ] && [ ! -f .commitlintrc.yaml ] && ! grep -q '"commitlint"' "package.json" 2>/dev/null; then - echo "extends:" > .commitlintrc.yml - echo " - '@commitlint/config-conventional'" >> .commitlintrc.yml - fi + echo "extends:" > .commitlintrc.yml + echo " - '@commitlint/config-conventional'" >> .commitlintrc.yml - name: Check PR title if: github.event_name == 'pull_request' diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml index fc9ca3f..051b5eb 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier.yml @@ -10,6 +10,7 @@ jobs: - uses: actions/checkout@v4 - name: Check for Prettier config + id: prettier-config run: | CONFIG_FILES=".prettierrc .prettierrc.json .prettierrc.js .prettierrc.yaml .prettierrc.yml .prettierrc.toml prettier.config.js prettier.config.mjs" HAS_CONFIG=false @@ -21,7 +22,7 @@ jobs: fi done - if [ "$HAS_CONFIG" = false ] && ! grep -q '"prettier"' "package.json" 2>/dev/null; then + if [ "$HAS_CONFIG" = false ]; then echo "::error file=.prettierrc::No Prettier configuration file found." echo "A Prettier config file is required to ensure consistent formatting across all developers." echo "Without a shared config, each developer's local Prettier settings will differ, causing unnecessary formatting changes in commits." @@ -29,6 +30,8 @@ jobs: exit 1 fi + echo "has-config=true" >> $GITHUB_OUTPUT + - name: Setup Bun uses: oven-sh/setup-bun@v2 with: @@ -37,5 +40,9 @@ jobs: - name: Install Prettier run: bun i -g prettier + - name: Install Dependencies + if: steps.prettier-config.outputs.has-config == 'true' + run: bun i + - name: Check formatting run: prettier --check .