Skip to content

Commit

Permalink
Merge pull request #37 from thehanimo/dev
Browse files Browse the repository at this point in the history
Release v1.4.0
  • Loading branch information
thehanimo authored Jun 2, 2023
2 parents 106ccc8 + 930cc2d commit 0cf5902
Show file tree
Hide file tree
Showing 13 changed files with 7,461 additions and 64,189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# `index.js` is the code that will run.
# For our project, we generate this file through a build process from other source files.
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
name: Check dist/
name: Check release drift

on:
push:
Expand All @@ -17,23 +17,19 @@ on:
workflow_dispatch:

jobs:
check-dist:
check-release-drift:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set Node.js 16.x
- name: Set Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install dependencies
run: npm i

- name: Rebuild the dist/ directory
run: npm run prepare

- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
Expand All @@ -42,8 +38,7 @@ jobs:
exit 1
fi
id: diff

# If index.js was different than expected, upload the expected version as an artifact
# If index.js was different than expected, upload the unexpected version as an artifact
- uses: actions/upload-artifact@v2
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
Expand Down
66 changes: 58 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ If at least one of them passes, the label will be removed.

This action causes CI tests to fail by default. However, if you do not want CI tests failing just because of this action, simply set `alwaysPassCI` as true in the CHECKS field. **An invalid config file will always cause the action to fail.**

Also, adding label names to the optional `ignoreLabels` field will forfeit any checks for PRs with those labels.
Adding label names to the optional `ignoreLabels` field will forfeit any checks for PRs with those labels.

The config file is always pulled from the action's context, i.e., the branch from which the pull request is made.

See [other ways to specify config file.](#other-ways-to-specify-config-file)

## Create Workflow

Create a workflow (eg: `.github/workflows/pr-title-checker.yml` see [Creating a Workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file)) to utilize the pr-title-checker action with content:
Create a workflow file (eg: `.github/workflows/pr-title-checker.yml`) with the following content:

```yaml
name: "PR Title Checker"
Expand All @@ -58,14 +62,60 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: thehanimo/pr-title-checker@v1.3.7
- uses: thehanimo/pr-title-checker@v1.4.0
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pass_on_octokit_error: false
configuration_path: ".github/pr-title-checker-config.json"
configuration_path: .github/pr-title-checker-config.json #(optional. defaults to .github/pr-title-checker-config.json)
```
NOTE:
* [`pull_request_target`](https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#pull_request_target) event trigger should be used (not [`pull_request`](https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#pull_request)) in order to support checking PRs from forks. This was added in `v1.3.2`. See [#8](https://github.com/thehanimo/pr-title-checker/issues/8).
* `pass_on_octokit_error` is an optional input which defaults to false. Setting it to true will prevent the CI from failing when an octokit error occurs. This is useful when the environment this action is run in is not consistent. For e.g, it could be a missing GITHUB_TOKEN. Thanks to [@bennycode](https://github.com/bennycode) for pointing this out.
* `configuration_path` is also an optional input which defaults to `".github/pr-title-checker-config.json"`. If you wish to store your config file elsewhere, pass in the path here.
To learn more about workflows, see [Create an example workflow.](https://docs.github.com/en/actions/using-workflows/about-workflows#create-an-example-workflow)
## Other ways to specify config file
### 1. Remote URL to a valid JSON file
```yaml
...
steps:
- uses: thehanimo/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pass_on_octokit_error: false
remote_configuration_path: "https://raw.githubusercontent.com/grpc/grpc/master/.github/pr_title_checker_config.json"
...
```
Note that this has to be a url pointing to a valid, raw json file. See [#28](https://github.com/thehanimo/pr-title-checker/issues/28)

### 2. Config file in a GitHub repo
```yaml
...
steps:
- uses: thehanimo/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pass_on_octokit_error: false
github_configuration_owner: RocketChat #(optional. defaults to the owner of the repo in which the action is run)
github_configuration_repo: Rocket.Chat #(optional. defaults to the repo in which the action is run)
github_configuration_path: .github/pr-title-checker-config.json #(optional. defaults to .github/pr-title-checker-config.json)
github_configuration_ref: <named branch, tag, or SHA> #(optional. defaults to the latest commit on the default branch or, if the repo specified is the same as the one on which the action is running, it defaults to the current context's sha)
github_configuration_token: ${{ secrets.YOUR_TOKEN }} #(optional. defaults to GITHUB_TOKEN)
...
```

### 3. Config file in the local file system of the action
```yaml
...
steps:
- uses: thehanimo/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pass_on_octokit_error: false
local_configuration_path: .github/actions/enforce-pr-titles/config.json
...
```
This is useful if a repo containing the config file is pulled in a previous step using, for e.g., actions/checkout. See [#36](https://github.com/thehanimo/pr-title-checker/issues/36)


## NOTE:
* [`pull_request_target`](https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#pull_request_target) event trigger should be used (not [`pull_request`](https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#pull_request)) in order to support checking PRs from forks. This was added in `v1.3.2`. See [#8.](https://github.com/thehanimo/pr-title-checker/issues/8)
* `pass_on_octokit_error` is an optional input which defaults to false. Setting it to true will prevent the CI from failing when an octokit error occurs. This is useful when the environment this action is run in is not consistent. For e.g, it could be a missing GITHUB_TOKEN. Thanks to [@bennycode](https://github.com/bennycode) for pointing this out.
41 changes: 31 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
name: "PR Title Checker"
description: "Checks if the PR Title follows contribution guidelines."
name: PR Title Checker
description: Checks if the PR Title follows contribution guidelines
branding:
icon: "tag"
color: "purple"
on: [pull_request]
icon: tag
color: purple
inputs:
GITHUB_TOKEN:
description: Override GitHub Token
required: false
pass_on_octokit_error:
description: "force CI to pass if an octokit error (e.g. missing GITHUB_TOKEN) occurs"
description: force CI to pass if an octokit error (e.g. missing GITHUB_TOKEN) occurs
default: false
configuration_path:
description: "config file path"
default: ".github/pr-title-checker-config.json"
description: config file path
default: .github/pr-title-checker-config.json
local_configuration_path:
description: use a local configuration file present in file system of the instance running the action
required: false
remote_configuration_url:
description: pull local configuration file from the internet using the url provided
required: false
github_configuration_owner:
description: the owner of the repo in which the config file is present. defaults to the owner of the repo in which the action is run
required: false
github_configuration_repo:
description: the repo in which the config file is present. defaults to the repo in which the action is run
required: false
github_configuration_path:
description: the path to the config file in the github repo. defaults to .github/pr-title-checker-config.json
required: false
github_configuration_ref:
description: the named branch, tag, or SHA from which the config file is pulled. defaults to the latest commit on the default branch
required: false
github_configuration_token:
description: the github access token to be used to access the config file using other github_configuration_* parameters. can differ from GITHUB_TOKEN. defaults to GITHUB_TOKEN
required: false
runs:
using: "node16"
main: "dist/index.js"
using: node16
main: dist/index.js
Loading

0 comments on commit 0cf5902

Please sign in to comment.