name: Format on: push: branches: - main concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: format: if: "${{ github.repository == 'remix-run/remix' && !startsWith(github.event.head_commit.message, 'chore: format') }}" runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v6 with: token: ${{ secrets.FORMAT_PAT }} - name: Detect formatting-relevant changes id: changes run: | base="${{ github.event.before }}" if [ "$base" = "0000000000000000000000000000000000000000" ]; then files="$(git ls-files)" else git fetch --no-tags --depth=1 origin "$base" files="$(git diff --name-only "$base" "$GITHUB_SHA")" fi if [ -z "$files" ]; then echo "No changed files detected" echo "should_run=false" >> "$GITHUB_OUTPUT" exit 0 fi while IFS= read -r file; do case "$file" in .oxfmtrc|.oxfmtrc.json|.oxfmtrc.jsonc|.oxfmtrc.js|.oxfmtrc.cjs|.oxfmtrc.mjs|oxfmt.config.ts|oxfmt.config.mts|oxfmt.config.cts|oxfmt.config.js|oxfmt.config.mjs|oxfmt.config.cjs|*.js|*.jsx|*.cjs|*.mjs|*.ts|*.tsx|*.cts|*.mts|*.json|*.jsonc|*.md|*.mdx|*.yaml|*.yml|*.toml|*.css|*.scss|*.html) echo "Formatting-relevant change: $file" echo "should_run=true" >> "$GITHUB_OUTPUT" exit 0 ;; esac done <> "$GITHUB_OUTPUT" - name: Install pnpm if: steps.changes.outputs.should_run == 'true' uses: pnpm/action-setup@v6 - name: Install Node.js if: steps.changes.outputs.should_run == 'true' uses: ./.github/actions/setup-node-pnpm-cache - name: Install dependencies if: steps.changes.outputs.should_run == 'true' run: pnpm install --frozen-lockfile - name: Format if: steps.changes.outputs.should_run == 'true' run: pnpm format - name: Commit if: steps.changes.outputs.should_run == 'true' run: | git config --local user.email "hello@remix.run" git config --local user.name "Remix Run Bot" git add . git restore .github/workflows # PAT doesn't have permission to push workflow changes if [ -z "$(git status --porcelain)" ]; then echo "No formatting changes" exit 0 fi git commit -m "chore: format" git push echo "Pushed formatting changes https://github.com/$GITHUB_REPOSITORY/commit/$(git rev-parse HEAD)"