Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ Add a step like this to your workflow:
# Arguments for the git tag command (the tag name always needs to be the first word not preceded by an hyphen)
# Default: ''
tag: 'v1.0.0 --force'

# The token to use to access the GitHub API when getting the author info (see the paragraph below for more info about the tokens used by the action)
# Default: secrets.GITHUB_TOKEN
token: ${{ secrets.GITHUB_TOKEN }}
```

### Adding files:
Expand Down Expand Up @@ -93,8 +89,7 @@ You can use the `tag` option to enter the arguments for a `git add` command. In

### Tokens:

The token from the `token` input is only used when getting the author info from the GitHub API: usually the default GitHub token is enough but if for some reason you want to change it, you can use that input.
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 change the token there.
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.

### Outputs:
Expand Down
6 changes: 2 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ inputs:
author_name:
description: The name of the user that will be displayed as the author of the commit
required: false
default: ${{ github.actor }}
author_email:
description: The email of the user that will be displayed as the author of the commit
required: false
default: ${{ github.actor }}@users.noreply.github.com
branch:
description: Name of the branch to use, if different from the one that triggered the workflow
required: false
Expand Down Expand Up @@ -39,10 +41,6 @@ inputs:
tag:
description: Arguments for the git tag command (the tag name always needs to be the first word not preceded by a hyphen)
required: false
token:
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
required: false
default: ${{ github.token }}

outputs:
committed:
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"homepage": "https://github.com/EndBug/add-and-commit#readme",
"dependencies": {
"@actions/core": "^1.2.6",
"axios": "^0.21.1",
"js-yaml": "^3.14.1",
"simple-git": "^2.27.0"
},
Expand Down
72 changes: 5 additions & 67 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
startGroup,
endGroup
} from '@actions/core'
import axios from 'axios'
import path from 'path'
import simpleGit, { Response } from 'simple-git'
import YAML from 'js-yaml'
Expand Down Expand Up @@ -179,25 +178,10 @@ async function checkInputs() {
const eventPath = process.env.GITHUB_EVENT_PATH,
event = eventPath && require(eventPath),
isPR = process.env.GITHUB_EVENT_NAME?.includes('pull_request'),
sha = (event?.pull_request?.head?.sha || process.env.GITHUB_SHA) as string,
defaultBranch = isPR
? (event?.pull_request?.head?.ref as string)
: process.env.GITHUB_REF?.substring(11)

// #region GITHUB_TOKEN
let token = process.env.GITHUB_TOKEN
if (token) {
debug('Using token from GITHUB_TOKEN env variable.')
warning(
"The GITHUB_TOKEN env variable is deprecated and will not be supported in the next major release. Use the 'token' input, " +
"which defaults to 'secrets.GITHUB_TOKEN'."
)
} else {
debug('Using token from token input.')
token = getInput('token')
}
// #endregion

// #region add, remove
if (!getInput('add') && !getInput('remove'))
throw new Error(
Expand Down Expand Up @@ -227,57 +211,11 @@ async function checkInputs() {
// #endregion

// #region author_name, author_email
if (getInput('author_name') && getInput('author_email')) {
info('> Using author info from inputs...')
} else {
info('> Some author info is missing, filling from workflow event...')
let author = event?.head_commit?.author

if (sha && !author) {
info(
'> Unable to get commit from workflow event: trying with the GitHub API...'
)

// https://docs.github.com/en/rest/reference/repos#get-a-commit--code-samples
const url = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}`,
headers = token
? {
Authorization: `Bearer ${token}`
}
: undefined,
commit = (
await axios.get(url, { headers }).catch((err) => {
startGroup('Request error:')
info(`> Request URL: ${url}\b${err}`)
endGroup()
return undefined
})
)?.data

author = commit?.commit?.author
}

if (typeof author == 'object') {
setDefault('author_name', author.name)
setDefault('author_email', author.email)
}

if (!getInput('author_name') || !getInput('author_email')) {
const reason = !eventPath
? 'event path'
: isPR
? sha
? 'fetch commit'
: 'find commit sha'
: !event?.head_commit
? 'find commit'
: 'find commit author'
warning(`Unable to fetch author info: couldn't ${reason}.`)
setDefault('author_name', 'Add & Commit Action')
setDefault('author_email', 'actions@github.com')
}
}

setDefault('author_name', `${process.env.GITHUB_ACTOR}`)
setDefault(
'author_email',
`${process.env.GITHUB_ACTOR}@users.noreply.github.com`
)
info(
`> Using '${getInput('author_name')} <${getInput(
'author_email'
Expand Down