Customization for commit message, committer name/email (#9)

This commit is contained in:
Sergey Zwezdin 2019-11-06 06:46:35 +05:00 committed by CrazyMax
parent fc6174a438
commit 560d9799e9
6 changed files with 74 additions and 119 deletions

View File

@ -65,6 +65,9 @@ Following inputs can be used as `step.with` keys
| `repo` | String | GitHub repository where assets will be deployed (default current) |
| `target_branch` | String | Git branch where assets will be deployed (default `gh-pages`) |
| `build_dir` | String | Build directory to deploy |
| `comitter_name` | String | Commit author's name |
| `comitter_email`| String | Commit author's email |
| `commit_message`| String | Commit message |
### environment variables

View File

@ -15,6 +15,15 @@ inputs:
build_dir:
description: 'Build directory to deploy'
required: true
comitter_name:
description: 'Name of the commit author'
default: 'github-actions'
comitter_email:
description: 'Email of the commit author'
default: 'username@users.noreply.github.com'
commit_message:
description: 'Commit description'
default: 'Deploy to GitHub pages'
runs:
using: 'node12'

View File

@ -17,16 +17,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const child_process = __importStar(require("child_process"));
const fs = __importStar(require("fs"));
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
const fs = __importStar(require("fs"));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const repo = core.getInput('repo') || process.env['GITHUB_REPOSITORY'] || '';
const target_branch = core.getInput('target_branch') || 'gh-pages';
const build_dir = core.getInput('build_dir', { required: true });
const username = process.env['GITHUB_ACTOR'] || 'github-actions';
const username = core.getInput('comitter_name') ||
process.env['GITHUB_ACTOR'] ||
'github-actions';
const useremail = core.getInput('comitter_email') || `${username}@users.noreply.github.com`;
const commitmessage = core.getInput('commit_message') || 'Deploy to GitHub pages';
if (!fs.existsSync(build_dir)) {
core.setFailed('⛔️ Build dir does not exist');
return;
@ -35,11 +39,7 @@ function run() {
process.chdir(build_dir);
yield exec.exec('git', ['init']);
yield exec.exec('git', ['config', 'user.name', username]);
yield exec.exec('git', [
'config',
'user.email',
`${username}@users.noreply.github.com`
]);
yield exec.exec('git', ['config', 'user.email', useremail]);
try {
child_process.execSync('git status --porcelain').toString();
}
@ -48,12 +48,7 @@ function run() {
return;
}
yield exec.exec('git', ['add', '.']);
yield exec.exec('git', [
'commit',
'--allow-empty',
'-m',
'Deploy to GitHub pages'
]);
yield exec.exec('git', ['commit', '--allow-empty', '-m', commitmessage]);
let gitURL = String('https://');
if (process.env['GITHUB_PAT']) {
gitURL = gitURL.concat(process.env['GITHUB_PAT']);

View File

@ -1,40 +1,15 @@
{
"_args": [
[
"@actions/core@1.2.0",
"/home/runner/work/ghaction-github-pages/ghaction-github-pages"
]
],
"_from": "@actions/core@1.2.0",
"_id": "@actions/core@1.2.0",
"_inBundle": false,
"_integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw==",
"_location": "/@actions/core",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "@actions/core@1.2.0",
"name": "@actions/core",
"escapedName": "@actions%2fcore",
"scope": "@actions",
"rawSpec": "1.2.0",
"saveSpec": null,
"fetchSpec": "1.2.0"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz",
"_spec": "1.2.0",
"_where": "/home/runner/work/ghaction-github-pages/ghaction-github-pages",
"bugs": {
"url": "https://github.com/actions/toolkit/issues"
},
"name": "@actions/core",
"version": "1.2.0",
"description": "Actions core lib",
"devDependencies": {
"@types/node": "^12.0.2"
},
"keywords": [
"github",
"actions",
"core"
],
"homepage": "https://github.com/actions/toolkit/tree/master/packages/core",
"license": "MIT",
"main": "lib/core.js",
"directories": {
"lib": "lib",
"test": "__tests__"
@ -42,15 +17,6 @@
"files": [
"lib"
],
"homepage": "https://github.com/actions/toolkit/tree/master/packages/core",
"keywords": [
"github",
"actions",
"core"
],
"license": "MIT",
"main": "lib/core.js",
"name": "@actions/core",
"publishConfig": {
"access": "public"
},
@ -63,5 +29,14 @@
"test": "echo \"Error: run tests from root\" && exit 1",
"tsc": "tsc"
},
"version": "1.2.0"
}
"bugs": {
"url": "https://github.com/actions/toolkit/issues"
},
"devDependencies": {
"@types/node": "^12.0.2"
}
,"_resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz"
,"_integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw=="
,"_from": "@actions/core@1.2.0"
}

View File

@ -1,40 +1,15 @@
{
"_args": [
[
"@actions/exec@1.0.1",
"/home/runner/work/ghaction-github-pages/ghaction-github-pages"
]
],
"_from": "@actions/exec@1.0.1",
"_id": "@actions/exec@1.0.1",
"_inBundle": false,
"_integrity": "sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ==",
"_location": "/@actions/exec",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "@actions/exec@1.0.1",
"name": "@actions/exec",
"escapedName": "@actions%2fexec",
"scope": "@actions",
"rawSpec": "1.0.1",
"saveSpec": null,
"fetchSpec": "1.0.1"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.1.tgz",
"_spec": "1.0.1",
"_where": "/home/runner/work/ghaction-github-pages/ghaction-github-pages",
"bugs": {
"url": "https://github.com/actions/toolkit/issues"
},
"name": "@actions/exec",
"version": "1.0.1",
"description": "Actions exec lib",
"devDependencies": {
"@actions/io": "^1.0.1"
},
"keywords": [
"github",
"actions",
"exec"
],
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exec",
"license": "MIT",
"main": "lib/exec.js",
"directories": {
"lib": "lib",
"test": "__tests__"
@ -42,16 +17,6 @@
"files": [
"lib"
],
"gitHead": "a2ab4bcf78e4f7080f0d45856e6eeba16f0bbc52",
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exec",
"keywords": [
"github",
"actions",
"exec"
],
"license": "MIT",
"main": "lib/exec.js",
"name": "@actions/exec",
"publishConfig": {
"access": "public"
},
@ -63,5 +28,15 @@
"test": "echo \"Error: run tests from root\" && exit 1",
"tsc": "tsc"
},
"version": "1.0.1"
}
"bugs": {
"url": "https://github.com/actions/toolkit/issues"
},
"devDependencies": {
"@actions/io": "^1.0.1"
},
"gitHead": "a2ab4bcf78e4f7080f0d45856e6eeba16f0bbc52"
,"_resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.1.tgz"
,"_integrity": "sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ=="
,"_from": "@actions/exec@1.0.1"
}

View File

@ -1,7 +1,7 @@
import * as child_process from 'child_process';
import * as fs from 'fs';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as fs from 'fs';
async function run() {
try {
@ -9,7 +9,14 @@ async function run() {
core.getInput('repo') || process.env['GITHUB_REPOSITORY'] || '';
const target_branch = core.getInput('target_branch') || 'gh-pages';
const build_dir = core.getInput('build_dir', {required: true});
const username = process.env['GITHUB_ACTOR'] || 'github-actions';
const username =
core.getInput('comitter_name') ||
process.env['GITHUB_ACTOR'] ||
'github-actions';
const useremail =
core.getInput('comitter_email') || `${username}@users.noreply.github.com`;
const commitmessage =
core.getInput('commit_message') || 'Deploy to GitHub pages';
if (!fs.existsSync(build_dir)) {
core.setFailed('⛔️ Build dir does not exist');
@ -23,11 +30,7 @@ async function run() {
process.chdir(build_dir);
await exec.exec('git', ['init']);
await exec.exec('git', ['config', 'user.name', username]);
await exec.exec('git', [
'config',
'user.email',
`${username}@users.noreply.github.com`
]);
await exec.exec('git', ['config', 'user.email', useremail]);
try {
child_process.execSync('git status --porcelain').toString();
@ -37,12 +40,7 @@ async function run() {
}
await exec.exec('git', ['add', '.']);
await exec.exec('git', [
'commit',
'--allow-empty',
'-m',
'Deploy to GitHub pages'
]);
await exec.exec('git', ['commit', '--allow-empty', '-m', commitmessage]);
let gitURL = String('https://');
if (process.env['GITHUB_PAT']) {