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
88 changes: 0 additions & 88 deletions .github/workflows/build-lint-pr.yml

This file was deleted.

5 changes: 1 addition & 4 deletions .github/workflows/lint-pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- id: lint-pr-title
uses: ./actions/lint-pr-title
with:
config-path: "${{ github.workspace }}/actions/lint-pr-title/commitlint.config.js"
env:
GITHUB_TOKEN: ${{ github.token }}
38 changes: 38 additions & 0 deletions .github/workflows/test-lint-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Lint & test "Lint PR title" action
on:
push:
branches:
- main
paths:
- .github/workflows/test-lint-pr-title.yml
- actions/lint-pr-title/**
pull_request:
paths:
- .github/workflows/test-lint-pr-title.yml
- actions/lint-pr-title/**
merge_group:

jobs:
build-lint-pr-title:
runs-on: ubuntu-latest

defaults:
run:
working-directory: actions/lint-pr-title

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Install bun package manager
uses: oven-sh/setup-bun@4bc047ad259df6fc24a6c9b0f9a0cb08cf17fbe5 # v2.0.1
with:
bun-version-file: "actions/lint-pr-title/package.json"

- name: Install lint-pr-title dependencies
run: bun install --frozen-lockfile

- name: Lint
run: bun lint

- name: Test
run: bun test
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Owned by the Grafana department's Infra O11y Frontend squad
.github/workflows/build-lint-pr.yml @grafana/infra-o11y-frontend
/actions/lint-pr-title/ @grafana/infra-o11y-frontend
/actions/lint-pr-title/ @grafana/infra-o11y-frontend @grafana/platform-productivity

# Platform CAT
/actions/generate-openapi-clients @grafana/platform-cat
Expand Down
5 changes: 5 additions & 0 deletions actions/lint-pr-title/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ yarn-error.log*

node_modules/

coverage/
dist/

.*.bun-build

# Editor
.idea
29 changes: 29 additions & 0 deletions actions/lint-pr-title/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM oven/bun:1.1.27 AS base
WORKDIR /usr/src/app

FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# Install dev dependencies to run the tests
ENV NODE_ENV=development
RUN bun install --frozen-lockfile --dev
RUN bun run test
RUN bun run build

FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/index.ts .
COPY --from=prerelease /usr/src/app/package.json .

ENTRYPOINT [ "bun", "run", "index.ts" ]
97 changes: 45 additions & 52 deletions actions/lint-pr-title/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
# Lint pull request title

This is a [Github Action](https://github.com/features/actions) that ensures that your PR title matches the [Commitlint Spec](https://github.com/conventional-changelog/commitlint) according to the configuration file.
This is a [GitHub Action][github-action] that ensures compliance with the
[Commitlint Spec][commitlint-spec] according to the given configuration file.

This is helpful when using the "Squash and merge" strategy, Github will suggest to use the PR title as the commit message. With this action you can validate that the PR title will lead to a correct commit message.
Despite its name, this action supports validating pull request titles and
commits in merge queues. It also supports validating the _body_ of the commit
message too, not only the title.

## Build
[github-action]: https://github.com/features/actions
[commitlint-spec]: https://github.com/conventional-changelog/commitlint

If you make any change on the `index.js` file, you should build the code before to commit the changes using the command:
## Pull Requests

```console
yarn build
```
This is helpful when using the "Squash and merge" strategy; GitHub will suggest
using the PR title as the commit message. With this action, you can validate
that the PR title will lead to a correct commit message.

## Merge queues

This action can also be used in merge queues to ensure that the commit messages
which will be merged into the main branch are compliant with the commitlint spec
and the project's configuration. When a project is using merge queues, it is the
commits in the merge queue branches which will be merged into the main branch,
so these are the commits that need to be validated.

## Inputs

| Name | Description | Default | Required |
| ------------- | ------------------------------------------------------------------------------------ | ------------------------ | -------- |
| `config-path` | Path to the commitlint configuration file, relative to the action's directory. | `./commitlint.config.js` | No |
| `title-only` | Check only the PR/commit title. If false, it will check the whole PR/commit message. | `true` | No |

## Validation

Expand All @@ -21,9 +40,14 @@ Examples for valid PR titles:

### The commit config

This action can receive the `commitlint.config.js` file using the input parameter `config-path`.
This parameter should contain the absolute path of the file.
So, it's recommended to start the path definition with `${{ github.workspace }}/`. See example below:
This action can receive a reference to a `commitlint.config.js` file using the
input parameter `config-path`. See the [commitlint documentation][docs] for
information on all of the options which can be set. This parameter is resolved
relative to the action's directory. It's recommended to start the path
definition with `${{ github.workspace }}/` to enable local configuration to be
found.

See example below:

```yml
---
Expand All @@ -32,67 +56,38 @@ with:
config-path: "${{ github.workspace }}/dir1/dir2/commitlint.config.js"
```

but this `config-path` parameter is optional. If you don't want to define it, the action will use the following rules by default:

```javascript
module.exports = {
"body-leading-blank": [1, "always"],
"body-max-line-length": [2, "always", 100],
"footer-leading-blank": [1, "always"],
"footer-max-line-length": [2, "always", 100],
"header-max-length": [2, "always", 100],
"subject-case": [
2,
"never",
["sentence-case", "start-case", "pascal-case", "upper-case"],
],
"subject-empty": [2, "never"],
"subject-full-stop": [2, "never", "."],
"type-case": [2, "always", "lower-case"],
"type-empty": [2, "never"],
"type-enum": [
2,
"always",
[
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"style",
"test",
],
],
};
```
but this `config-path` parameter is optional. By default, the action will use
the [`commitlint.config.js` file located in this directory][config].

[config]: ./commitlint.config.js
[docs]: https://commitlint.js.org/reference/configuration.html

## Example workflows

### Example with config path defined:

In this example the `commitlint.config.js` file is located in the root directory from where the action is being executed.
In this example the `commitlint.config.js` file is located in the root directory
of the project which is being linted.

```yml
name: Lint PR title

on:
pull_request:
types: [opened, edited, synchronize]
merge_group:
types: [checks_requested]
jobs:
lint-pr-title:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- id: lint-pr-title
uses: grafana/shared-workflows/actions/lint-pr-title@main
with:
config-path: "${{ github.workspace }}/commitlint.config.js"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
title-only: false
```

## Example without config path:
Expand All @@ -109,6 +104,4 @@ jobs:
steps:
- id: lint-pr-title
uses: grafana/shared-workflows/actions/lint-pr-title@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
36 changes: 33 additions & 3 deletions actions/lint-pr-title/action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
name: Lint pull request title using Javascript
description: Run lint on the PR title to check if It matches the commitlint specification.

inputs:
config-path:
description: "Absolute path for the commitlint configuration file"
default: "./commitlint.config.js"
description: "Path to the commitlint configuration file, relative to the action's directory."
required: false

title-only:
default: "true"
description: "Check only the PR/commit title. If false, it will check the whole PR/commit message."
required: false

runs:
using: "node20"
main: "dist/index.js"
using: "composite"
steps:
- name: Install bun package manager
uses: oven-sh/setup-bun@4bc047ad259df6fc24a6c9b0f9a0cb08cf17fbe5 # v2.0.1
with:
bun-version-file: "./package.json"

- name: Install dependencies
shell: sh
working-directory: ${{ github.action_path }}
run: |
bun install --frozen-lockfile --production

- name: Lint PR title
shell: sh
working-directory: ${{ github.action_path }}
env:
GITHUB_TOKEN: ${{ github.token }}
INPUT_CONFIG_PATH: ${{ inputs.config-path }}
INPUT_TITLE_ONLY: ${{ inputs.title-only }}
NODE_ENV: "production"
run: |
bun run src/index.ts

branding:
icon: "shield"
color: "green"
Binary file added actions/lint-pr-title/bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion actions/lint-pr-title/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
extends: ["@commitlint/config-conventional"],
rules: {
"body-leading-blank": [1, "always"],
Expand Down
Loading
Loading