Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USWDS-Next - CI: Create a GH action to test code formatting #32

Merged
merged 7 commits into from
Jul 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Code formatting
on: push
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Install dependencies
run: npm ci
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: At some point we may need to move tasks around between actions to cut down on the number of times we're running npm ci in CI

Copy link
Collaborator Author

@mejiaj mejiaj Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great thought.

The setup-node action supports caching. Added in ef95346.

You should now see a caches link in actions.

image

Not seeing any major differences so far.

Before After
image image

https://github.com/uswds/uswds-next/actions/caches


Tip

Monorepo dependencies can be cached too. Example below.

Monorepo dependency cache

Details

steps:
- uses: actions/setup-node@v4
  with:
    node-version: '18.x'
    cache: 'npm'
    cache-dependency-path: '**/package-lock.json'
- run: npm ci
- run: npm test

Source: https://github.com/actions/setup-node?tab=readme-ov-file#caching-global-packages-data

- name: Run prettier
run: 'npm run prettier:js'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): Doesn't have to be in this PR but it might be a good idea to add a minimal prettier config even if we're just using defaults. Some editors need a config in order to run prettier, and it's just helpful to have at the project root to signal intent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with clear intent.

Added .prettierignore and .prettierrc in 6342c0d.