From 3aff9771ced080501e0edf7660229b16bb469d4f Mon Sep 17 00:00:00 2001 From: Pedro Carreno <34664891+Pkcarreno@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:55:11 -0400 Subject: [PATCH] ci: add lint and tsc checks on pr --- .../setup-node-pnpm-install/action.yml | 16 ++++ .github/workflows/precheck.yml | 77 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 .github/actions/setup-node-pnpm-install/action.yml create mode 100644 .github/workflows/precheck.yml diff --git a/.github/actions/setup-node-pnpm-install/action.yml b/.github/actions/setup-node-pnpm-install/action.yml new file mode 100644 index 0000000..78235c4 --- /dev/null +++ b/.github/actions/setup-node-pnpm-install/action.yml @@ -0,0 +1,16 @@ +# Taken from obytes' react native template: https://github.com/obytes/react-native-template-obytes + +name: "Setup Node + PNPM + Install Dependencies" +description: "Setup Node + PNPM + Install Dependencies" +runs: + using: "composite" + steps: + - uses: pnpm/action-setup@v4 + + - uses: actions/setup-node@v4 + with: + cache: "pnpm" + + - name: 📦 Install Project Dependencies + run: pnpm install --frozen-lockfile + shell: bash diff --git a/.github/workflows/precheck.yml b/.github/workflows/precheck.yml new file mode 100644 index 0000000..3d7429a --- /dev/null +++ b/.github/workflows/precheck.yml @@ -0,0 +1,77 @@ +# Taken from obytes' react native template: https://github.com/obytes/react-native-template-obytes + +name: Precheck + +on: + pull_request: + branches: [main] + workflow_call: + +jobs: + install: + name: Prepare enviroment + Cache + runs-on: ubuntu-latest + steps: + - name: 📦 Checkout project repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: 📦 Setup Node + PNPM + install deps + uses: ./.github/actions/setup-node-pnpm-install + + lint: + name: Lint TS (eslint, prettier) + needs: [install] + runs-on: ubuntu-latest + steps: + - name: 📦 Checkout project repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: 📦 Setup Node + PNPM + install deps + uses: ./.github/actions/setup-node-pnpm-install + + - name: 🏃‍♂️ Run ESLint PR + if: github.event_name == 'pull_request' + uses: reviewdog/action-eslint@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + eslint_flags: "src --max-warnings=0" + + - name: 🏃‍♂️ Run ESLint PR + if: github.event_name != 'pull_request' + run: pnpm run lint + + type-check: + name: Check + needs: [install] + runs-on: ubuntu-latest + steps: + - name: 📦 Checkout project repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: 📦 Setup Node + PNPM + install deps + uses: ./.github/actions/setup-node-pnpm-install + + - name: 📦 Install Reviewdog + if: github.event_name == 'pull_request' + uses: reviewdog/action-setup@v1 + + - name: 🏃‍♂️ Run TypeScript PR # Reviewdog tsc errorformat: %f:%l:%c - error TS%n: %m + # We only need to add the reviewdog step if it's a pull request + if: github.event_name == 'pull_request' + run: | + pnpm check | reviewdog -name="tsc" -efm="%f(%l,%c): error TS%n: %m" -reporter="github-pr-review" -filter-mode="nofilter" -fail-on-error -tee + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: + 🏃‍♂️ Run TypeScript Commit + # If it's not a Pull Request then we just need to run the type-check + if: github.event_name != 'pull_request' + run: pnpm check