Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
111 changes: 111 additions & 0 deletions .github/workflows/plugins-benchmark-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Benchmark PR

on:
workflow_call:
inputs:
npm-script:
type: string
default: benchmark
required: false

jobs:
benchmark:
if: ${{ github.event.label.name == 'benchmark' }}
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
PR-BENCH-16: ${{ steps.benchmark-pr.outputs.BENCH_RESULT_16 }}
PR-BENCH-18: ${{ steps.benchmark-pr.outputs.BENCH_RESULT_18 }}
PR-BENCH-20: ${{ steps.benchmark-pr.outputs.BENCH_RESULT_20 }}
DEFAULT-BENCH-16: ${{ steps.benchmark-default.outputs.BENCH_RESULT_16 }}
DEFAULT-BENCH-18: ${{ steps.benchmark-default.outputs.BENCH_RESULT_18 }}
DEFAULT-BENCH-20: ${{ steps.benchmark-default.outputs.BENCH_RESULT_20 }}

strategy:
matrix:
node-version: [16, 18, 20]
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
ref: ${{github.event.pull_request.head.sha}}
repository: ${{github.event.pull_request.head.repo.full_name}}

- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install
run: |
npm install --ignore-scripts

- name: Run benchmark
id: benchmark-pr
run: |
echo 'BENCH_RESULT_${{matrix.node-version}}<<EOF' >> $GITHUB_OUTPUT
npm run --silent ${{inputs.npm-script}} >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT

- uses: actions/checkout@v3
with:
persist-credentials: false
ref: refs/heads/${{ github.event.repository.default_branch }}
repository: ${{github.event.pull_request.head.repo.full_name}}

- name: Install
run: |
npm install --ignore-scripts

- name: Run benchmark
id: benchmark-default
run: |
echo 'BENCH_RESULT_${{matrix.node-version}}<<EOF' >> $GITHUB_OUTPUT
npm run --silent ${{inputs.npm-script}} >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT

output-benchmark:
needs:
- benchmark
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
message: |
**Node**: 16
**${{github.event.pull_request.head.ref}}**:
```
${{ needs.benchmark.outputs.PR-BENCH-16 }}
```
**${{ github.event.repository.default_branch }}**:
```
${{ needs.benchmark.outputs.DEFAULT-BENCH-16 }}
```

---

**Node**: 18
**${{github.event.pull_request.head.ref}}**:
```
${{ needs.benchmark.outputs.PR-BENCH-18 }}
```
**${{ github.event.repository.default_branch }}**:
```
${{ needs.benchmark.outputs.DEFAULT-BENCH-18 }}
```

---

**Node**: 20
**${{github.event.pull_request.head.ref}}**:
```
${{ needs.benchmark.outputs.PR-BENCH-20 }}
```
**${{ github.event.repository.default_branch }}**:
```
${{ needs.benchmark.outputs.DEFAULT-BENCH-20 }}
```
56 changes: 50 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ Reusable workflows for use in the Fastify organization.

## Intro

GitHub [introduced reusable workflows](https://github.blog/2021-11-29-github-actions-reusable-workflows-is-generally-available/) on 2021-11-29 which, as the name suggests, are workflows that can be referenced across the entirety of GitHub.
GitHub [introduced reusable workflows](https://github.blog/2021-11-29-github-actions-reusable-workflows-is-generally-available/) on 2021-11-29 which, as the name suggests, are workflows that can be referenced across the entirety of GitHub. A reusable workflow is called by using the `uses` keyword in another workflow.

For more information, including limitations, [see the GitHub Docs](https://docs.github.com/en/actions/learn-github-actions/reusing-workflows).

## Usage

A reusable workflow is called by using the `uses` keyword in another workflow:
## CI workflows
### Usage

```yml
name: CI
Expand All @@ -26,7 +25,7 @@ on:
- '*.md'

jobs:
call-reuseable-workflow:
ci:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
```

Expand Down Expand Up @@ -58,7 +57,7 @@ jobs:
lint: true
```

## Inputs
### Inputs

| Input Name | Required | Type | Default | Description |
| ---------------------------------- | ---------- | ------- | --------- | ---------------------------------------------------------------------------------- |
Expand All @@ -67,6 +66,51 @@ jobs:
| `license-check-allowed-additional` | false | string | | Provide a semicolon separated list of SPDX-license identifiers that you want to additionally allow. |
| `lint` | false | boolean | `false` | Set to `true` to run the `lint` script in a repository's `package.json`. |

## Benchmark PR workflow

The benchmark workflow expects `pull_request` or `pull_request_target` events. A common use for this workflow is to run benchmarks when a `benchmark` label is added to the PR.

### Usage

```yml
name: Benchmark PR

on:
pull_request_target:
types:
- labeled

jobs:
benchmark:
if: ${{ github.event.label.name == 'benchmark' }}
uses: fastify/workflows/.github/workflows/plugins-benchmark-pr.yml@main
with:
npm-script: bench

remove-label:
if: "always()"
needs:
- benchmark
runs-on: ubuntu-latest
steps:
- name: Remove benchmark label
uses: octokit/request-action@v2.x
id: remove-label
with:
route: DELETE /repos/{repo}/issues/{issue_number}/labels/{name}
repo: ${{ github.event.pull_request.head.repo.full_name }}
issue_number: ${{ github.event.pull_request.number }}
name: benchmark
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

### Inputs
| Input Name | Required | Type | Default | Description |
| ---------------------------------- | ---------- | ------- | ----------- | ---------------------------------------------------------------------------------- |
| `npm-script` | false | string | `benchmark` | Provide the name of the npm script to run |


## Acknowledgements

Past sponsors:
Expand Down