Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d77fa2c79 | ||
|
|
f6b13bc7e9 | ||
|
|
116c918fd3 | ||
|
|
fbbcae9aa5 | ||
|
|
7bd2b1ca10 | ||
|
|
61d14d1bee | ||
|
|
6a75638ec3 | ||
|
|
ff38b6c4a6 | ||
|
|
e67ce7f439 | ||
|
|
a83118880c | ||
|
|
a28158a63f | ||
|
|
30030e85c0 | ||
|
|
79fa1f9f98 |
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
@@ -5,6 +5,7 @@ on:
|
||||
- dist
|
||||
paths:
|
||||
- src/**
|
||||
- .github/workflows/build.yml
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -26,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:
|
||||
force: true
|
||||
message: "[auto] Update compiled version"
|
||||
path: lib
|
||||
pattern: "*.js"
|
||||
add: lib
|
||||
force: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -31,7 +31,7 @@ inputs:
|
||||
|
||||
runs:
|
||||
using: node12
|
||||
main: lib/main.js
|
||||
main: lib/index.js
|
||||
|
||||
branding:
|
||||
icon: git-commit
|
||||
|
||||
73
lib/entrypoint.sh
Executable file
73
lib/entrypoint.sh
Executable 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
1
lib/index.js
Normal 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")}});
|
||||
@@ -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;setDefault("author_name",b.name),setDefault("author_email",b.email)}else core.warning("No event path available, unable to fetch author info."),setDefault("author_name","Add & Commit Action"),setDefault("author_email","actions@github.com");core.info(`Using '${core.getInput("author_name")} <${core.getInput("author_email")}>' as author.`)}function setDefault(a,b){const c="INPUT_"+a.toUpperCase();process.env[c]||(process.env[c]=b)}
|
||||
1321
package-lock.json
generated
1321
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": "4.0.0",
|
||||
"version": "4.0.1",
|
||||
"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"
|
||||
}
|
||||
|
||||
20
src/main.ts
20
src/main.ts
@@ -1,26 +1,28 @@
|
||||
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 { execFileSync } from 'child_process'
|
||||
|
||||
try {
|
||||
checkInputs()
|
||||
shell.exec(path.join(__dirname, '../src/entrypoint.sh'))
|
||||
execFileSync(path(__dirname, 'entrypoint.sh'))
|
||||
} catch (err) {
|
||||
core.setFailed(err)
|
||||
setFailed(err)
|
||||
}
|
||||
|
||||
function checkInputs() {
|
||||
const eventPath = process.env.GITHUB_EVENT_PATH
|
||||
if (eventPath) {
|
||||
const { author } = require(eventPath).head_commit
|
||||
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 (!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 '${core.getInput('author_name')} <${core.getInput('author_email')}>' as author.`)
|
||||
|
||||
info(`Using '${getInput('author_name')} <${getInput('author_email')}>' as author.`)
|
||||
}
|
||||
|
||||
function setDefault(input: string, value: string) {
|
||||
|
||||
Reference in New Issue
Block a user