Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bf921b386 | ||
|
|
beedcea439 | ||
|
|
6cb111a771 | ||
|
|
6a4387c9c9 | ||
|
|
132aa0f637 | ||
|
|
7dbb54bce3 | ||
|
|
7f1289bf4a | ||
|
|
88d475f304 | ||
|
|
98f4b8018b | ||
|
|
2f6a78549b | ||
|
|
9cd727829f | ||
|
|
f0fcdb07a3 | ||
|
|
5ead79aef9 | ||
|
|
72da43cf1b | ||
|
|
9eb0d21b0d | ||
|
|
2db75722ce | ||
|
|
68d0f64f6f | ||
|
|
d1cfc165c7 | ||
|
|
5f12f937cb | ||
|
|
2d77fa2c79 | ||
|
|
f6b13bc7e9 | ||
|
|
116c918fd3 | ||
|
|
fbbcae9aa5 | ||
|
|
7bd2b1ca10 | ||
|
|
61d14d1bee | ||
|
|
6a75638ec3 | ||
|
|
ff38b6c4a6 | ||
|
|
e67ce7f439 | ||
|
|
a83118880c | ||
|
|
a28158a63f | ||
|
|
30030e85c0 | ||
|
|
79fa1f9f98 | ||
|
|
06fd39b8b7 | ||
|
|
f278ec6d47 | ||
|
|
5a3f4c1c24 | ||
|
|
602bf4ea71 | ||
|
|
5148cf0f38 | ||
|
|
12febc42d8 | ||
|
|
de8a121ebd | ||
|
|
a2b49385e8 | ||
|
|
ea7cddff4f | ||
|
|
9acdb7d7f4 | ||
|
|
6d08b4f153 | ||
|
|
925751a406 | ||
|
|
d3ccc660f4 | ||
|
|
4d5fbad9c9 | ||
|
|
aa1a8cef82 | ||
|
|
df80e1746f | ||
|
|
e6702dc457 |
16
.github/workflows/build.yml
vendored
16
.github/workflows/build.yml
vendored
@@ -3,6 +3,9 @@ on:
|
||||
push:
|
||||
branches-ignore:
|
||||
- dist
|
||||
paths:
|
||||
- src/**
|
||||
- .github/workflows/build.yml
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -10,12 +13,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@master
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@master
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12.0.0
|
||||
node-version: 12.x
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
@@ -24,11 +27,10 @@ jobs:
|
||||
run: npm run build
|
||||
|
||||
- name: Commit changes
|
||||
uses: EndBug/add-and-commit@v2.3.0
|
||||
uses: EndBug/add-and-commit@v4.0.0
|
||||
with:
|
||||
force: true
|
||||
message: "[auto] Update compiled version"
|
||||
path: lib
|
||||
pattern: "*.js"
|
||||
add: lib
|
||||
force: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
2
.github/workflows/versioning.yml
vendored
2
.github/workflows/versioning.yml
vendored
@@ -2,7 +2,7 @@ name: Keep the versions up-to-date
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
types: [published, edited]
|
||||
|
||||
jobs:
|
||||
actions-tagger:
|
||||
|
||||
116
README.md
116
README.md
@@ -1,64 +1,68 @@
|
||||
# Add & Commit
|
||||
|
||||
You can use this GitHub Action to commit changes made in your workflow run directly to your repo: for example, you use it to lint your code, update documentation, commit updated builds and so on...
|
||||
You can use this GitHub Action to commit changes made in your workflow run directly to your repo: for example, you use it to lint your code, update documentation, commit updated builds, etc....
|
||||
|
||||
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.
|
||||
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
|
||||
|
||||
Add a step like this to your workflow:
|
||||
|
||||
```yaml
|
||||
- name: Commit changes # This is the step name that will be displayed in your runs
|
||||
uses: EndBug/add-and-commit@v2 # You can change this to use a specific version
|
||||
with: # See more info about inputs below
|
||||
- uses: EndBug/add-and-commit@v4 # You can change this to use a specific version
|
||||
with:
|
||||
# The arguments for the `git add` command (see the paragraph below for more info)
|
||||
# Default: '.'
|
||||
add: 'src'
|
||||
|
||||
# The name of the user that will be displayed as the author of the commit
|
||||
# Default: author of the commit that triggered the run
|
||||
author_name: Your Name
|
||||
|
||||
# The email of the user that will be displayed as the author of the commit
|
||||
# Default: author of the commit that triggered the run
|
||||
author_email: mail@example.com
|
||||
message: "Your commit message"
|
||||
path: "."
|
||||
pattern: "*.js"
|
||||
force: false
|
||||
|
||||
# The local path to the directory where your repository is located. You should use actions/checkout first to set it up
|
||||
# Default: '.'
|
||||
cwd: './path/to/the/repo'
|
||||
|
||||
# Whether to use the --force option on `git add`, in order to bypass eventual gitignores
|
||||
# Default: false
|
||||
force: true
|
||||
|
||||
# The message for the commit
|
||||
# Default: 'Commit from GitHub Actions'
|
||||
message: 'Your commit message'
|
||||
|
||||
# The arguments for the `git rm` command (see the paragraph below for more info)
|
||||
# Default: ''
|
||||
remove: "./dir/old_file.js"
|
||||
|
||||
env:
|
||||
# This is necessary in order to push a commit to the repo
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
|
||||
```
|
||||
|
||||
### Inputs:
|
||||
|
||||
- `author_name` : the name of the user that will be displayed as the author of the commit, defaults to the author of the commit that triggered the run
|
||||
- `author_email` : the email of the user that will be displayed as the author of the commit, defaults to the author of the commit that triggered the run
|
||||
- `message` : the message for the commit
|
||||
- `path` : the path(s) to stage files from
|
||||
- `pattern` : the pattern that matches file names
|
||||
- `force` : whether to use the force option on git add, in order to bypass eventual gitignores
|
||||
|
||||
### Environment variables:
|
||||
|
||||
The only `env` variable required is the token for the action to run: GitHub generates one automatically, but you need to pass it through `env` to make it available to actions. You can find more about `GITHUB_TOKEN` [here](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret).
|
||||
With that said, you can just copy the example line and don't worry about it. If you do want to use a different token you can pass that in, but I wouldn't see any possible advantage in doing so.
|
||||
That said, you can just copy the example line and not worry about it. If you do want to use a different token you can pass that in, but I wouldn't see any possible advantage in doing so.
|
||||
|
||||
### 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 don't want it to use a recursive behavior: `$(find . -maxdepth 1 -name *.js)`.
|
||||
The script will not stop if one of the git commands fails. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
|
||||
|
||||
### Deleting files:
|
||||
|
||||
This action only **adds** files so in order to commit a file deletion you need to stage that separately: for that, you can run `git rm` in a previous step. Here's a quick example:
|
||||
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.
|
||||
The script will not stop if one of the git commands fails. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
|
||||
|
||||
```yaml
|
||||
- run: git rm delete_me.txt
|
||||
### Examples:
|
||||
|
||||
- uses: EndBug/add-and-commit@v2
|
||||
with:
|
||||
author_name: Your Name
|
||||
author_email: mail@example.com
|
||||
message: "Remove file"
|
||||
path: "."
|
||||
pattern: "*.js" # The path is not important, the file will get removed anyway: that means you can still use the action as usual
|
||||
force: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
### Example:
|
||||
|
||||
You want to lint your JavaScript files, located in the `src` folder, with ESLint so that fixable changes are done without your intervention. You can use a workflow like this:
|
||||
Do you want to lint your JavaScript files, located in the `src` folder, with ESLint, so that fixable changes are done without your intervention? You can use a workflow like this:
|
||||
|
||||
```yaml
|
||||
name: Lint source code
|
||||
@@ -70,7 +74,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v1
|
||||
@@ -84,17 +88,47 @@ jobs:
|
||||
run: eslint "src/**" --fix
|
||||
|
||||
- name: Commit changes
|
||||
uses: EndBug/add-and-commit@v2
|
||||
uses: EndBug/add-and-commit@v4
|
||||
with:
|
||||
author_name: Your Name
|
||||
author_email: mail@example.com
|
||||
message: "Your commit message"
|
||||
path: "."
|
||||
pattern: "*.js"
|
||||
add: "*.js"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
If you need to run the action on a repository that is not located in [`$GITHUB_WORKSPACE`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables), you can use the `cwd` option: the action uses a `cd` normal command, so the path should follow bash standards.
|
||||
|
||||
```yaml
|
||||
name: Use a different repository directory
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
run:
|
||||
name: Add a text file
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
# If you need to, you can check out your repo to a different location
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
path: "./pathToRepo/"
|
||||
|
||||
# You can make whatever type of change to the repo...
|
||||
- run: echo "123" > ./pathToRepo/file.txt
|
||||
|
||||
# ...and then use the action as you would normally do, but providing the path to the repo
|
||||
- uses: EndBug/add-and-commit@v4
|
||||
with:
|
||||
message: "Add the very useful text file"
|
||||
add: "*.txt"
|
||||
cwd: "./pathToRepo/"
|
||||
force: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This action is distributed under the MIT license, check the [license](LICENSE) for more info.
|
||||
|
||||
20
action.yml
20
action.yml
@@ -2,12 +2,20 @@ name: Add & Commit
|
||||
description: Add & commit files from a path directly from GitHub Actions
|
||||
|
||||
inputs:
|
||||
add:
|
||||
description: Arguments for the git add command
|
||||
required: false
|
||||
default: "."
|
||||
author_name:
|
||||
description: The name of the user that will be displayed as the author of the commit
|
||||
required: false
|
||||
author_email:
|
||||
description: The email of the user that will be displayed as the author of the commit
|
||||
required: false
|
||||
cwd:
|
||||
description: The directory where your repository is located. You should use actions/checkout first to set it up
|
||||
required: false
|
||||
default: "."
|
||||
force:
|
||||
description: Whether to use the force option on git add, in order to bypass eventual gitignores
|
||||
required: false
|
||||
@@ -16,18 +24,14 @@ inputs:
|
||||
description: The message for the commit
|
||||
required: false
|
||||
default: Commit from GitHub Actions
|
||||
path:
|
||||
description: The path to stage files from
|
||||
remove:
|
||||
description: Arguments for the git rm command
|
||||
required: false
|
||||
default: "."
|
||||
pattern:
|
||||
description: The pattern that mathces file names
|
||||
required: false
|
||||
default: "*.*"
|
||||
default: ""
|
||||
|
||||
runs:
|
||||
using: node12
|
||||
main: lib/main.js
|
||||
main: lib/index.js
|
||||
|
||||
branding:
|
||||
icon: git-commit
|
||||
|
||||
79
lib/entrypoint.sh
Executable file
79
lib/entrypoint.sh
Executable file
@@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
|
||||
echo "::group::Internal logs"
|
||||
|
||||
cd $INPUT_CWD
|
||||
echo "Running in $PWD."
|
||||
|
||||
# Set up .netrc file with GitHub credentials
|
||||
git_setup() {
|
||||
cat <<-EOF >$HOME/.netrc
|
||||
machine github.com
|
||||
login $GITHUB_ACTOR
|
||||
password $GITHUB_TOKEN
|
||||
|
||||
machine api.github.com
|
||||
login $GITHUB_ACTOR
|
||||
password $GITHUB_TOKEN
|
||||
EOF
|
||||
chmod 600 $HOME/.netrc
|
||||
git config --global user.email "$INPUT_AUTHOR_EMAIL"
|
||||
git config --global user.name "$INPUT_AUTHOR_NAME"
|
||||
}
|
||||
|
||||
add() {
|
||||
if $INPUT_FORCE; then f=-f; else f=; fi
|
||||
git add $INPUT_ADD $f
|
||||
}
|
||||
|
||||
remove() {
|
||||
if [ -n "$INPUT_REMOVE" ]; then git rm $INPUT_REMOVE; fi
|
||||
}
|
||||
|
||||
# This is needed to make the check work for untracked files
|
||||
echo "Staging files..."
|
||||
add
|
||||
remove
|
||||
|
||||
echo "Checking for uncommitted changes in the git working tree..."
|
||||
# This section only runs if there have been file changes
|
||||
if ! git diff --cached --quiet --exit-code; then
|
||||
git_setup
|
||||
|
||||
git fetch
|
||||
|
||||
# Verify if the branch needs to be created
|
||||
if ! git rev-parse --verify --quiet "${GITHUB_REF:11}"; then
|
||||
echo "Creating branch..."
|
||||
git branch "${GITHUB_REF:11}"
|
||||
fi
|
||||
|
||||
# Switch to branch from current workflow run
|
||||
echo "Switching branch..."
|
||||
git checkout "${GITHUB_REF:11}"
|
||||
|
||||
echo "Pulling from remote..."
|
||||
git fetch && git pull
|
||||
|
||||
echo "Resetting files..."
|
||||
git reset
|
||||
|
||||
echo "Adding files..."
|
||||
add
|
||||
|
||||
echo "Removing files..."
|
||||
remove
|
||||
|
||||
echo "Creating commit..."
|
||||
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
|
||||
|
||||
echo "Pushing to repo..."
|
||||
git push --set-upstream origin "${GITHUB_REF:11}"
|
||||
|
||||
echo "::endgroup::"
|
||||
echo "Task completed."
|
||||
else
|
||||
echo "::endgroup::"
|
||||
echo "Working tree clean. Nothing to commit."
|
||||
fi
|
||||
1
lib/index.js
Normal file
1
lib/index.js
Normal file
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
|
||||
"use strict";var __importStar=this&&this.__importStar||function(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var c in a)Object.hasOwnProperty.call(a,c)&&(b[c]=a[c]);return b["default"]=a,b};Object.defineProperty(exports,"__esModule",{value:!0});const core=__importStar(require("@actions/core")),shell=__importStar(require("shelljs")),path=__importStar(require("path"));try{checkInputs(),shell.exec(path.join(__dirname,"../src/entrypoint.sh"))}catch(a){core.setFailed(a)}function checkInputs(){const a=process.env.GITHUB_EVENT_PATH;if(a){const{author:b}=require(a).head_commit;process.env.INPUT_AUTHOR_NAME||(process.env.INPUT_AUTHOR_NAME=b.name),process.env.INPUT_AUTHOR_EMAIL||(process.env.INPUT_AUTHOR_EMAIL=b.email)}else core.warning("No event path available, unable to fetch author info."),process.env.INPUT_AUTHOR_NAME||(process.env.INPUT_AUTHOR_NAME="Add & Commit Action"),process.env.INPUT_AUTHOR_EMAIL||(process.env.INPUT_AUTHOR_EMAIL="actions@github.com");core.info(`Using '${process.env.INPUT_AUTHOR_NAME} <${process.env.INPUT_AUTHOR_EMAIL}>' as author.`)}
|
||||
1323
package-lock.json
generated
1323
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@@ -1,13 +1,11 @@
|
||||
{
|
||||
"name": "add-and-commit",
|
||||
"version": "2.3.0",
|
||||
"version": "4.0.3",
|
||||
"description": "Add & commit files from a path directly from GitHub Actions",
|
||||
"main": "lib/main.js",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "npm run compile && npm run minify && rm build/*.js",
|
||||
"compile": "tsc",
|
||||
"minify": "minify build -d lib",
|
||||
"dist": "echo \"Preparing for distribution...\" && npm i --only=prod && git add -f node_modules && git commit -m \"Commit dist files\"",
|
||||
"build": "npm i && ncc build src/main.ts --minify --out lib",
|
||||
"watch": "ncc build src/main.ts --watch --out lib",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
@@ -28,15 +26,14 @@
|
||||
},
|
||||
"homepage": "https://github.com/EndBug/add-and-commit#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.1.3",
|
||||
"shelljs": "^0.8.3"
|
||||
"@actions/core": "^1.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.7.12",
|
||||
"@types/shelljs": "^0.8.6",
|
||||
"@typescript-eslint/eslint-plugin": "^2.12.0",
|
||||
"@typescript-eslint/parser": "^2.12.0",
|
||||
"babel-minify": "^0.5.1",
|
||||
"@zeit/ncc": "^0.21.1",
|
||||
"eslint": "^6.8.0",
|
||||
"typescript": "^3.6.4"
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
set -u
|
||||
|
||||
echo "::group::Internal logs"
|
||||
|
||||
cd $INPUT_CWD
|
||||
echo "Running in $PWD."
|
||||
|
||||
# Set up .netrc file with GitHub credentials
|
||||
git_setup() {
|
||||
cat <<- EOF > $HOME/.netrc
|
||||
cat <<-EOF >$HOME/.netrc
|
||||
machine github.com
|
||||
login $GITHUB_ACTOR
|
||||
password $GITHUB_TOKEN
|
||||
@@ -13,33 +18,33 @@ git_setup() {
|
||||
password $GITHUB_TOKEN
|
||||
EOF
|
||||
chmod 600 $HOME/.netrc
|
||||
|
||||
git config --global user.email "$INPUT_AUTHOR_EMAIL"
|
||||
git config --global user.name "$INPUT_AUTHOR_NAME"
|
||||
}
|
||||
|
||||
add() {
|
||||
if $INPUT_FORCE
|
||||
then find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add -f $x; done
|
||||
else find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add $x; done
|
||||
fi
|
||||
if $INPUT_FORCE; then f=-f; else f=; fi
|
||||
git add $INPUT_ADD $f
|
||||
}
|
||||
|
||||
remove() {
|
||||
if [ -n "$INPUT_REMOVE" ]; then git rm $INPUT_REMOVE; fi
|
||||
}
|
||||
|
||||
# This is needed to make the check work for untracked files
|
||||
echo "Staging files in commit path..."
|
||||
echo "Staging files..."
|
||||
add
|
||||
remove
|
||||
|
||||
echo "Checking for uncommitted changes in the git working tree..."
|
||||
# This section only runs if there have been file changes
|
||||
if ! git diff --cached --exit-code
|
||||
then
|
||||
if ! git diff --cached --quiet --exit-code; then
|
||||
git_setup
|
||||
|
||||
git fetch
|
||||
git fetch
|
||||
|
||||
# Verify if the branch needs to be created
|
||||
if ! git rev-parse --verify --quiet "${GITHUB_REF:11}"
|
||||
then
|
||||
if ! git rev-parse --verify --quiet "${GITHUB_REF:11}"; then
|
||||
echo "Creating branch..."
|
||||
git branch "${GITHUB_REF:11}"
|
||||
fi
|
||||
@@ -48,14 +53,27 @@ then
|
||||
echo "Switching branch..."
|
||||
git checkout "${GITHUB_REF:11}"
|
||||
|
||||
echo "Pulling from remote..."
|
||||
git fetch && git pull
|
||||
|
||||
echo "Resetting files..."
|
||||
git reset
|
||||
|
||||
echo "Adding files..."
|
||||
add
|
||||
|
||||
echo "Removing files..."
|
||||
remove
|
||||
|
||||
echo "Creating commit..."
|
||||
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
|
||||
|
||||
echo "Pushing to repo..."
|
||||
git push --set-upstream origin "${GITHUB_REF:11}"
|
||||
|
||||
echo "::endgroup::"
|
||||
echo "Task completed."
|
||||
else
|
||||
echo "::endgroup::"
|
||||
echo "Working tree clean. Nothing to commit."
|
||||
fi
|
||||
|
||||
38
src/main.ts
38
src/main.ts
@@ -1,24 +1,34 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as shell from 'shelljs'
|
||||
import * as path from 'path'
|
||||
import { info, setFailed, getInput, warning } from '@actions/core'
|
||||
import { join as path } from 'path'
|
||||
import { execFile } from 'child_process'
|
||||
|
||||
try {
|
||||
checkInputs()
|
||||
shell.exec(path.join(__dirname, '../src/entrypoint.sh'))
|
||||
} catch (e) {
|
||||
core.setFailed(e)
|
||||
const child = execFile(path(__dirname, 'entrypoint.sh'))
|
||||
child.stdout?.pipe(process.stdout)
|
||||
child.stderr?.pipe(process.stderr)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
setFailed(err instanceof Error ? err.message : err)
|
||||
}
|
||||
|
||||
function checkInputs() {
|
||||
const eventPath = process.env.GITHUB_EVENT_PATH
|
||||
if (eventPath) {
|
||||
const { author } = require(eventPath).head_commit
|
||||
if (!process.env.INPUT_AUTHOR_NAME) process.env.INPUT_AUTHOR_NAME = author.name
|
||||
if (!process.env.INPUT_AUTHOR_EMAIL) process.env.INPUT_AUTHOR_EMAIL = author.email
|
||||
const author = eventPath && require(eventPath)?.head_commit?.author
|
||||
|
||||
if (author) {
|
||||
setDefault('author_name', author.name)
|
||||
setDefault('author_email', author.email)
|
||||
} else {
|
||||
core.warning('No event path available, unable to fetch author info.')
|
||||
if (!process.env.INPUT_AUTHOR_NAME) process.env.INPUT_AUTHOR_NAME = 'Add & Commit Action'
|
||||
if (!process.env.INPUT_AUTHOR_EMAIL) process.env.INPUT_AUTHOR_EMAIL = 'actions@github.com'
|
||||
if (!getInput('author_name') || !getInput('author_email')) warning(`Unable to fetch author info: couldn't find ${!eventPath ? 'event path' : !require(eventPath)?.head_commit ? 'commit' : 'commit author'}.`)
|
||||
setDefault('author_name', 'Add & Commit Action')
|
||||
setDefault('author_email', 'actions@github.com')
|
||||
}
|
||||
core.info(`Using '${process.env.INPUT_AUTHOR_NAME} <${process.env.INPUT_AUTHOR_EMAIL}>' as author.`)
|
||||
|
||||
info(`Using '${getInput('author_name')} <${getInput('author_email')}>' as author.`)
|
||||
}
|
||||
|
||||
function setDefault(input: string, value: string) {
|
||||
const key = 'INPUT_' + input.toUpperCase()
|
||||
if (!process.env[key]) process.env[key] = value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user