-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from s0/skip-empty-commits
Allow skipping of empty commits
- Loading branch information
Showing
7 changed files
with
172 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
jest.setTimeout(15000); | ||
jest.setTimeout(1000 * 60 * 60); |
12 changes: 12 additions & 0 deletions
12
action/test/specs/__snapshots__/ssh-skip-empty-commits.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Skip empty commits 1`] = ` | ||
"msg:Update branch-a to output generated at <sha1> | ||
tree:b60735c9b4d9728b47c0f2752bb973cd6f3d9d80 | ||
author:s0 <[email protected]> | ||
msg:Update branch-a to output generated at <sha2> | ||
tree:8bf87c66655949e66937b11593cc4ae732d1f610 | ||
author:s0 <[email protected]>" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as path from 'path'; | ||
|
||
import * as util from '../util'; | ||
|
||
const REPO_DIR = path.join(util.REPOS_DIR, 'ssh-skip-empty-commits.git'); | ||
const DATA_DIR = path.join(util.DATA_DIR, 'ssh-skip-empty-commits'); | ||
|
||
it('Skip empty commits', async () => { | ||
|
||
// Create empty repo | ||
await util.mkdir(REPO_DIR); | ||
await util.execWithOutput('git init --bare', { cwd: REPO_DIR }); | ||
|
||
// Create dummy data | ||
await util.mkdir(DATA_DIR); | ||
await util.mkdir(path.join(DATA_DIR, 'dummy')); | ||
await util.writeFile(path.join(DATA_DIR, 'dummy', 'baz'), 'foobar'); | ||
await util.writeFile(path.join(DATA_DIR, 'dummy', '.bat'), 'foobar'); | ||
|
||
// Run Action | ||
await util.runWithGithubEnv( | ||
path.basename(__filename), | ||
{ | ||
REPO: 'ssh://git@git-ssh/git-server/repos/ssh-skip-empty-commits.git', | ||
BRANCH: 'branch-a', | ||
FOLDER: DATA_DIR, | ||
SSH_PRIVATE_KEY: (await util.readFile(util.SSH_PRIVATE_KEY)).toString(), | ||
KNOWN_HOSTS_FILE: util.KNOWN_HOSTS, | ||
SKIP_EMPTY_COMMITS: 'true', | ||
}, | ||
's0/test', | ||
{}, | ||
's0', | ||
); | ||
const fullSha1 = await util.getFullRepoSha(); | ||
// Change files and run action again | ||
await util.writeFile(path.join(DATA_DIR, 'dummy', 'bat'), 'foobar'); | ||
await util.runWithGithubEnv( | ||
path.basename(__filename), | ||
{ | ||
REPO: 'ssh://git@git-ssh/git-server/repos/ssh-skip-empty-commits.git', | ||
BRANCH: 'branch-a', | ||
FOLDER: DATA_DIR, | ||
SSH_PRIVATE_KEY: (await util.readFile(util.SSH_PRIVATE_KEY)).toString(), | ||
KNOWN_HOSTS_FILE: util.KNOWN_HOSTS, | ||
SKIP_EMPTY_COMMITS: 'true', | ||
}, | ||
's0/test', | ||
{}, | ||
's0', | ||
); | ||
const fullSha2 = await util.getFullRepoSha(); | ||
// Run the action again with no content changes to test skip behaviour | ||
await util.runWithGithubEnv( | ||
path.basename(__filename), | ||
{ | ||
REPO: 'ssh://git@git-ssh/git-server/repos/ssh-skip-empty-commits.git', | ||
BRANCH: 'branch-a', | ||
FOLDER: DATA_DIR, | ||
SSH_PRIVATE_KEY: (await util.readFile(util.SSH_PRIVATE_KEY)).toString(), | ||
KNOWN_HOSTS_FILE: util.KNOWN_HOSTS, | ||
SKIP_EMPTY_COMMITS: 'true', | ||
}, | ||
's0/test', | ||
{}, | ||
's0', | ||
); | ||
|
||
// Check that the log of the repo is as expected | ||
// (check tree-hash, commit message, and author) | ||
// TODO: test {msg} placeholder and running action outside of a git repo | ||
let log = (await util.exec( | ||
'git log --pretty="format:msg:%B%ntree:%T%nauthor:%an <%ae>" branch-a', | ||
{ | ||
cwd: REPO_DIR | ||
} | ||
)).stdout; | ||
const sha1 = fullSha1.substr(0, 7); | ||
const sha2 = fullSha2.substr(0, 7); | ||
const cleanedLog = log.replace(sha1, '<sha1>').replace(sha2, '<sha2>'); | ||
expect(cleanedLog).toMatchSnapshot(); | ||
}); |