diff --git a/__tests__/get-inputs.test.ts b/__tests__/get-inputs.test.ts index 7ff2590..10f11f5 100644 --- a/__tests__/get-inputs.test.ts +++ b/__tests__/get-inputs.test.ts @@ -56,6 +56,7 @@ function getInputsLog(authMethod: string, inps: Inputs): string { [INFO] EnableJekyll (DisableNoJekyll): ${inps.DisableNoJekyll} [INFO] CNAME: ${inps.CNAME} [INFO] ExcludeAssets ${inps.ExcludeAssets} +[INFO] DryRun ${inps.DryRun} `; } @@ -125,6 +126,7 @@ describe('getInputs()', () => { expect(inps.DisableNoJekyll).toBe(false); expect(inps.CNAME).toMatch(''); expect(inps.ExcludeAssets).toMatch('.github'); + expect(inps.DryRun).toBeFalsy(); }); test('get spec inputs', () => { @@ -147,6 +149,7 @@ describe('getInputs()', () => { process.env['INPUT_DISABLE_NOJEKYLL'] = 'true'; process.env['INPUT_CNAME'] = 'github.com'; process.env['INPUT_EXCLUDE_ASSETS'] = '.github'; + process.env['INPUT_DRY_RUN'] = 'true'; const inps: Inputs = getInputs(); @@ -169,6 +172,7 @@ describe('getInputs()', () => { expect(inps.DisableNoJekyll).toBe(true); expect(inps.CNAME).toMatch('github.com'); expect(inps.ExcludeAssets).toMatch('.github'); + expect(inps.DryRun).toBeTruthy(); }); test('get spec inputs enable_jekyll', () => { diff --git a/action.yml b/action.yml index 175640d..5291cdb 100644 --- a/action.yml +++ b/action.yml @@ -77,3 +77,7 @@ inputs: description: 'Set files or directories to exclude from a publish directory.' required: false default: '.github' + dry_run: + description: 'Set true to run the action with dry run mode.' + required: false + default: 'false' diff --git a/src/get-inputs.ts b/src/get-inputs.ts index 1f70517..762d879 100644 --- a/src/get-inputs.ts +++ b/src/get-inputs.ts @@ -29,6 +29,7 @@ export function showInputs(inps: Inputs): void { [INFO] EnableJekyll (DisableNoJekyll): ${inps.DisableNoJekyll} [INFO] CNAME: ${inps.CNAME} [INFO] ExcludeAssets ${inps.ExcludeAssets} +[INFO] DryRun ${inps.DryRun} `); } @@ -67,7 +68,8 @@ export function getInputs(): Inputs { TagMessage: core.getInput('tag_message'), DisableNoJekyll: useBuiltinJekyll, CNAME: core.getInput('cname'), - ExcludeAssets: core.getInput('exclude_assets') + ExcludeAssets: core.getInput('exclude_assets'), + DryRun: (core.getInput('dry_run') || 'false').toUpperCase() === 'TRUE' }; return inps; diff --git a/src/interfaces.ts b/src/interfaces.ts index d1a615d..b21e5dc 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -18,6 +18,7 @@ export interface Inputs { readonly DisableNoJekyll: boolean; readonly CNAME: string; readonly ExcludeAssets: string; + readonly DryRun: boolean; } export interface CmdResult { diff --git a/src/main.ts b/src/main.ts index 6ddf944..cb68f1f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -79,8 +79,11 @@ export async function run(): Promise { core.endGroup(); core.startGroup('Push the commit or tag'); - await push(inps.PublishBranch, inps.ForceOrphan); - await pushTag(inps.TagName, inps.TagMessage); + if (!inps.DryRun) { + core.info(`[INFO] dry run mode, skip pushing`); + await push(inps.PublishBranch, inps.ForceOrphan); + await pushTag(inps.TagName, inps.TagMessage); + } core.endGroup(); core.info('[INFO] Action successfully completed');