Compare commits

...

72 Commits

Author SHA1 Message Date
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
Federico Grandi
aa1a8cef82 Add cwd option (#15)
* Add cwd option

* Commit dist files

* Debugging

* Remove modules

* Update docs

* Remove debugging command

* Minor formatting change
2019-12-29 20:19:06 +01:00
Federico Grandi
df80e1746f Update build.yml 2019-12-24 10:52:12 +01:00
Federico Grandi
e6702dc457 Update build.yml 2019-12-24 10:51:16 +01:00
Federico Grandi
08a333fd51 Remove build from dist script 2019-12-20 22:48:26 +01:00
Federico Grandi
570c13708e Fix dependencies 2019-12-20 22:28:48 +01:00
Federico Grandi
6354828f7b Add linting & edit scripts 2019-12-20 22:25:36 +01:00
Federico Grandi
5f0bbb3e99 Remove latest-tag 2019-12-20 22:20:33 +01:00
Federico Grandi
a32c180667 Minor improvements 2019-12-20 22:19:31 +01:00
Federico Grandi
5ba43bd1de Update docs 2019-12-20 22:17:58 +01:00
Federico Grandi
514b397571 Use actions-tagger 2019-12-20 22:17:37 +01:00
Federico Grandi
0a723093dc Delete build-release.yml 2019-12-14 23:36:50 +01:00
Federico Grandi
f85bf9b85e Last test with auto-building dist branch 2019-12-14 23:29:49 +01:00
Federico Grandi
2096009ef6 Bump version 2019-12-14 23:25:20 +01:00
Federico Grandi
8063b07a5a Edit workflows 2019-12-14 23:14:32 +01:00
Federico Grandi
dd4d657304 Back to manual pushing for releases 2019-12-14 23:10:48 +01:00
Federico Grandi
983180c6c6 Speed up the whole thing 2019-12-14 23:04:14 +01:00
Federico Grandi
aecfd6262a Update workflow to use self-compilation 2019-12-14 22:52:07 +01:00
Federico Grandi
b5a17167bf [auto] Update compiled version 2019-12-14 21:29:45 +00:00
Federico Grandi
c3549913c6 Implement changes of v2.2.0 2019-12-14 22:28:47 +01:00
Federico Grandi
b4fc1efdd2 Delete entrypoint.sh 2019-12-14 22:07:32 +01:00
Federico Grandi
01b3042145 Update workflows 2019-12-14 22:02:25 +01:00
Federico Grandi
e5272e4c09 Remove modules from source 2019-12-14 21:58:11 +01:00
Federico Grandi
f118062594 Update with working working version (#12)
* Fix workflow

* Trigger

* [auto] Update compiled version

* [auto] Commit modules

* Push Windows changes

* Fix

* [auto] Update compiled version

* Try removing cwd

* [auto] Update compiled version

* Try with path module

* [auto] Update compiled version

* Fix path

* [auto] Update compiled version

* Use raw path

* [auto] Update compiled version

* Other path

* [auto] Update compiled version

* Avoid @action/exec

* [auto] Update compiled version

* test

* [auto] Update compiled version

* test

* [auto] Update compiled version

* test

* [auto] Update compiled version

* test

* [auto] Update compiled version

* Try with shelljs

* [auto] Update compiled version

* Fix my stupidity

* Copy scripts to local dir

* [auto] Update compiled version

* Still use path

* [auto] Update compiled version

* Delete entrypoint.sh

* [auto] Update compiled version

* Make file executable

* [auto] Update compiled version

* Try using bash

* [auto] Update compiled version
2019-12-14 21:47:13 +01:00
Federico Grandi
d81e04e96c [auto] Update compiled version 2019-12-10 20:10:39 +00:00
Federico Grandi
33d0a0858a Fix workflows 2019-12-10 21:09:49 +01:00
Federico Grandi
5277b29cf2 Add build workflows 2019-12-10 21:00:28 +01:00
Federico Grandi
463ebc38cb Update gitignore 2019-12-10 20:51:12 +01:00
Federico Grandi
b99985e9be Add lib directory 2019-12-10 20:50:52 +01:00
Federico Grandi
bfb772f923 Move from Docker to TS/Node 2019-12-10 20:50:40 +01:00
Federico Grandi
b1b499b985 Add node package files
Ignore node_modules folder
2019-12-10 20:49:57 +01:00
Federico Grandi
7a1f5ecb56 Fix version in docs 2019-12-07 20:53:12 +01:00
Federico Grandi
6d22917a33 Bump version in docs 2019-12-07 20:52:18 +01:00
Federico Grandi
cf96c454b6 Fix branch conflicts (#7)
* Add branch check

* Improve docs
2019-12-07 20:50:05 +01:00
Federico Grandi
98ce691ee3 Merge pull request #3 from EndBug/force
Add force option
2019-09-19 22:21:27 +02:00
Federico Grandi
abd5c01a4d Switch version in docs 2019-09-19 22:21:08 +02:00
Federico Grandi
f97486922d Fix if/else 2019-09-19 22:15:41 +02:00
Federico Grandi
a34577c63e Add force option 2019-09-19 22:09:51 +02:00
Federico Grandi
04cd48bddf Force quotes 2019-09-18 23:06:22 +02:00
Federico Grandi
2de99109b2 Merge pull request #2 from EndBug/better-paths
Add patterns
2019-09-18 23:01:21 +02:00
Federico Grandi
7f082ab428 Add patterns 2019-09-18 23:00:21 +02:00
Federico Grandi
782b6b1816 Merge pull request #1 from EndBug/better-paths
Better paths
2019-09-18 22:51:32 +02:00
Federico Grandi
6a097ea13d Little tweak to README 2019-09-18 22:50:09 +02:00
Federico Grandi
bac719afe5 Use quotes 2019-09-18 22:34:38 +02:00
Federico Grandi
58ecc16393 Allow multiple paths 2019-09-18 22:30:30 +02:00
Federico Grandi
0f9f6c2d95 Add latest-tag to workflows 2019-09-18 19:44:33 +02:00
16 changed files with 1730 additions and 102 deletions

63
.eslintrc Normal file
View File

@@ -0,0 +1,63 @@
{
"env": {
"node": true,
"browser": true,
"amd": true,
"es6": true
},
"root": true,
"extends": [
"eslint:recommended"
],
"plugins": [
"@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"no-cond-assign": [
2,
"except-parens"
],
"no-use-before-define": [
2,
{
"functions": false,
"classes": false,
"variables": false
}
],
"new-cap": 0,
"no-caller": 2,
"no-undef": 2,
"no-unused-vars": 1,
"no-empty": [
"error",
{
"allowEmptyCatch": true
}
],
"no-console": "off",
"prefer-const": [
"warn",
{
"destructuring": "all"
}
],
"quotes": [
"warn",
"single"
],
"semi": [
"warn",
"never"
],
"spaced-comment": "warn"
}
}

36
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,36 @@
name: Build
on:
push:
branches-ignore:
- dist
paths:
- src/**
- .github/workflows/build.yml
jobs:
build:
name: Build compiled JS version
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install dependencies
run: npm install
- name: Compile TypeScript into compressed JavaScript
run: npm run build
- name: Commit changes
uses: EndBug/add-and-commit@v4.0.0
with:
message: "[auto] Update compiled version"
add: lib
force: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

15
.github/workflows/versioning.yml vendored Normal file
View File

@@ -0,0 +1,15 @@
name: Keep the versions up-to-date
on:
release:
types: [published, edited]
jobs:
actions-tagger:
runs-on: windows-latest
steps:
- uses: Actions-R-Us/actions-tagger@latest
with:
publish_latest: true
env:
GITHUB_TOKEN: "${{secrets.GITHUB_TOKEN}}"

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
node_modules
build
lib

View File

@@ -1,14 +0,0 @@
FROM alpine/git:1.0.7
LABEL "com.github.actions.name"="Add & Commit"
LABEL "com.github.actions.description"="Add & commit files from a path directly from GitHub Actions"
LABEL "com.github.actions.icon"="git-commit"
LABEL "com.github.actions.color"="black"
LABEL "repository"="https://github.com/EndBug/add-and-commit"
LABEL "homepage"="https://github.com/EndBug/add-and-commit"
LABEL "maintainer"="Federico Grandi <fgrandi30@gmail.com>"
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["sh", "/entrypoint.sh"]

View File

@@ -10,32 +10,59 @@ This action lets you choose the path that you want to use when adding & committi
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@v1.0.0 # 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 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: ./*.js
# 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
- `author_email` : the email of the user that will be displayed as the author of the commit
- `message` : the message for the commit
- `path` : the path to stage files from
### 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.
### Example:
### Adding files:
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:
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 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:
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 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.
### Examples:
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
@@ -47,12 +74,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
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: 10.0.0
node-version: 12.x
- name: Install dependencies
run: npm install
@@ -61,16 +88,47 @@ jobs:
run: eslint "src/**" --fix
- name: Commit changes
uses: EndBug/add-and-commit@v1.0.0
uses: EndBug/add-and-commit@v4
with:
author_name: Your Name
author_email: mail@example.com
message: "Your commit message"
path: ./*.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 checkout 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.
This action is distributed under the MIT license, check the [license](LICENSE) for more info.

View File

@@ -1,28 +1,38 @@
name: 'Add & Commit'
description: 'Add & commit files from a path directly from GitHub Actions'
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: true
default: 'Add & Commit GitHub Action'
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: true
default: 'actions@github.com'
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
default: "false"
message:
description: 'The message for the commit'
required: true
default: 'Commit from GitHub Actions'
path:
description: 'The path to stage files from'
required: true
default: './**/*.*'
description: The message for the commit
required: false
default: Commit from GitHub Actions
remove:
description: Arguments for the git rm command
required: false
default: ""
runs:
using: 'docker'
image: 'Dockerfile'
using: node12
main: lib/index.js
branding:
icon: 'git-commit'
color: black
branding:
icon: git-commit
color: gray-dark

View File

@@ -1,48 +0,0 @@
#!/bin/sh
set -eu
# 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 "actions@github.com"
git config --global user.name "Add & Commit GitHub Action"
}
# This is needed to make the check work for untracked files
echo "Staging files in commit path..."
git add "${INPUT_PATH}"
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
git_setup
git fetch
# Switch to branch from current Workflow run
echo "Creating and switching branch..."
git branch "${GITHUB_REF:11}"
git checkout "${GITHUB_REF:11}"
echo "Adding files..."
git add "${INPUT_PATH}"
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}"
else
echo "Working tree clean. Nothing to commit."
fi

