From f6488fd66dc874edd664abc194fcd7f666db945b Mon Sep 17 00:00:00 2001 From: gladiuscode Date: Sun, 26 Jan 2025 18:24:39 +0100 Subject: [PATCH 1/4] feat: create pull-request-code-checks workflow --- .../workflows/pull-request-code-checks.yml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/pull-request-code-checks.yml diff --git a/.github/workflows/pull-request-code-checks.yml b/.github/workflows/pull-request-code-checks.yml new file mode 100644 index 0000000..e50f14d --- /dev/null +++ b/.github/workflows/pull-request-code-checks.yml @@ -0,0 +1,35 @@ +name: pull-request-code-checks + +on: + pull_request: + branches: + - main + +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 From 9fec08220af837df9ab65f9af0cf5f52b7f7ae9d Mon Sep 17 00:00:00 2001 From: gladiuscode Date: Sun, 26 Jan 2025 18:30:12 +0100 Subject: [PATCH 2/4] feat: update pull-request-code-checks to run only when pr is approved --- .github/workflows/pull-request-code-checks.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-code-checks.yml b/.github/workflows/pull-request-code-checks.yml index e50f14d..68ec545 100644 --- a/.github/workflows/pull-request-code-checks.yml +++ b/.github/workflows/pull-request-code-checks.yml @@ -1,9 +1,10 @@ name: pull-request-code-checks on: - pull_request: + pull_request_review: branches: - main + types: [ submitted ] jobs: build: From 3ef820332ffae60ce057061f4b544d1b976a71f5 Mon Sep 17 00:00:00 2001 From: gladiuscode Date: Sun, 26 Jan 2025 18:31:11 +0100 Subject: [PATCH 3/4] docs: create pull-request-code-checks --- docs/pull-request-code-checks.md | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 docs/pull-request-code-checks.md 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 + +``` + From 2bb2b282fc45e21f1f60f17de242c30f68a4fc8f Mon Sep 17 00:00:00 2001 From: gladiuscode Date: Sun, 26 Jan 2025 18:31:20 +0100 Subject: [PATCH 4/4] chore: update readme with newly created workflow --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) 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)