Skip to content

Commit

Permalink
feat: restructured input params (#67)
Browse files Browse the repository at this point in the history
* feat: restructured input params

* fix: debug log

* fix: fixed checks condition

* feat: added file loading capability

* chore: added group and updated documentation

* chore: refactored input

* fix: fixed input
  • Loading branch information
saurav0705 authored Mar 24, 2024
1 parent d2afb6f commit 9ea3cfc
Show file tree
Hide file tree
Showing 12 changed files with 552 additions and 226 deletions.
166 changes: 115 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,81 +17,146 @@ Ensure that you have these dependencies installed or included in your workflow e

## Inputs

You can provide input directly to the file or you can provide a config file

### DIRECT INPUT

#### This is to check file

```yaml
# This is to check file
- name: Check Changed File
uses: saurav0705/check-history-action@v1
id: check-changed-file
with:
GIT_TOKEN: ${{secrets.GIT_SECRET}}
KEYS: |
- key: android-lint
pattern: android/**
- key: android-detekt
pattern: android/**
- name: Check Changed File
uses: saurav0705/check-history-action@v1
id: check-changed-file
with:
GIT_TOKEN: ${{secrets.GIT_SECRET}}
CONFIG: |
disable: false // disables the check
comment:
disable: false // disables the PR comment
retentionDays: 30 // artifact which contains the PR comment info if not given is set to 30 days
checks:
- key: name
pattern:
- PATH_1
- PATH_2
disbale: false // disable individual check
disableInComment: false // does not post status in message
```
or
```yaml
# .github/config.yml
disable: false // disables the check
comment:
disable: false // disables the PR comment
retentionDays: 30 // artifact which contains the PR comment info if not given is set to 30 days
checks:
- key: name
pattern:
- PATH_1
- PATH_2
disbale: false // disable individual check
disableInComment: false // does not post status in message

# check.yml
- name: Check Changed File
uses: saurav0705/check-history-action@v1
id: check-changed-file
with:
GIT_TOKEN: ${{secrets.GIT_SECRET}}
CONFIG: ./.github/config.yml
```
#### This is to Upload Artifact
```yml
# This will be consumed by the job
- name: Check Changed File
uses: saurav0705/check-history-action@v1
id: check-changed-file
with:
GIT_TOKEN: ${{secrets.GIT_SECRET}}
# if UPLOAD_KEYS is present KEYS will be ignored
UPLOAD_KEY: JOB_NAME_1
ARTIFACT_RETENTION_DAYS: '30' #default it is set to 30
- name: Check Changed File
uses: saurav0705/check-history-action@v1
id: check-changed-file
with:
GIT_TOKEN: ${{secrets.GIT_SECRET}}
UPLOAD: |
key: JOB_NAME
retentionDays : 30 #default it is set to 30
```
### `GIT_TOKEN` (required)
### `GIT_TOKEN`

The GitHub token used to authenticate API requests. You can use the `{{ secrets.GITHUB_TOKEN }}` token available in your workflow without any additional setup.

### `KEYS` (required)
This is the key in which we mention the workflow name and pattern that we want to match which are seperated by `,`.
### `CONFIG` (required)

## Explanation of Configuration

### `UPLOAD_KEY` (required)
This is required when you want to update the successful run of a job.
### Disable Settings

### `DISABLE_CHECK`
This is used if you want to disable check then all the keys that are provided will have shouldRun as `true`.
- **disable**: `boolean`
- Description: This setting controls the overall disabling of the action.
- Value: `false` indicates that the feature is enabled and is default value.

### `DISABLE_PR_COMMENT`
This is used if you want to disable pr comment if this is truned as `true` this action will not post the comment.
### Comment Settings

### `ARTIFACT_RETENTION_DAYS`
This is used to set artifact retention days while logging a successful run and will be consumed when `UPLOAD_KEYS` is given.
- **disable**: `false`
- Description: This sub-setting under `comment` controls the disabling of pr commenting functionality.
- Value: `false` indicates that commenting functionality is enabled which is default.
- **retentionDays**: `30`
- Description: This sub-setting specifies the retention period for pr comment.
- Value: `30` indicates comments will be retained for 30 days which is bt default.

### Checks

- **key**: `string`
- Description: This setting specifies a key which is identify against which check you are running the checks.
- **pattern**:
- Description: This setting defines the pattern against which checks will be applied.
- Value: `/file/pattern` represents the picomatch expression pattern used for matching.

### `UPLOAD`

- **key**: `string`
- Description: This setting specifies a key which is identify against which check you are uploading the `sha`.
- **retentionDays**:
- Description: This setting defines the pattern against which checks will be applied.
- Value: `/file/pattern` represents the picomatch expression pattern used for matching.

## Outputs

This Return a `status` object in which the following are present

```json
{
"job_1" : {
"shouldRun" : true, // boolean
"key" : "job_1-{pr-number}", // string
"suppliedKey" : "job_1", // string
"filesRegex" : "regex", // string
"sha":"some-sha", // string
"diffFiles" : [ "file-1","file-2" ] // Array<string>
}
"job_1": {
"shouldRun": true, // boolean
"key": "job_1-{pr-number}", // string
"suppliedKey": "job_1", // string
"filesRegex": "regex", // string
"sha": "some-sha", // string
"diffFiles": ["file-1", "file-2"] // Array<string>
}
}
```

### `shouldRun`

It's a boolean which tell if these 2 commits have pattern matching file change.

### `key`

It's a string which is the job key for which this is fetched appended with pr number.

### `filesRegex`

It's a string which is the regex for file path match.

### `sha`

sha for last successful run.

### `diffFiles`
Array of files that has been changed between current and last successfull sha.

Array of files that has been changed between current and last successfull sha.

## Usage

Expand All @@ -107,26 +172,26 @@ jobs:
setup:
runs-on: ubuntu-latest
outputs:
JOB_NAME : ${{steps.changed-files.outputs.JOB_NAME}}
JOB_NAME : ${{steps.changed-files.outputs.JOB_NAME}}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '20'
- name: Run Check Changed Files
id: changed-files
uses: saurav0705/check-history-action@v1
with:
GIT_TOKEN: ${{secrets.GIT_SECRET}}
KEYS: |
- key: android-lint
pattern: android/**
- key: android-detekt
pattern: android/**
CONFIG: |
checks
- key: JOB_NAME
pattern:
- file/pattern/match
- name: Print status
run: echo "Action status: ${{ steps.regex_commenter.outputs.status }}"
Expand All @@ -142,7 +207,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '20'
- name: Install Dependencies
run: do something
Expand All @@ -151,12 +216,11 @@ jobs:
uses: saurav0705/check-history-action@v1
with:
GIT_TOKEN: ${{secrets.GIT_SECRET}}
UPLOAD_KEY: JOB_NAME
ARTIFACT_RETENTION_DAYS: '30'
UPLOAD: |
name: JOB_NAME
retentionDays : 30
```


## Support

For any questions or issues regarding this GitHub Action, please open an issue in the repository.
43 changes: 23 additions & 20 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,36 @@ name: 'Check History Action'
description: 'Compare commits with file Regex and shows status if it should run the check or not'
author: 'saurav0705'
inputs:
KEYS:
required: false
description: 'Define key and regex pattern that needs to be fetched'
default: ''
GIT_TOKEN:
required: true
description: 'GITHUB TOKEN FOR THE REPO'
default: ''
UPLOAD_KEY:
required: false
description: 'GITHUB TOKEN FOR THE REPO'
default: ${{github.token}}
UPLOAD:
description: This is required to publish the successful sha to repo varaible
DISABLE_PR_COMMENT:
default: 'false'
required: false
description: This is used to turn off the pr comment which is published by action
DISABLE_CHECK:
default: 'false'
required: false
description: This is used to turn off the action
ARTIFACT_RETENTION_DAYS:
default: '30'
required: false
description: This is used to define artifact upload days
default: ''
CONFIG:
required: true
description: |
// This is the config for the action it can take either file path or you can directly pass the config which follows the below structure
./.github/config.yml
OR
disable: false // disables the check
comment:
disable: false // disables the PR comment
retentionDays: 30 // artifact which contains the PR comment info if not given is set to 30 days
checks:
- key: name
pattern:
- PATH_1
- PATH_2
disbale: false // disable individual check
disableInComment: false // does not post status in message
default: ''

branding:
icon: cloud-lightning
color: blue
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
Loading

0 comments on commit 9ea3cfc

Please sign in to comment.