Skip to content

Commit

Permalink
feat: add a new action to validate contribution to the bonita documen…
Browse files Browse the repository at this point in the history
…tation content (#115)

Create action to validate the contribution follow our documentation
guidelines.

* Adding forbidden pattern check (ex: static link to
https://www.documentation.bontiasoft.com)
* Validate if some attributes are put in updated file (ex: :description:
tag to help us for the SEO)
  • Loading branch information
benjaminParisel authored Oct 19, 2023
1 parent ddfde5f commit 2d675f0
Show file tree
Hide file tree
Showing 19 changed files with 15,495 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Centralized repository providing GitHub Actions developed by Bonitasoft and used

- [list-branches](packages/list-branches): list and return branches in JSON filtered by input regex.
- [notify-slack](packages/notify-slack): send a Slack message.
- [pr-diff-checker](packages/pr-diff-checker): check the diff in a PR, and fail if one or more of the set criteria isn't met.
- [pr-antora-content-guidelines-checker](packages/pr-antora-content-guidelines-checker): to check contributions done to the AsciiDoc content of a repository used to produced documentation generated with Antora. Check the diff of a Pull Request, and fail if one or more of the set criteria isn't met.
- [pr-diff-checker](packages/pr-diff-checker): check the diff in a PR, and fail if one or more of the set criteria isn't met (deprecated, use `pr-antora-content-guidelines-checke` instead).
- [pr-title-conventional-commits](packages/pr-title-conventional-commits): check that the Pull Request title follows guidelines of [Conventional Commits v1.0.0](https://www.conventionalcommits.org/en/v1.0.0/).
- [surge-preview-tools](packages/surge-preview-tools): companion of the [surge-preview action](https://github.com/afc163/surge-preview).

Expand Down
3 changes: 3 additions & 0 deletions packages/pr-antora-content-guidelines-checker/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
34 changes: 34 additions & 0 deletions packages/pr-antora-content-guidelines-checker/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"github"
],
"rules": {
}
}
1 change: 1 addition & 0 deletions packages/pr-antora-content-guidelines-checker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/
1 change: 1 addition & 0 deletions packages/pr-antora-content-guidelines-checker/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
61 changes: 61 additions & 0 deletions packages/pr-antora-content-guidelines-checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# PR Antora content guidelines checker

This action checks the diff in a PR, and fails if one or more of the set criteria isn't met.
If action failed, a comment with details will be written in the Pull Request

## Using this action

See [action.yml](./action.yml) for the detailed list of inputs and outputs.

### Permissions

Set the `pull-requests` permission to `write` to allow the action to post comments on the PR.
Set the `github-token` if you want to use a personal access token, by default the value is `${{ secrets.GITHUB_TOKEN }}`

```
name: Check PR content
on: [pull_request]
jobs:
check_contribution:
runs-on: ubuntu-22.04
permissions:
pull-requests: write # post comments when the Pull Request title doesn't match the "Guidelines" rules
steps:
- name: Check contribution guidelines
uses: bonitasoft/actions/packages/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }} // optional
attributes-to-check: ':description:'
files-to-check: 'adoc'
forbidden-pattern-to-check: 'https://documentation.bonitasoft.com, link:'
```

An example is also provided in [bonita-labs-doc repository](https://github.com/bonitasoft/bonita-labs-doc/blob/master/.github/workflows/check-contribution.yml).

## Steps

### Attributes Checking

For each file updated in the pull request, check if the files contains the value of `forbidden-pattern-to-check` properties and failed if at least one attribute is missing

### Forbidden Pattern

For each file updated in the pull request, check if the files contains the value of `attributes-to-check` properties and failed if pattern is exist.

## Development

**Node version**: see the [.nvmrc](.nvmrc) file

As for all JavaScript actions, the `dist` folder must be committed.

So when changing the JS code or when updating the production dependencies (that are bundled in the final distribution),
please regenerate the content of the `dist` folder.
* Run `npm ci && npm run package:all`
* Commit the dist folder


## License

This is released under the MIT license.
23 changes: 23 additions & 0 deletions packages/pr-antora-content-guidelines-checker/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'PR Antora content guidelines checker'
description: 'Checks files updated on PR are following the contribution guideline for an Antora documentation content.'
inputs:
github-token:
description: 'The token used to create Pull Request comment when the contribution does not follow requirements'
required: false
default: ${{ github.token }}
files-to-check:
description: 'Comma-separated list of file extension to check in the modified files. (ex: adoc, md, txt)`'
required: false
default: 'adoc'
attributes-to-check:
description: 'Comma-separated list of attributes to check in the modified files. (ex: :description:, :alias:), keep empty to skip this check.`'
default: ''
required: false
forbidden-pattern-to-check:
description: 'Comma-separated list of forbidden pattern to check in the modified files. (ex: http://documentation.mydomain,link:), keep empty to skip this check.'
default: ''
required: false

runs:
using: 'node20'
main: 'dist/index.js'
Loading

0 comments on commit 2d675f0

Please sign in to comment.