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

Add dry-run input #144

Merged
merged 1 commit into from May 13, 2021
Merged
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/ci.yml
Expand Up @@ -7,6 +7,10 @@ on:
branches:
- 'dev'
- 'releases/v*'
pull_request:
branches:
- 'dev'
- 'releases/v*'

jobs:
ci:
Expand Down Expand Up @@ -92,5 +96,6 @@ jobs:
target_branch: ${{ matrix.target_branch }}
keep_history: ${{ matrix.keep_history }}
build_dir: public
dry-run: ${{ github.event_name == 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -138,6 +138,7 @@ Following inputs can be used as `step.with` keys
| `commit_message` | String | Commit message (default `Deploy to GitHub pages`) |
| `fqdn` | String | Write the given domain name to the CNAME file |
| `jekyll` | Bool | Allow Jekyll to build your site (default `true`) |
| `dry-run` | Bool | If enabled, nothing will be pushed (default `false`) |

### environment variables

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -45,6 +45,10 @@ inputs:
description: 'Allow Jekyll to build your site'
default: 'true'
required: false
dry-run:
description: 'If enabled, nothing will be pushed'
default: 'false'
required: false

runs:
using: 'node12'
Expand Down
119 changes: 68 additions & 51 deletions dist/index.js

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

50 changes: 27 additions & 23 deletions src/git.ts
@@ -1,4 +1,5 @@
import * as exec from './exec';
import * as mexec from './exec';
import * as exec from '@actions/exec';

export const defaults = {
targetBranch: 'gh-pages',
Expand All @@ -7,51 +8,51 @@ export const defaults = {
message: 'Deploy to GitHub pages'
};

const git = async (args: string[] = []): Promise<string> => {
return await exec.exec(`git`, args, true).then(res => {
export async function remoteBranchExists(remoteURL: string, branch: string): Promise<boolean> {
return await mexec.exec('git', ['ls-remote', '--heads', remoteURL, branch], true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
return res.stdout.trim();
});
};

export async function remoteBranchExists(remoteURL: string, branch: string): Promise<boolean> {
return await git(['ls-remote', '--heads', remoteURL, branch]).then(output => {
return output.trim().length > 0;
return res.stdout.trim().length > 0;
});
}

export async function clone(remoteURL: string, branch: string, dest: string): Promise<void> {
await git(['clone', '--quiet', '--branch', branch, '--depth', '1', remoteURL, dest]);
await exec.exec('git', ['clone', '--quiet', '--branch', branch, '--depth', '1', remoteURL, dest]);
}

export async function init(dest: string): Promise<void> {
await git(['init', dest]);
await exec.exec('git', ['init', dest]);
}

export async function checkout(branch: string): Promise<void> {
await git(['checkout', '--orphan', branch]);
await exec.exec('git', ['checkout', '--orphan', branch]);
}

export async function isDirty(): Promise<boolean> {
return await git(['status', '--short']).then(output => {
return output.trim().length > 0;
return await mexec.exec('git', ['status', '--short'], true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
return res.stdout.trim().length > 0;
});
}

export async function hasChanges(): Promise<boolean> {
return await git(['status', '--porcelain']).then(output => {
return output.trim().length > 0;
return await mexec.exec('git', ['status', '--porcelain'], true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
return res.stdout.trim().length > 0;
});
}

export async function setConfig(key: string, value: string): Promise<void> {
await git(['config', key, value]);
await exec.exec('git', ['config', key, value]);
}

export async function add(pattern: string): Promise<void> {
await git(['add', '--all', pattern]);
await exec.exec('git', ['add', '--all', pattern]);
}

export async function commit(allowEmptyCommit: boolean, author: string, message: string): Promise<void> {
Expand All @@ -64,12 +65,15 @@ export async function commit(allowEmptyCommit: boolean, author: string, message:
args.push('--author', author);
}
args.push('--message', message);
await git(args);
await exec.exec('git', args);
}

export async function showStat(): Promise<string> {
return await git(['show', `--stat-count=2000`, 'HEAD']).then(output => {
return output;
return await mexec.exec('git', ['show', `--stat-count=2000`, 'HEAD'], true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
return res.stdout.trim();
});
}

Expand All @@ -80,5 +84,5 @@ export async function push(remoteURL: string, branch: string, force: boolean): P
args.push('--force');
}
args.push(remoteURL, branch);
await git(args);
await exec.exec('git', args);
}