Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dry_run #513

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
github.ref == 'refs/heads/main'
uses: ./
with:
dry_run: ${{ github.event_name == 'pull_request' }}
# deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_branch: gh-pages
Expand All @@ -122,6 +123,7 @@ jobs:
github.ref == 'refs/heads/main'
uses: ./
with:
dry_run: ${{ github.event_name == 'pull_request' }}
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
# github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages-ubuntu-16.04
Expand All @@ -140,6 +142,7 @@ jobs:
github.ref == 'refs/heads/main'
uses: ./
with:
dry_run: ${{ github.event_name == 'pull_request' }}
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
# github_token: ${{ secrets.GITHUB_TOKEN }}
# personal_token: ${{ secrets.PERSONAL_TOKEN }}
Expand All @@ -159,6 +162,7 @@ jobs:
github.ref == 'refs/heads/main'
uses: ./
with:
dry_run: ${{ github.event_name == 'pull_request' }}
# deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
# personal_token: ${{ secrets.PERSONAL_TOKEN }}
Expand All @@ -178,6 +182,7 @@ jobs:
github.ref == 'refs/heads/main'
uses: ./
with:
dry_run: ${{ github.event_name == 'pull_request' }}
# deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages-ubuntu-20.04
Expand Down
4 changes: 4 additions & 0 deletions __tests__/get-inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
`;
}

Expand Down Expand Up @@ -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', () => {
Expand All @@ -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();

Expand All @@ -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', () => {
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
1 change: 1 addition & 0 deletions lib/index.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/get-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
`);
}

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Inputs {
readonly DisableNoJekyll: boolean;
readonly CNAME: string;
readonly ExcludeAssets: string;
readonly DryRun: boolean;
}

export interface CmdResult {
Expand Down
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ export async function run(): Promise<void> {
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');
Expand Down