Skip to content

Commit

Permalink
chore(deps): bump @actions/core from 1.2.7 to 1.3.0 (actions#203)
Browse files Browse the repository at this point in the history
* chore(deps): bump @actions/core from 1.2.7 to 1.3.0

Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.7 to 1.3.0.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>

* feat: switch to YAML boolean for inputs

The parsing is now handled by `@actions/core` package

* docs(README): minor changes

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Federico Grandi <fgrandi30@gmail.com>
  • Loading branch information
dependabot[bot] and EndBug committed May 24, 2021
1 parent bf5e32a commit b2ad943
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 35 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
'prettier/prettier': 'warn',
'no-cond-assign': [2, 'except-parens'],
'no-unused-vars': 0,
'no-redeclare': 0,
'@typescript-eslint/no-unused-vars': 1,
'no-empty': [
'error',
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You can use this GitHub Action to commit changes made in your workflow run direc
This is **heavily** inspired by [git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action) (by [Stefan Zweifel](https://github.com/stefanzweifel)): that action automatically detects changed files and commits them. While this is useful for most situations, this doesn't commit untracked files and can sometimes commit unintended changes (such as `package-lock.json` or similar, that may have happened during previous steps).
This action lets you choose the path that you want to use when adding & committing changes so that it works as you would normally do using `git` on your machine.

## Usage
## Inputs

Add a step like this to your workflow:

Expand Down Expand Up @@ -58,7 +58,7 @@ Add a step like this to your workflow:
# Default: ''
remove: './dir/old_file.js'

# Whether to use the --signoff option on `git commit` (only `true` and `false` are accepted)
# Whether to use the --signoff option on `git commit` (only boolean values accepted*)
# Default: false
signoff: true

Expand All @@ -72,19 +72,19 @@ Add a step like this to your workflow:
Multiple options let you provide the git arguments that you want the action to use. It's important to note that these arguments **are not actually used with a CLI command**, but they are parsed by a package called [`string-argv`](https://npm.im/string-argv), and then used with [`simple-git`](https://npm.im/simple-git).
What does this mean for you? It means that string that contain a lot of nested quotes may be parsed incorrectly, and that specific ways of declaring arguments may not be supported by this libraries. If you're having issues with your argument strings you can check whether they're being parsed correctly either by [enabling debug logging](https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging) for your workflow runs or by testing it directly with `string-argv` ([RunKit demo](https://npm.runkit.com/string-argv)): if each argument and option is aprsed correctly you'll see an array where every string is an option or value.

### Adding files:
### Adding files

The action adds files using a regular `git add` command, so you can put every kind of argument in the `add` option. For example, if you want to force-add a file: `./path/to/file.txt --force`.
The script will not stop if one of the git commands doesn't match any file. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
You can also use JSON or YAML arrays (e.g. `'["first", "second"]'`, `"['first', 'second']"`) to make the action run multiple `git add` commands: the action will log how your input has been parsed. Please mind that your input still needs to be a string because of how GitHub Actions works with inputs: just write your array inside the string, the action will parse it later.

### Deleting files:
### Deleting files

You can delete files with the `remove` option: that runs a `git rm` command that will stage the files in the given path for removal. As with the `add` argument, you can use every option `git rm` allows (e.g. add `--force` to ignore `.gitignore` rules).
The script will not stop if one of the git commands doesn't match any file. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
You can also use JSON or YAML arrays (e.g. `'["first", "second"]'`, `"['first', 'second']"`) to make the action run multiple `git rm` commands: the action will log how your input has been parsed. Please mind that your input still needs to be a string because of how GitHub Actions works with inputs: just write your array inside the string, the action will parse it later.

### Pushing:
### Pushing

By default the action runs the following command: `git push origin ${branch input} --set-upstream`. You can use the `push` input to modify this behavior, here's what you can set it to:

Expand All @@ -95,11 +95,11 @@ By default the action runs the following command: `git push origin ${branch inpu

One way to use this is if you want to force push to a branch of your repo: you'll need to set the `push` input to, for example, `origin yourBranch --force`.

### Tagging:
### Tagging

You can use the `tag` option to enter the arguments for a `git add` command. In order for the action to isolate the tag name from the rest of the arguments, it should be the first word not preceded by an hyphen (e.g. `-a tag-name -m "some other stuff"` is ok).

### Tokens:
### Tokens

When pushing, the action uses the token that the local git repository has been configured with: that means that if you want to change it you'll need to do it in the steps that run before this action. For example: if you set up your repo with [`actions/checkout`](https://github.com/actions/checkout/) then you have to add the token there.
Changing the token with which the repo is configured can be useful if you want to run CI checks on the commit pushed by this action; anyway, it has to be set up outside of this action.
Expand All @@ -117,7 +117,7 @@ Some users reported that they were getting an error:

If you're getting this error and you're using `actions/checkout@v1`, try upgrading to `actions/checkout@v2`. If you're still having problems after upgrading, feel free to open an issue. Issue ref: [#146](https://github.com/EndBug/add-and-commit/issues/146)

### Outputs:
## Outputs

The action provides these outputs:

Expand All @@ -127,7 +127,7 @@ The action provides these outputs:

For more info on how to use outputs, see ["Context and expression syntax"](https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions).

### Examples:
## Examples

If you don't want to use your GitHub username for the CI commits, you can use the `default_author` option to make it appear as if it was made by "github-actions"

Expand Down
6 changes: 3 additions & 3 deletions lib/index.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"homepage": "https://github.com/EndBug/add-and-commit#readme",
"dependencies": {
"@actions/core": "^1.2.7",
"@actions/core": "^1.3.0",
"actions-toolkit": "github:EndBug/actions-toolkit#core-actions",
"js-yaml": "^4.1.0",
"simple-git": "^2.27.0",
Expand Down
22 changes: 15 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
log,
matchGitArgs,
outputs,
parseBool,
readJSON,
setOutput
} from './util'
Expand Down Expand Up @@ -105,7 +104,12 @@ core.info(`Running in ${baseDir}`)
.catch((err) => core.setFailed(err))
} else core.info('> No tag info provided.')

const pushOption = parseBool(getInput('push')) ?? getInput('push')
let pushOption: string | boolean
try {
pushOption = getInput('push', true)
} catch {
pushOption = getInput('push')
}
if (pushOption) {
// If the options is `true | string`...
core.info('> Pushing commit to repo...')
Expand Down Expand Up @@ -301,7 +305,7 @@ async function checkInputs() {

// #region signoff
if (getInput('signoff')) {
const parsed = parseBool(getInput('signoff'))
const parsed = getInput('signoff', true)

if (parsed === undefined)
throw new Error(
Expand All @@ -328,11 +332,15 @@ async function checkInputs() {
// #region push
if (getInput('push')) {
// It has to be either 'true', 'false', or any other string (use as arguments)
const parsed = parseBool(getInput('push'))
let value: string | boolean

core.debug(
`Current push option: '${getInput('push')}' (parsed as ${typeof parsed})`
)
try {
value = getInput('push', true)
} catch {
value = getInput('push')
}

core.debug(`Current push option: '${value}' (parsed as ${typeof value})`)
}
// #endregion

Expand Down
12 changes: 4 additions & 8 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const outputs: Record<Output, 'true' | 'false'> = {
tagged: 'false'
}

export function getInput(name: Input) {
export function getInput(name: Input, bool: true): boolean
export function getInput(name: Input, bool?: false): string
export function getInput(name: Input, bool = false) {
if (bool) return core.getBooleanInput(name)
return tools.inputs[name] || ''
}

Expand Down Expand Up @@ -92,13 +95,6 @@ export function matchGitArgs(string: string) {
return parsed
}

export function parseBool(value: any) {
try {
const parsed = JSON.parse(value)
if (typeof parsed == 'boolean') return parsed
} catch {}
}

export function readJSON(filePath: string) {
let fileContent: string
try {
Expand Down

0 comments on commit b2ad943

Please sign in to comment.