diff --git a/.github/workflows/pull-request-code-checks.yml b/.github/workflows/pull-request-code-checks.yml new file mode 100644 index 0000000..68ec545 --- /dev/null +++ b/.github/workflows/pull-request-code-checks.yml @@ -0,0 +1,36 @@ +name: pull-request-code-checks + +on: + pull_request_review: + branches: + - main + types: [ submitted ] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup + uses: ./.github/actions/setup + + - name: Build + run: yarn build + + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup + uses: ./.github/actions/setup + + - name: Lint + run: yarn lint diff --git a/README.md b/README.md index 82b7e54..b9c3870 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,12 @@ approach to the bypass procedure. This workflow shows how to pass artifacts from one job to another. Take a look at the [pass-artifacts-to-next-job](./docs/pass-artifacts-to-next-jobs.md) document to see how to set it up. +### Pull Request Code Checks + +This workflow shows how to run code checks on a pull request that targets the main branch, it runs the `build` and `lint` +scripts. +Take a look at the [pull-request-code-checks](./docs/pull-request-code-checks.md) document to see how to set it up. + ## Useful links - [Github Actions Documentation](https://docs.github.com/en/actions) diff --git a/docs/pull-request-code-checks.md b/docs/pull-request-code-checks.md new file mode 100644 index 0000000..87abe1c --- /dev/null +++ b/docs/pull-request-code-checks.md @@ -0,0 +1,53 @@ +# Pull request code checks + +When a new pull request is opened against the main branch, it is a good idea to run some checks on the code to make sure +that it is up to the standards of the project. +You can run it on every push, but it is better to run it only when a pull request is approved, to avoid reaching the +limits of the Github Actions free tier. + +Take a look at the following example: + +```yaml + +name: pull-request-code-checks + +on: + # (1) Run the workflow only when a pull request is: + # - opened against the main branch + # - and a review is submitted + pull_request_review: + branches: + - main + types: [ submitted ] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup + uses: ./.github/actions/setup + + - name: Build + run: yarn build + + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup + uses: ./.github/actions/setup + + - name: Lint + run: yarn lint + +``` +