Compare commits

...

115 Commits
v2 ... v4.4.0

Author SHA1 Message Date
Federico Grandi
a988073222 release: v4.4.0 2020-07-31 20:55:15 +02:00
allcontributors[bot]
88408e5833 docs: add connorjclark as a contributor (#50)
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2020-07-31 20:52:03 +02:00
Federico Grandi
27a89ad786 feat: add PR support (#49)
* feat: add PR support

* add debug steps

* fix: use console

* fix: fix buil error

* [auto] build: update compiled version

* fix: better branch handling

* [auto] build: update compiled version

* chore: remove debug steps

* fix: fetch author using GitHub API when in PR

* [auto] build: update compiled version

* feat: extend API functionality to non-PR runs

* [auto] build: update compiled version
2020-07-31 20:47:38 +02:00
Federico Grandi
d5f44e7aeb release: v4.3.0 2020-07-29 19:07:42 +02:00
allcontributors[bot]
52f10712cb docs: add pvogt09 as a contributor (#47)
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2020-07-29 19:05:50 +02:00
pvogt09
51fc21c221 add option to use --signoff with git commit (#46)
* adds option to use --signoff with git commit

Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>

* [auto] build: update compiled version

* fix: remove quotes and refactor

* [auto] build: update compiled version

Co-authored-by: Federico Grandi <fgrandi30@gmail.com>
2020-07-29 19:04:48 +02:00
Federico Grandi
46b61e173e release: v4.2.1 2020-07-10 20:03:38 +02:00
Federico Grandi
06d54462fa Merge pull request #44 from EndBug/all-contributors/add-JonasJacobsUserspace
docs: add JonasJacobsUserspace as a contributor
2020-07-10 17:27:46 +02:00
allcontributors[bot]
21a36873cf docs: update .all-contributorsrc [skip ci] 2020-07-10 15:27:32 +00:00
allcontributors[bot]
4d2a782ca7 docs: update README.md [skip ci] 2020-07-10 15:27:31 +00:00
Federico Grandi
feb7bba5df Merge pull request #43 from EndBug/all-contributors/add-ToMe25
docs: add ToMe25 as a contributor
2020-07-10 17:23:01 +02:00
allcontributors[bot]
30fd5a24e7 docs: update .all-contributorsrc [skip ci] 2020-07-10 15:22:37 +00:00
allcontributors[bot]
4f4dea335c docs: update README.md [skip ci] 2020-07-10 15:22:36 +00:00
Federico Grandi
caecee358e Merge pull request #42 from EndBug/all-contributors/add-jsoref
docs: add jsoref as a contributor
2020-07-10 17:21:25 +02:00
allcontributors[bot]
79fc4adbf9 docs: update .all-contributorsrc [skip ci] 2020-07-10 15:21:12 +00:00
allcontributors[bot]
4fe29d7392 docs: update README.md [skip ci] 2020-07-10 15:21:11 +00:00
Federico Grandi
2b94f96e3e docs: re-generate contributors 2020-07-10 17:19:43 +02:00
Federico Grandi
ab8370c244 Merge pull request #37 from EndBug/all-contributors/add-DmitrijOkeanij
docs: add DmitrijOkeanij as a contributor
2020-07-10 17:18:53 +02:00
Federico Grandi
61eda586c3 Merge branch 'master' into all-contributors/add-DmitrijOkeanij 2020-07-10 17:18:35 +02:00
Federico Grandi
b34850c645 Merge pull request #41 from EndBug/all-contributors/add-onilton
docs: add onilton as a contributor
2020-07-10 17:16:13 +02:00
allcontributors[bot]
f0718670ec docs: update .all-contributorsrc [skip ci] 2020-07-10 15:15:24 +00:00
allcontributors[bot]
ce9997b52f docs: update README.md [skip ci] 2020-07-10 15:15:23 +00:00
Federico Grandi
8cb387e3de Merge pull request #40 from EndBug/all-contributors/add-RobinWijnant
docs: add RobinWijnant as a contributor
2020-07-10 17:14:43 +02:00
allcontributors[bot]
4d0876f6b0 docs: update .all-contributorsrc [skip ci] 2020-07-10 15:14:11 +00:00
allcontributors[bot]
34cf82b848 docs: update README.md [skip ci] 2020-07-10 15:14:10 +00:00
Federico Grandi
8cc88cd3ac fix(contributors): fix malformed JSON 2020-07-10 17:13:43 +02:00
Federico Grandi
c94b5af098 Merge pull request #39 from EndBug/all-contributors/add-felixlapalma
docs: add felixlapalma as a contributor
2020-07-10 17:10:50 +02:00
Federico Grandi
d992c49843 Merge branch 'master' into all-contributors/add-felixlapalma 2020-07-10 17:10:39 +02:00
Federico Grandi
8a80768baa Merge pull request #38 from EndBug/all-contributors/add-brahma-dev
docs: add brahma-dev as a contributor
2020-07-10 17:06:24 +02:00
allcontributors[bot]
8b941d4dfd docs: update .all-contributorsrc [skip ci] 2020-07-10 15:05:53 +00:00
allcontributors[bot]
d5de9f3f0d docs: update README.md [skip ci] 2020-07-10 15:05:52 +00:00
allcontributors[bot]
2d9c41ae6b docs: update .all-contributorsrc [skip ci] 2020-07-10 15:05:03 +00:00
allcontributors[bot]
5560eecdc1 docs: update README.md [skip ci] 2020-07-10 15:05:02 +00:00
allcontributors[bot]
58530b3799 docs: update .all-contributorsrc [skip ci] 2020-07-10 15:03:49 +00:00
allcontributors[bot]
026e98aa42 docs: update README.md [skip ci] 2020-07-10 15:03:48 +00:00
Federico Grandi
c2e2293f44 Merge pull request #36 from EndBug/all-contributors/add-jhhughes
docs: add jhhughes as a contributor
2020-07-10 17:03:07 +02:00
allcontributors[bot]
08fe1b6e43 docs: update .all-contributorsrc [skip ci] 2020-07-10 15:02:16 +00:00
allcontributors[bot]
46d77cfa2d docs: update README.md [skip ci] 2020-07-10 15:02:15 +00:00
Federico Grandi
8feda109a1 Merge pull request #35 from EndBug/all-contributors/add-yelizariev
docs: add yelizariev as a contributor
2020-07-10 17:01:05 +02:00
allcontributors[bot]
7e9ca065e6 docs: update .all-contributorsrc [skip ci] 2020-07-10 14:59:36 +00:00
allcontributors[bot]
7acf8aea7c docs: update README.md [skip ci] 2020-07-10 14:59:35 +00:00
Federico Grandi
30fab2fa31 Merge pull request #34 from EndBug/all-contributors/add-jactor-rises
docs: add jactor-rises as a contributor
2020-07-10 16:56:30 +02:00
allcontributors[bot]
cbdf3e43f1 docs: update .all-contributorsrc [skip ci] 2020-07-10 14:55:06 +00:00
allcontributors[bot]
507713a63b docs: update README.md [skip ci] 2020-07-10 14:55:04 +00:00
Federico Grandi
c512c446c5 chore: update commit message 2020-07-10 16:51:32 +02:00
Federico Grandi
3067c9e15c docs: add @EndBug as a contributor 2020-07-10 16:50:22 +02:00
Federico Grandi
85ed07244a docs(contributors): add all-contributors 2020-07-10 16:50:14 +02:00
Federico Grandi
13550b50b0 [auto] Update compiled version 2020-07-08 14:43:47 +00:00
Federico Grandi
bf3210f533 try join instead of resolve 2020-07-08 16:42:53 +02:00
Federico Grandi
6411f389b7 [auto] Update compiled version 2020-07-08 14:40:10 +00:00
Federico Grandi
dec54c038c try using shell parameter 2020-07-08 16:37:42 +02:00
Federico Grandi
e109cd1639 [auto] Update compiled version 2020-07-08 14:11:22 +00:00
Federico Grandi
ac2b74d9d0 fix:use resolve instead of join 2020-07-08 16:10:51 +02:00
Federico Grandi
d82f4d33b7 Lock to v1 (safer) 2020-05-17 18:36:51 +02:00
Federico Grandi
d926d1c554 [auto] Update compiled version 2020-05-17 16:26:50 +00:00
Federico Grandi
8b797ba126 Fix tag clobbering 2020-05-17 18:26:13 +02:00
Federico Grandi
1b11953688 Bump version: 4.2.0 2020-05-17 18:18:56 +02:00
Federico Grandi
36bc3f778b Improve tagging docs 2020-05-17 18:17:30 +02:00
Federico Grandi
c61b317dea Merge pull request #30 from ToMe25/master
Add tagging support
2020-05-17 18:12:19 +02:00
ToMe25
22cdfa345a [auto] Update compiled version 2020-05-16 17:54:55 +00:00
ToMe25
d4aeb9335d Hopefully this time fix which commit gets tagged 2020-05-16 19:54:18 +02:00
ToMe25
46569f991f [auto] Update compiled version 2020-05-16 17:45:45 +00:00
ToMe25
83761c7e8e Hopefully fix wrong commit getting tagged 2020-05-16 19:44:48 +02:00
ToMe25
f0a1d2598a [auto] Update compiled version 2020-05-16 17:17:36 +00:00
ToMe25
c902408157 Add missing push arg 2020-05-16 19:16:43 +02:00
ToMe25
6b705fa3a4 Add tagging support 2020-05-16 18:30:49 +02:00
Federico Grandi
0e98be578d Version bump: 4.1.0 2020-05-01 15:36:30 +02:00
Federico Grandi
c07603c1c4 [auto] Update compiled version 2020-05-01 13:28:50 +00:00
Federico Grandi
9cd6e9c0ea Add ref option 2020-05-01 15:27:44 +02:00
Federico Grandi
5bf921b386 Version bump: 4.0.3 2020-05-01 11:52:28 +02:00
Federico Grandi
beedcea439 Version bump: 4.0.2 2020-05-01 11:48:19 +02:00
Federico Grandi
6cb111a771 [auto] Update compiled version 2020-05-01 09:47:36 +00:00
Federico Grandi
6a4387c9c9 Minor log improvement 2020-05-01 11:46:57 +02:00
Federico Grandi
132aa0f637 [auto] Update compiled version 2020-05-01 09:42:54 +00:00
Federico Grandi
7dbb54bce3 Add groups 2020-05-01 11:42:13 +02:00
Federico Grandi
7f1289bf4a Pipe stderr too 2020-05-01 11:39:32 +02:00
Federico Grandi
88d475f304 [auto] Update compiled version 2020-05-01 09:35:49 +00:00
Federico Grandi
98f4b8018b Try with .pipe 2020-05-01 11:35:06 +02:00
Federico Grandi
2f6a78549b [auto] Update compiled version 2020-05-01 09:26:43 +00:00
Federico Grandi
9cd727829f Try using execFile 2020-05-01 11:26:05 +02:00
Federico Grandi
f0fcdb07a3 [auto] Update compiled version 2020-05-01 09:17:33 +00:00
Federico Grandi
5ead79aef9 Try to fix logs 2020-05-01 11:16:32 +02:00
Federico Grandi
72da43cf1b Merge pull request #28 from RobinWijnant/master
Add --quiet flag to git diff
2020-05-01 11:08:07 +02:00
Robin Wijnant
9eb0d21b0d add --quiet flag git diff
This fixes ENOBUFS error which is thrown when the stdout buffer exceeds 1MB
2020-04-30 10:31:44 +02:00
Federico Grandi
2db75722ce Merge pull request #26 from jsoref/grammar
Improve grammar and formatting in README
2020-04-27 16:07:53 +02:00
Josh Soref
68d0f64f6f Grammar 2020-04-26 18:23:22 -04:00
Federico Grandi
d1cfc165c7 [auto] Update compiled version 2020-04-19 17:48:30 +00:00
Federico Grandi
5f12f937cb Fix error hadling
Ref #25
2020-04-19 19:47:38 +02:00
Federico Grandi
2d77fa2c79 Bump version 2020-03-20 16:49:50 +01:00
Federico Grandi
f6b13bc7e9 [auto] Update compiled version 2020-03-20 15:37:19 +00:00
Federico Grandi
116c918fd3 Warn only if one of the params is missing 2020-03-20 16:36:34 +01:00
Federico Grandi
fbbcae9aa5 [auto] Update compiled version 2020-03-20 14:12:28 +00:00
Federico Grandi
7bd2b1ca10 Fix: allow action to work without head_commit
Ref: Issue #22
2020-03-20 15:11:47 +01:00
Federico Grandi
61d14d1bee Merge pull request #24 from EndBug/ncc
Use @zeit/ncc for builds
2020-03-20 14:54:36 +01:00
Federico Grandi
6a75638ec3 Update lib file name 2020-03-20 14:51:31 +01:00
Federico Grandi
ff38b6c4a6 [auto] Update compiled version 2020-03-20 13:48:59 +00:00
Federico Grandi
e67ce7f439 Use @zeit/ncc for builds 2020-03-20 14:48:20 +01:00
Federico Grandi
a83118880c Use child_process instead of shelljs 2020-03-20 14:47:36 +01:00
Federico Grandi
a28158a63f Fix CVE-2020-7598 2020-03-20 13:03:43 +01:00
dependabot[bot]
30030e85c0 Bump acorn from 7.1.0 to 7.1.1 (#21)
Bumps [acorn](https://github.com/acornjs/acorn) from 7.1.0 to 7.1.1.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/7.1.0...7.1.1)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-03-14 15:21:39 +01:00
Federico Grandi
79fa1f9f98 Use add-and-commit@v4.0.0 2020-03-03 19:42:01 +01:00
Federico Grandi
06fd39b8b7 Fix typo 2020-03-03 19:31:46 +01:00
Federico Grandi
f278ec6d47 Trigger workflow run 2020-03-03 19:30:13 +01:00
Federico Grandi
5a3f4c1c24 Update build workflow 2020-03-03 19:29:21 +01:00
Federico Grandi
602bf4ea71 Final adjustments for v4 2020-03-03 19:28:06 +01:00
Federico Grandi
5148cf0f38 Use set -u instead of -eu 2020-03-03 19:04:22 +01:00
Federico Grandi
12febc42d8 Use git add 2020-03-03 18:36:41 +01:00
Federico Grandi
de8a121ebd Rm (#20)
* Add remove option

* [auto] Update compiled version

* Add fixes

* [auto] Update compiled version

* Update docs
2020-02-21 16:48:19 +01:00
Federico Grandi
a2b49385e8 [auto] Update compiled version 2020-02-11 20:31:49 +00:00
Federico Grandi
ea7cddff4f Better usage docs 2020-02-03 17:12:00 +01:00
Federico Grandi
9acdb7d7f4 Small refactor 2020-02-03 16:54:41 +01:00
Federico Grandi
6d08b4f153 Add setDefault function 2020-02-03 16:53:01 +01:00
Federico Grandi
925751a406 Update versioning.yml 2020-01-24 10:52:35 +01:00
Federico Grandi
d3ccc660f4 Fix typos 2020-01-22 21:31:06 +01:00
Federico Grandi
4d5fbad9c9 Add pull command 2020-01-22 21:18:55 +01:00
12 changed files with 1504 additions and 1083 deletions

145
.all-contributorsrc Normal file
View File

@@ -0,0 +1,145 @@
{
"projectName": "add-and-commit",
"projectOwner": "EndBug",
"repoType": "github",
"repoHost": "https://github.com",
"files": [
"README.md"
],
"imageSize": 100,
"commit": true,
"commitConvention": "angular",
"contributors": [
{
"login": "EndBug",
"name": "Federico Grandi",
"avatar_url": "https://avatars1.githubusercontent.com/u/26386270?v=4",
"profile": "https://github.com/EndBug",
"contributions": [
"code",
"doc"
]
},
{
"login": "jactor-rises",
"name": "Tor Egil Jacobsen",
"avatar_url": "https://avatars3.githubusercontent.com/u/14565088?v=4",
"profile": "https://github.com/jactor-rises",
"contributions": [
"code"
]
},
{
"login": "yelizariev",
"name": "Ivan Yelizariev",
"avatar_url": "https://avatars0.githubusercontent.com/u/186131?v=4",
"profile": "https://twitter.com/yelizariev",
"contributions": [
"ideas"
]
},
{
"login": "jhhughes",
"name": "jhhughes",
"avatar_url": "https://avatars2.githubusercontent.com/u/13724293?v=4",
"profile": "https://github.com/jhhughes",
"contributions": [
"bug"
]
},
{
"login": "DmitrijOkeanij",
"name": "Дмитрий Океаний",
"avatar_url": "https://avatars3.githubusercontent.com/u/10674646?v=4",
"profile": "https://sunengine.site",
"contributions": [
"ideas"
]
},
{
"login": "brahma-dev",
"name": "Brahma Dev",
"avatar_url": "https://avatars3.githubusercontent.com/u/1793295?v=4",
"profile": "https://github.com/brahma-dev",
"contributions": [
"bug"
]
},
{
"login": "felixlapalma",
"name": "Felix Rojo Lapalma",
"avatar_url": "https://avatars2.githubusercontent.com/u/38389683?v=4",
"profile": "https://github.com/felixlapalma",
"contributions": [
"bug"
]
},
{
"login": "RobinWijnant",
"name": "Robin Wijnant",
"avatar_url": "https://avatars3.githubusercontent.com/u/33033209?v=4",
"profile": "http://robinwijnant.me",
"contributions": [
"bug",
"code"
]
},
{
"login": "onilton",
"name": "Onilton Maciel",
"avatar_url": "https://avatars2.githubusercontent.com/u/725676?v=4",
"profile": "https://github.com/onilton",
"contributions": [
"ideas"
]
},
{
"login": "jsoref",
"name": "Josh Soref",
"avatar_url": "https://avatars0.githubusercontent.com/u/2119212?v=4",
"profile": "https://github.com/jsoref",
"contributions": [
"doc"
]
},
{
"login": "ToMe25",
"name": "ToMe25",
"avatar_url": "https://avatars1.githubusercontent.com/u/38815969?v=4",
"profile": "https://github.com/ToMe25",
"contributions": [
"code",
"ideas"
]
},
{
"login": "JonasJacobsUserspace",
"name": "JonasJacobsUserspace",
"avatar_url": "https://avatars0.githubusercontent.com/u/59708720?v=4",
"profile": "https://github.com/JonasJacobsUserspace",
"contributions": [
"bug"
]
},
{
"login": "pvogt09",
"name": "pvogt09",
"avatar_url": "https://avatars3.githubusercontent.com/u/50047961?v=4",
"profile": "https://github.com/pvogt09",
"contributions": [
"code"
]
},
{
"login": "connorjclark",
"name": "Connor Clark",
"avatar_url": "https://avatars1.githubusercontent.com/u/4071474?v=4",
"profile": "http://hoten.cc",
"contributions": [
"ideas"
]
}
],
"contributorsPerLine": 7,
"skipCi": true
}

View File

@@ -3,6 +3,9 @@ on:
push:
branches-ignore:
- dist
paths:
- src/**
- .github/workflows/build.yml
jobs:
build:
@@ -24,11 +27,10 @@ jobs:
run: npm run build
- name: Commit changes
uses: EndBug/add-and-commit@v2
uses: EndBug/add-and-commit@v4.0.0
with:
message: "[auto] build: update compiled version"
add: lib
force: true
message: "[auto] Update compiled version"
path: lib
pattern: "*.js"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -2,13 +2,13 @@ name: Keep the versions up-to-date
on:
release:
types: [published]
types: [published, edited]
jobs:
actions-tagger:
runs-on: windows-latest
steps:
- uses: Actions-R-Us/actions-tagger@latest
- uses: Actions-R-Us/actions-tagger@v1
with:
publish_latest: true
env:

142
README.md
View File

@@ -1,66 +1,88 @@
# Add & Commit
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
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
cwd: "."
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
# Whether to use the --signoff option on `git commit`
# Default: false
signoff: true
# The message for the commit
# Default: 'Commit from GitHub Actions'
message: 'Your commit message'
# Name of the branch to use, if different from the one that triggered the workflow
# Default: the branch that triggered the workflow (from GITHUB_REF)
ref: 'someOtherBranch'
# The arguments for the `git rm` command (see the paragraph below for more info)
# Default: ''
remove: "./dir/old_file.js"
# Name of the tag to add to the new commit (see the paragraph below for more info)
# Default: ''
tag: "v1.0.0"
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
- `cwd` : the working directory in which your repository is located, defaults to `.`
- `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
### Tagging:
- 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 }}
```
You can tag commits with the `tag` option: when used, it will create a lightweight tag for the commit with the name you set as input. If not entered (or if an empty string is passed) teh action won't create any tag.
If there is already a tag with the name you entered it will be overwritten, and so the tag will be "updated".
### Example:
### Examples:
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
@@ -86,13 +108,12 @@ 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 }}
```
@@ -109,7 +130,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# If you need to, you can checkout your repo to a different location
# If you need to, you can check out your repo to a different location
- uses: actions/checkout@v2
with:
path: "./pathToRepo/"
@@ -118,17 +139,50 @@ jobs:
- 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@v2
- uses: EndBug/add-and-commit@v4
with:
message: "Add the very useful text file"
path: "."
pattern: "*.txt"
add: "*.txt"
cwd: "./pathToRepo/"
force: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/EndBug"><img src="https://avatars1.githubusercontent.com/u/26386270?v=4" width="100px;" alt=""/><br /><sub><b>Federico Grandi</b></sub></a><br /><a href="https://github.com/EndBug/add-and-commit/commits?author=EndBug" title="Code">💻</a> <a href="https://github.com/EndBug/add-and-commit/commits?author=EndBug" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/jactor-rises"><img src="https://avatars3.githubusercontent.com/u/14565088?v=4" width="100px;" alt=""/><br /><sub><b>Tor Egil Jacobsen</b></sub></a><br /><a href="https://github.com/EndBug/add-and-commit/commits?author=jactor-rises" title="Code">💻</a></td>
<td align="center"><a href="https://twitter.com/yelizariev"><img src="https://avatars0.githubusercontent.com/u/186131?v=4" width="100px;" alt=""/><br /><sub><b>Ivan Yelizariev</b></sub></a><br /><a href="#ideas-yelizariev" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/jhhughes"><img src="https://avatars2.githubusercontent.com/u/13724293?v=4" width="100px;" alt=""/><br /><sub><b>jhhughes</b></sub></a><br /><a href="https://github.com/EndBug/add-and-commit/issues?q=author%3Ajhhughes" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://sunengine.site"><img src="https://avatars3.githubusercontent.com/u/10674646?v=4" width="100px;" alt=""/><br /><sub><b>Дмитрий Океаний</b></sub></a><br /><a href="#ideas-DmitrijOkeanij" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/brahma-dev"><img src="https://avatars3.githubusercontent.com/u/1793295?v=4" width="100px;" alt=""/><br /><sub><b>Brahma Dev</b></sub></a><br /><a href="https://github.com/EndBug/add-and-commit/issues?q=author%3Abrahma-dev" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/felixlapalma"><img src="https://avatars2.githubusercontent.com/u/38389683?v=4" width="100px;" alt=""/><br /><sub><b>Felix Rojo Lapalma</b></sub></a><br /><a href="https://github.com/EndBug/add-and-commit/issues?q=author%3Afelixlapalma" title="Bug reports">🐛</a></td>
</tr>
<tr>
<td align="center"><a href="http://robinwijnant.me"><img src="https://avatars3.githubusercontent.com/u/33033209?v=4" width="100px;" alt=""/><br /><sub><b>Robin Wijnant</b></sub></a><br /><a href="https://github.com/EndBug/add-and-commit/issues?q=author%3ARobinWijnant" title="Bug reports">🐛</a> <a href="https://github.com/EndBug/add-and-commit/commits?author=RobinWijnant" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/onilton"><img src="https://avatars2.githubusercontent.com/u/725676?v=4" width="100px;" alt=""/><br /><sub><b>Onilton Maciel</b></sub></a><br /><a href="#ideas-onilton" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/jsoref"><img src="https://avatars0.githubusercontent.com/u/2119212?v=4" width="100px;" alt=""/><br /><sub><b>Josh Soref</b></sub></a><br /><a href="https://github.com/EndBug/add-and-commit/commits?author=jsoref" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/ToMe25"><img src="https://avatars1.githubusercontent.com/u/38815969?v=4" width="100px;" alt=""/><br /><sub><b>ToMe25</b></sub></a><br /><a href="https://github.com/EndBug/add-and-commit/commits?author=ToMe25" title="Code">💻</a> <a href="#ideas-ToMe25" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/JonasJacobsUserspace"><img src="https://avatars0.githubusercontent.com/u/59708720?v=4" width="100px;" alt=""/><br /><sub><b>JonasJacobsUserspace</b></sub></a><br /><a href="https://github.com/EndBug/add-and-commit/issues?q=author%3AJonasJacobsUserspace" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/pvogt09"><img src="https://avatars3.githubusercontent.com/u/50047961?v=4" width="100px;" alt=""/><br /><sub><b>pvogt09</b></sub></a><br /><a href="https://github.com/EndBug/add-and-commit/commits?author=pvogt09" title="Code">💻</a></td>
<td align="center"><a href="http://hoten.cc"><img src="https://avatars1.githubusercontent.com/u/4071474?v=4" width="100px;" alt=""/><br /><sub><b>Connor Clark</b></sub></a><br /><a href="#ideas-connorjclark" title="Ideas, Planning, & Feedback">🤔</a></td>
</tr>
</table>
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
## License
This action is distributed under the MIT license, check the [license](LICENSE) for more info.

View File

@@ -2,6 +2,10 @@ 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
@@ -16,22 +20,29 @@ inputs:
description: Whether to use the force option on git add, in order to bypass eventual gitignores
required: false
default: "false"
signoff:
description: Whether to use the signoff option on git commit
required: false
default: "false"
message:
description: The message for the commit
required: false
default: Commit from GitHub Actions
path:
description: The path to stage files from
ref:
description: Name of the branch to use, if different from the one that triggered the workflow
required: false
default: "."
pattern:
description: The pattern that mathces file names
remove:
description: Arguments for the git rm command
required: false
default: "*.*"
default: ""
tag:
description: The name of the tag to add to the new commit
required: false
default: ""
runs:
using: node12
main: lib/main.js
main: lib/index.js
branding:
icon: git-commit

88
lib/entrypoint.sh Executable file
View File

@@ -0,0 +1,88 @@
#!/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
}
commit() {
if $INPUT_SIGNOFF; then signoffcmd=--signoff; else signoffcmd=; fi
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>" $signoffcmd
}
tag() {
if [ -n "$INPUT_TAG" ]; then git tag $INPUT_TAG; 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
# Switch branch (create a new one if it doesn't exist)
echo "Switching/creating branch..."
git checkout "$INPUT_REF" 2>/dev/null || git checkout -b "$INPUT_REF"
echo "Pulling from remote..."
git fetch && git pull
echo "Resetting files..."
git reset
echo "Adding files..."
add
echo "Removing files..."
remove
echo "Creating commit..."
commit
echo "Tagging commit..."
tag
echo "Pushing commits to repo..."
git push --set-upstream origin "$INPUT_REF"
echo "Pushing tags to repo..."
git push --set-upstream origin "$INPUT_REF" --force --tags
echo "::endgroup::"
echo "Task completed."
else
echo "::endgroup::"
echo "Working tree clean. Nothing to commit."
fi

1
lib/index.js Normal file

File diff suppressed because one or more lines are too long

View File

@@ -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.`)}

2000
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,11 @@
{
"name": "add-and-commit",
"version": "2.3.0",
"version": "4.4.0",
"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": {
@@ -29,14 +27,15 @@
"homepage": "https://github.com/EndBug/add-and-commit#readme",
"dependencies": {
"@actions/core": "^1.1.3",
"shelljs": "^0.8.3"
"axios": "^0.19.2"
},
"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",
"all-contributors-cli": "^6.16.1",
"eslint": "^6.8.0",
"typescript": "^3.6.4"
}

View File

@@ -1,12 +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
@@ -16,49 +18,71 @@ 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
}
commit() {
if $INPUT_SIGNOFF; then signoffcmd=--signoff; else signoffcmd=; fi
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>" $signoffcmd
}
tag() {
if [ -n "$INPUT_TAG" ]; then git tag $INPUT_TAG; 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
echo "Creating branch..."
git branch "${GITHUB_REF:11}"
fi
# Switch branch (create a new one if it doesn't exist)
echo "Switching/creating branch..."
git checkout "$INPUT_REF" 2>/dev/null || git checkout -b "$INPUT_REF"
# 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 "Creating commit..."
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
echo "Removing files..."
remove
echo "Pushing to repo..."
git push --set-upstream origin "${GITHUB_REF:11}"
echo "Creating commit..."
commit
echo "Tagging commit..."
tag
echo "Pushing commits to repo..."
git push --set-upstream origin "$INPUT_REF"
echo "Pushing tags to repo..."
git push --set-upstream origin "$INPUT_REF" --force --tags
echo "::endgroup::"
echo "Task completed."
else
echo "::endgroup::"
echo "Working tree clean. Nothing to commit."
fi

View File

@@ -1,24 +1,68 @@
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 { execFile } from 'child_process'
import path from 'path'
import axios from 'axios'
try {
checkInputs()
shell.exec(path.join(__dirname, '../src/entrypoint.sh'))
} catch (e) {
core.setFailed(e)
}
checkInputs().then(() => {
const child = execFile(path.join(__dirname, 'entrypoint.sh'), [], { shell: true })
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
} 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'
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,
defaultRef = isPR
? event?.pull_request?.head?.ref as string
: process.env.GITHUB_REF?.substring(11)
const actualRef = setDefault('ref', defaultRef || '')
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 = process.env.GITHUB_TOKEN ? {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`
} : undefined,
commit = (await axios.get(url, { headers })).data
author = commit?.commit?.author
}
core.info(`Using '${process.env.INPUT_AUTHOR_NAME} <${process.env.INPUT_AUTHOR_EMAIL}>' as author.`)
if (author) {
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')
}
info(`Using '${getInput('author_name')} <${getInput('author_email')}>' as author.`)
if (isPR) info(`Running for a PR, the action will use '${actualRef}' as ref.`)
}
function setDefault(input: string, value: string) {
const key = 'INPUT_' + input.toUpperCase()
if (!process.env[key]) process.env[key] = value
return process.env[key] as string
}