Skip to content

Commit

Permalink
Add dry-run input
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed May 13, 2021
1 parent 1424fdc commit 62bf12f
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 102 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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);
}
Loading

0 comments on commit 62bf12f

Please sign in to comment.