0
lib/.gitkeep Normal file
View File

73
lib/entrypoint.sh Executable file
View File

@@ -0,0 +1,73 @@
#!/bin/bash
set -u
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 --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}"
else
echo "Working tree clean. Nothing to commit."
fi

1
lib/index.js Normal file
View File

@@ -0,0 +1 @@
module.exports=function(e,t){"use strict";var r={};function __webpack_require__(t){if(r[t]){return r[t].exports}var n=r[t]={i:t,l:false,exports:{}};e[t].call(n.exports,n,n.exports,__webpack_require__);n.l=true;return n.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(131)}return startup()}({87:function(e){e.exports=require("os")},129:function(e){e.exports=require("child_process")},131:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});const n=r(470);const o=r(622);const s=r(129);try{checkInputs();s.execFileSync(r.ab+"entrypoint.sh")}catch(e){n.setFailed(e)}function checkInputs(){var e,t,r;const o=process.env.GITHUB_EVENT_PATH;const s=o&&((t=(e=require(o))===null||e===void 0?void 0:e.head_commit)===null||t===void 0?void 0:t.author);if(s){setDefault("author_name",s.name);setDefault("author_email",s.email)}else{if(!n.getInput("author_name")||!n.getInput("author_email"))n.warning(`Unable to fetch author info: couldn't find ${!o?"event path":!((r=require(o))===null||r===void 0?void 0:r.head_commit)?"commit":"commit author"}.`);setDefault("author_name","Add & Commit Action");setDefault("author_email","actions@github.com")}n.info(`Using '${n.getInput("author_name")} <${n.getInput("author_email")}>' as author.`)}function setDefault(e,t){const r="INPUT_"+e.toUpperCase();if(!process.env[r])process.env[r]=t}},431:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(Object.hasOwnProperty.call(e,r))t[r]=e[r];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const o=n(r(87));function issueCommand(e,t,r){const n=new Command(e,t,r);process.stdout.write(n.toString()+o.EOL)}t.issueCommand=issueCommand;function issue(e,t=""){issueCommand(e,{},t)}t.issue=issue;const s="::";class Command{constructor(e,t,r){if(!e){e="missing.command"}this.command=e;this.properties=t;this.message=r}toString(){let e=s+this.command;if(this.properties&&Object.keys(this.properties).length>0){e+=" ";let t=true;for(const r in this.properties){if(this.properties.hasOwnProperty(r)){const n=this.properties[r];if(n){if(t){t=false}else{e+=","}e+=`${r}=${escapeProperty(n)}`}}}}e+=`${s}${escapeData(this.message)}`;return e}}function escapeData(e){return(e||"").replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function escapeProperty(e){return(e||"").replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")}},470:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}return new(r||(r=Promise))(function(r,o){function fulfilled(e){try{step(n.next(e))}catch(e){o(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){o(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};var o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(Object.hasOwnProperty.call(e,r))t[r]=e[r];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const s=r(431);const i=o(r(87));const u=o(r(622));var a;(function(e){e[e["Success"]=0]="Success";e[e["Failure"]=1]="Failure"})(a=t.ExitCode||(t.ExitCode={}));function exportVariable(e,t){process.env[e]=t;s.issueCommand("set-env",{name:e},t)}t.exportVariable=exportVariable;function setSecret(e){s.issueCommand("add-mask",{},e)}t.setSecret=setSecret;function addPath(e){s.issueCommand("add-path",{},e);process.env["PATH"]=`${e}${u.delimiter}${process.env["PATH"]}`}t.addPath=addPath;function getInput(e,t){const r=process.env[`INPUT_${e.replace(/ /g,"_").toUpperCase()}`]||"";if(t&&t.required&&!r){throw new Error(`Input required and not supplied: ${e}`)}return r.trim()}t.getInput=getInput;function setOutput(e,t){s.issueCommand("set-output",{name:e},t)}t.setOutput=setOutput;function setFailed(e){process.exitCode=a.Failure;error(e)}t.setFailed=setFailed;function isDebug(){return process.env["RUNNER_DEBUG"]==="1"}t.isDebug=isDebug;function debug(e){s.issueCommand("debug",{},e)}t.debug=debug;function error(e){s.issue("error",e)}t.error=error;function warning(e){s.issue("warning",e)}t.warning=warning;function info(e){process.stdout.write(e+i.EOL)}t.info=info;function startGroup(e){s.issue("group",e)}t.startGroup=startGroup;function endGroup(){s.issue("endgroup")}t.endGroup=endGroup;function group(e,t){return n(this,void 0,void 0,function*(){startGroup(e);let r;try{r=yield t()}finally{endGroup()}return r})}t.group=group;function saveState(e,t){s.issueCommand("save-state",{name:e},t)}t.saveState=saveState;function getState(e){return process.env[`STATE_${e}`]||""}t.getState=getState},622:function(e){e.exports=require("path")}});

1226
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

40
package.json Normal file
View File

@@ -0,0 +1,40 @@
{
"name": "add-and-commit",
"version": "4.0.1",
"description": "Add & commit files from a path directly from GitHub Actions",
"main": "lib/index.js",
"scripts": {
"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": {
"type": "git",
"url": "git+https://github.com/EndBug/add-and-commit.git"
},
"keywords": [
"github",
"action",
"version",
"npm",
"node"
],
"author": "Federico Grandi <fgrandi30@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/EndBug/add-and-commit/issues"
},
"homepage": "https://github.com/EndBug/add-and-commit#readme",
"dependencies": {
"@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",
"@zeit/ncc": "^0.21.1",
"eslint": "^6.8.0",
"typescript": "^3.6.4"
}
}

73
src/entrypoint.sh Executable file
View File

@@ -0,0 +1,73 @@
#!/bin/bash
set -u
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 --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}"
else
echo "Working tree clean. Nothing to commit."
fi

31
src/main.ts Normal file
View File

@@ -0,0 +1,31 @@
import { info, setFailed, getInput, warning } from '@actions/core'
import { join as path } from 'path'
import { execFileSync } from 'child_process'
try {
checkInputs()
execFileSync(path(__dirname, 'entrypoint.sh'))
} catch (err) {
setFailed(err)
}
function checkInputs() {
const eventPath = process.env.GITHUB_EVENT_PATH
const author = eventPath && require(eventPath)?.head_commit?.author
if (author) {
setDefault('author_name', author.name)
setDefault('author_email', author.email)
} else {
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')
}
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
}

61
tsconfig.json Normal file
View File

@@ -0,0 +1,61 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./build", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": [
"node_modules",
"**/*.test.ts"
]
}