Skip to content

Checking format

Checking format #638

Workflow file for this run

name: Check format
run-name: Checking format
on:
pull_request:
branches:
- master
jobs:
install:
name: "Install"
runs-on: ubuntu-latest
steps:
- name: Checkout files
uses: actions/checkout@v3
- name: Install node_modules
# This action does not work very well with subdirectories out of the box,
# but we can use this workaround to make it work.
# Note that this is highly dependent on the version of the action used
uses: OffchainLabs/actions/node-modules/install@35a1f8c3f3ad803e1fd9b81b94d063a4fc90a030
with:
install-command: cd website && yarn install --frozen-lockfile
cache-key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
check-formatting:
name: "Check Formatting - does not fail, only comments on error"
runs-on: ubuntu-latest
needs: install
steps:
- name: Checkout files
uses: actions/checkout@v3
- name: Restore node_modules
# This action does not work very well with subdirectories out of the box,
# but we can use this workaround to make it work.
# Note that this is highly dependent on the version of the action used
uses: OffchainLabs/actions/node-modules/restore@35a1f8c3f3ad803e1fd9b81b94d063a4fc90a030
with:
cache-key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: Check formatting with Prettier
id: prettier-check
working-directory: ./website
run: |
set +e
yarn format:check
echo "format-check-result=$?" >> $GITHUB_OUTPUT
- name: Output formatting error
if: |
steps.prettier-check.outputs.format-check-result == 1 &&
github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: 'Hey there!\nIt looks like your changes are not well formatted. You can merge this PR, but we recommend to format your code with:\n```\ncd website && yarn format\n```\nThanks!💙🧡'
})