Skip to content

Commit

Permalink
move pretty check to a new job
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Jan 23, 2025
1 parent 1b69a37 commit 241fae5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 78 deletions.
81 changes: 3 additions & 78 deletions .github/workflows/monkey-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,84 +115,9 @@ jobs:
name: Install dependencies
run: pnpm install

check-pretty:
name: check-pretty
needs: [pre-ci, prime-cache]
runs-on: ubuntu-latest
permissions:
contents: write
if: needs.pre-ci.outputs.should-build-be == 'true' || needs.pre-ci.outputs.should-build-fe == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true' || needs.pre-ci.outputs.assets-json == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci')
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}

- name: Install prettier
run: pnpm add -g [email protected]

- name: Get changed files
if: github.event_name == 'pull_request'
id: get-changed-files
uses: actions/github-script@v7
with:
script: |
const changedFiles = await github.paginate(
github.rest.pulls.listFiles,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
}
);
return changedFiles.filter(file=> file.status !== "removed").map(file => file.filename).join(' ');
- name: Check pretty (changed files)
if: github.event_name == 'pull_request'
id: check-pretty
continue-on-error: true
run: |
CHANGED_FILES=$(echo ${{ steps.get-changed-files.outputs.result }})
if [ -n "$CHANGED_FILES" ]; then
pnpm prettier --check $CHANGED_FILES
fi
- name: Check pretty (all files)
if: github.event_name == 'push'
id: check-pretty-all
continue-on-error: true
run: pnpm prettier --check .

- name: Fix pretty (changed files)
id: fix-pretty
if: github.event_name == 'pull_request' && steps.check-pretty.outcome == 'failure'
run: |
CHANGED_FILES=$(echo ${{ steps.get-changed-files.outputs.result }})
if [ -n "$CHANGED_FILES" ]; then
pnpm prettier --write $CHANGED_FILES
fi
- name: Fix pretty (all files)
id: fix-pretty-all
if: github.event_name == 'push' && steps.check-pretty-all.outcome == 'failure'
run: pnpm prettier --write .

- name: Commmit fixes
if: steps.fix-pretty.outcome == 'success' || steps.fix-pretty-all.outcome == 'success'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: prettier fixes"

ci-be:
name: ci-be
needs: [pre-ci, prime-cache, check-pretty]
needs: [pre-ci, prime-cache]
runs-on: ubuntu-latest
if: needs.pre-ci.outputs.should-build-be == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci')
steps:
Expand Down Expand Up @@ -240,7 +165,7 @@ jobs:

ci-fe:
name: ci-fe
needs: [pre-ci, prime-cache, check-pretty]
needs: [pre-ci, prime-cache]
runs-on: ubuntu-latest
if: needs.pre-ci.outputs.should-build-fe == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci')
steps:
Expand Down Expand Up @@ -293,7 +218,7 @@ jobs:

ci-assets:
name: ci-assets
needs: [pre-ci, prime-cache, check-pretty]
needs: [pre-ci, prime-cache]
runs-on: ubuntu-latest
if: needs.pre-ci.outputs.assets-json == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci')
steps:
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/pretty-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Prettier Check

env:
NODE_VERSION: "20.16.0"

on:
pull_request:
branches: [master]
types: [opened, reopened, synchronize, ready_for_review]

jobs:
check-prettier:
if: github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'force-ci') || contains(github.event.pull_request.labels.*.name, 'force-full-ci')
name: Check Prettier
runs-on: ubuntu-latest

steps:
- name: Full checkout
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}

- name: Install prettier
run: pnpm add -g [email protected]


- name: Get changed files
id: get-changed-files
uses: actions/github-script@v7
with:
script: |
const changedFiles = await github.paginate(
github.rest.pulls.listFiles,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
}
);
return changedFiles.filter(file=> file.status !== "removed").map(file => file.filename).join(' ');
- name: Check pretty (changed files)
run: |
CHANGED_FILES=$(echo ${{ steps.get-changed-files.outputs.result }})
if [ -n "$CHANGED_FILES" ]; then
pnpm prettier --check $CHANGED_FILES
fi

0 comments on commit 241fae5

Please sign in to comment.