-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1245bc
commit 55e55bb
Showing
7 changed files
with
254 additions
and
3 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
10 changes: 10 additions & 0 deletions
10
action/test/specs/__snapshots__/ssh-target-dir-exists.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,10 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Deploy to a branch on a custom dir that exists 1`] = ` | ||
"msg:Update master to output generated at <sha> | ||
tree:91548ed23fe65d56dfcbb58357a11c32c9b0b95d | ||
author:s0 <[email protected]> | ||
msg:initial | ||
tree:d019febe4c92496949f9d9eb3eff95d8435aff76 | ||
author:Test User <[email protected]>" | ||
`; |
10 changes: 10 additions & 0 deletions
10
action/test/specs/__snapshots__/ssh-target-dir-no-exists.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,10 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Deploy to a branch on a custom dir that does not exist 1`] = ` | ||
"msg:Update master to output generated at <sha> | ||
tree:91548ed23fe65d56dfcbb58357a11c32c9b0b95d | ||
author:s0 <[email protected]> | ||
msg:initial | ||
tree:2ba0f344a4227360745f8b743b28af58d010c2f4 | ||
author:Test User <[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { promises as fs } from 'fs'; | ||
import * as path from 'path'; | ||
import { mkdirP } from '@actions/io'; | ||
|
||
import * as util from '../util'; | ||
import { prepareTestFolders } from '../util/io'; | ||
import { listTree } from '../util/git'; | ||
|
||
it('Deploy to a branch on a custom dir that exists', async () => { | ||
const folders = await prepareTestFolders({ __filename }); | ||
|
||
// Create empty repo | ||
await util.wrappedExec('git init --bare', { cwd: folders.repoDir }); | ||
|
||
// Clone repo, and create an initial commit | ||
await util.wrappedExec(`git clone "${folders.repoDir}" clone`, { | ||
cwd: folders.workDir, | ||
}); | ||
await fs.writeFile(path.join(folders.repoCloneDir, 'initial1'), 'foobar1'); | ||
await fs.writeFile(path.join(folders.repoCloneDir, 'initial2'), 'foobar2'); | ||
await mkdirP(path.join(folders.repoCloneDir, 'folder')); | ||
await fs.writeFile(path.join(folders.repoCloneDir, 'folder', 'a'), 'foobar1'); | ||
await fs.writeFile(path.join(folders.repoCloneDir, 'folder', 'b'), 'foobar2'); | ||
await mkdirP(path.join(folders.repoCloneDir, 'custom')); | ||
await fs.writeFile(path.join(folders.repoCloneDir, 'custom', 'a'), 'foobar1'); | ||
await util.wrappedExec(`git add -A .`, { cwd: folders.repoCloneDir }); | ||
await util.wrappedExec(`git config user.name "Test User"`, { | ||
cwd: folders.repoCloneDir, | ||
}); | ||
await util.wrappedExec(`git config user.email "[email protected]"`, { | ||
cwd: folders.repoCloneDir, | ||
}); | ||
await util.wrappedExec(`git commit -m initial`, { | ||
cwd: folders.repoCloneDir, | ||
}); | ||
await util.wrappedExec(`git push origin master`, { | ||
cwd: folders.repoCloneDir, | ||
}); | ||
|
||
// Create dummy data | ||
await mkdirP(path.join(folders.dataDir, 'dummy')); | ||
await fs.writeFile(path.join(folders.dataDir, 'dummy', 'baz'), 'foobar'); | ||
await fs.writeFile(path.join(folders.dataDir, 'dummy', '.bat'), 'foobar'); | ||
|
||
// Run Action | ||
await util.runWithGithubEnv( | ||
path.basename(__filename), | ||
{ | ||
REPO: folders.repoUrl, | ||
BRANCH: 'master', | ||
FOLDER: folders.dataDir, | ||
SSH_PRIVATE_KEY: (await fs.readFile(util.SSH_PRIVATE_KEY)).toString(), | ||
KNOWN_HOSTS_FILE: util.KNOWN_HOSTS, | ||
TARGET_DIR: 'custom' | ||
}, | ||
's0/test', | ||
{}, | ||
's0' | ||
); | ||
|
||
// Check that the list of files in the root of the target repo is as expected | ||
expect(await listTree(folders.repoDir)).toEqual([ | ||
'.', | ||
'custom', | ||
'custom/dummy', | ||
'custom/dummy/.bat', | ||
'custom/dummy/baz', | ||
'folder', | ||
'folder/a', | ||
'folder/b', | ||
'initial1', | ||
'initial2', | ||
]); | ||
|
||
// Check that the log of the repo is as expected | ||
// (check tree-hash, commit message, and author) | ||
const log = ( | ||
await util.exec( | ||
'git log --pretty="format:msg:%s%ntree:%T%nauthor:%an <%ae>" master', | ||
{ | ||
cwd: folders.repoDir, | ||
} | ||
) | ||
).stdout; | ||
const sha = await util.getRepoSha(); | ||
const cleanedLog = log.replace(sha, '<sha>'); | ||
expect(cleanedLog).toMatchSnapshot(); | ||
}); |
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,86 @@ | ||
import { promises as fs } from 'fs'; | ||
import * as path from 'path'; | ||
import { mkdirP } from '@actions/io'; | ||
|
||
import * as util from '../util'; | ||
import { prepareTestFolders } from '../util/io'; | ||
import { listTree } from '../util/git'; | ||
|
||
it('Deploy to a branch on a custom dir that does not exist', async () => { | ||
const folders = await prepareTestFolders({ __filename }); | ||
|
||
// Create empty repo | ||
await util.wrappedExec('git init --bare', { cwd: folders.repoDir }); | ||
|
||
// Clone repo, and create an initial commit | ||
await util.wrappedExec(`git clone "${folders.repoDir}" clone`, { | ||
cwd: folders.workDir, | ||
}); | ||
await fs.writeFile(path.join(folders.repoCloneDir, 'initial1'), 'foobar1'); | ||
await fs.writeFile(path.join(folders.repoCloneDir, 'initial2'), 'foobar2'); | ||
await mkdirP(path.join(folders.repoCloneDir, 'folder')); | ||
await fs.writeFile(path.join(folders.repoCloneDir, 'folder', 'a'), 'foobar1'); | ||
await fs.writeFile(path.join(folders.repoCloneDir, 'folder', 'b'), 'foobar2'); | ||
await util.wrappedExec(`git add -A .`, { cwd: folders.repoCloneDir }); | ||
await util.wrappedExec(`git config user.name "Test User"`, { | ||
cwd: folders.repoCloneDir, | ||
}); | ||
await util.wrappedExec(`git config user.email "[email protected]"`, { | ||
cwd: folders.repoCloneDir, | ||
}); | ||
await util.wrappedExec(`git commit -m initial`, { | ||
cwd: folders.repoCloneDir, | ||
}); | ||
await util.wrappedExec(`git push origin master`, { | ||
cwd: folders.repoCloneDir, | ||
}); | ||
|
||
// Create dummy data | ||
await mkdirP(path.join(folders.dataDir, 'dummy')); | ||
await fs.writeFile(path.join(folders.dataDir, 'dummy', 'baz'), 'foobar'); | ||
await fs.writeFile(path.join(folders.dataDir, 'dummy', '.bat'), 'foobar'); | ||
|
||
// Run Action | ||
await util.runWithGithubEnv( | ||
path.basename(__filename), | ||
{ | ||
REPO: folders.repoUrl, | ||
BRANCH: 'master', | ||
FOLDER: folders.dataDir, | ||
SSH_PRIVATE_KEY: (await fs.readFile(util.SSH_PRIVATE_KEY)).toString(), | ||
KNOWN_HOSTS_FILE: util.KNOWN_HOSTS, | ||
TARGET_DIR: 'custom' | ||
}, | ||
's0/test', | ||
{}, | ||
's0' | ||
); | ||
|
||
// Check that the list of files in the root of the target repo is as expected | ||
expect(await listTree(folders.repoDir)).toEqual([ | ||
'.', | ||
'custom', | ||
'custom/dummy', | ||
'custom/dummy/.bat', | ||
'custom/dummy/baz', | ||
'folder', | ||
'folder/a', | ||
'folder/b', | ||
'initial1', | ||
'initial2', | ||
]); | ||
|
||
// Check that the log of the repo is as expected | ||
// (check tree-hash, commit message, and author) | ||
const log = ( | ||
await util.exec( | ||
'git log --pretty="format:msg:%s%ntree:%T%nauthor:%an <%ae>" master', | ||
{ | ||
cwd: folders.repoDir, | ||
} | ||
) | ||
).stdout; | ||
const sha = await util.getRepoSha(); | ||
const cleanedLog = log.replace(sha, '<sha>'); | ||
expect(cleanedLog).toMatchSnapshot(); | ||
}); |