Skip to content

Commit

Permalink
Updated Commit Handler With Custom Commit Message & SKIP CI
Browse files Browse the repository at this point in the history
  • Loading branch information
varunsridharan committed Feb 11, 2021
1 parent 1144782 commit ad7e795
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 21 deletions.
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ inputs:
description: "Whether or not you want to do a pull request. Only works when branch name is provided. Default false"
required: false
default: 'false'
SKIP_CI:
description: "Adds [skip ci] to commit message which will avoid running github actions in targer repository"
required: false
default: 'false'
COMMIT_MESSAGE:
description: "Provide your own custom commit MESSAGE"
required: false
default: 'false'

runs:
using: 'node12'
Expand Down
62 changes: 45 additions & 17 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,17 @@ const source_file_location = async( WORKFLOW_FILES_DIR, REPOSITORY_OWNER, REPOSI
return _return;
};

const commitfile = async( local_path ) => {
const commitfile = async( local_path, skip_ci, commit_message ) => {
let message = `💬 - Files Synced | Runner ID : ${toolkit.input.env( 'GITHUB_RUN_NUMBER' )} | ⚡ Triggered By ${toolkit.input.env( 'GITHUB_REPOSITORY' )}`;

if( typeof commit_message === 'undefined' && true === skip_ci ) {
message = message + ' | [skip ci] ';
}

if( typeof commit_message === 'string' && ( commit_message !== 'false' && commit_message !== 'true' ) ) {
message = commit_message;
}

return await toolkit.git.commit( local_path, message );
};

Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ async function run() {
let REPOSITORIES = require( './variables' ).REPOSITORIES;
let WORKFLOW_FILES = require( './variables' ).WORKFLOW_FILES;
let PULL_REQUEST = require( './variables' ).PULL_REQUEST;
let SKIP_CI = require( './variables' ).SKIP_CI;
let COMMIT_MESSAGE = require( './variables' ).COMMIT_MESSAGE;

toolkit.log( '-------------------------------------------------------' );
toolkit.log( '⚙️ Basic Config' );
Expand All @@ -24,6 +26,8 @@ async function run() {
toolkit.log( ` * DRY_RUN : ${DRY_RUN}` );
toolkit.log( ` * WORKFLOW_FILES_DIR : ${WORKFLOW_FILES_DIR}` );
toolkit.log( ` * WORKSPACE : ${WORKSPACE}` );
toolkit.log( ` * SKIP_CI : ${SKIP_CI}` );
toolkit.log( ` * COMMIT_MESSAGE : ${COMMIT_MESSAGE}` );
toolkit.log( '-------------------------------------------------------' );
toolkit.log( '' );

Expand Down Expand Up @@ -112,7 +116,7 @@ async function run() {
if( '' === haschange ) {
toolkit.log.green( ' No changes detected' );
} else if( false !== haschange ) {
await helper.commitfile( local_path );
await helper.commitfile( local_path, SKIP_CI, COMMIT_MESSAGE );
modified.push( `${workflow_file.dest}` );
}
}
Expand All @@ -133,7 +137,7 @@ async function run() {
if( '' === haschange && !COMMIT_EACH_FILE ) {
toolkit.log.success( 'No Changes Are Done :', ' ' );
} else if( false !== haschange && !COMMIT_EACH_FILE ) {
await helper.commitfile( local_path );
await helper.commitfile( local_path, SKIP_CI, COMMIT_MESSAGE );
modified.push( local_path );
}

Expand Down
4 changes: 4 additions & 0 deletions src/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const AUTO_CREATE_NEW_BRANCH = toolkit.input.tobool( core.getInput( 'AUTO_CREATE
const COMMIT_EACH_FILE = toolkit.input.tobool( core.getInput( 'COMMIT_EACH_FILE' ) );
const DRY_RUN = toolkit.input.tobool( core.getInput( 'DRY_RUN' ) );
const PULL_REQUEST = toolkit.input.tobool( core.getInput( 'PULL_REQUEST' ) );
const SKIP_CI = toolkit.input.tobool( core.getInput( 'SKIP_CI' ) );
const GITHUB_TOKEN = core.getInput( 'GITHUB_TOKEN' );
const RAW_REPOSITORIES = core.getInput( 'REPOSITORIES' );
const COMMIT_MESSAGE = core.getInput( 'COMMIT_MESSAGE' );
const RAW_WORKFLOW_FILES = core.getInput( 'WORKFLOW_FILES' );
const WORKFLOW_FILES_DIR = core.getInput( 'WORKFLOW_FILES_DIR' );
const REPOSITORIES = RAW_REPOSITORIES.split( '\n' );
Expand All @@ -29,4 +31,6 @@ module.exports = {
WORKFLOW_FILES,
WORKSPACE,
GITHUB_WORKSPACE,
SKIP_CI,
COMMIT_MESSAGE
};

0 comments on commit ad7e795

Please sign in to comment.