-
-
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 #27 from s0/feature/tags
Implement Tags feature
- Loading branch information
Showing
5 changed files
with
168 additions
and
15 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
23 changes: 23 additions & 0 deletions
23
action/test/specs/__snapshots__/ssh-custom-tags.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,23 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Test custom tags 1`] = ` | ||
"msg:This is another commit follow up with no content changes | ||
tree:8bf87c66655949e66937b11593cc4ae732d1f610 | ||
author:s0 <[email protected]> | ||
msg:Update branch-a to output generated at <sha> | ||
tree:8bf87c66655949e66937b11593cc4ae732d1f610 | ||
author:s0 <[email protected]>" | ||
`; | ||
exports[`Test custom tags 2`] = ` | ||
"msg:This is another commit follow up with no content changes | ||
tree:8bf87c66655949e66937b11593cc4ae732d1f610 | ||
author:s0 <[email protected]> | ||
msg:Update branch-a to output generated at <sha> | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import git from 'isomorphic-git'; | ||
|
||
import * as util from '../util'; | ||
|
||
const REPO_DIR = path.join(util.REPOS_DIR, 'ssh-custom-tags.git'); | ||
const DATA_DIR = path.join(util.DATA_DIR, 'ssh-custom-tags'); | ||
|
||
it('Test custom tags', 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-custom-tags.git', | ||
BRANCH: 'branch-a', | ||
FOLDER: DATA_DIR, | ||
SSH_PRIVATE_KEY: (await util.readFile(util.SSH_PRIVATE_KEY)).toString(), | ||
KNOWN_HOSTS_FILE: util.KNOWN_HOSTS, | ||
}, | ||
's0/test', | ||
{}, | ||
's0', | ||
); | ||
// Run the action again to make sure that a commit is added even when there are | ||
// no content changes | ||
await util.runWithGithubEnv( | ||
path.basename(__filename), | ||
{ | ||
REPO: 'ssh://git@git-ssh/git-server/repos/ssh-custom-tags.git', | ||
BRANCH: 'branch-a', | ||
FOLDER: DATA_DIR, | ||
SSH_PRIVATE_KEY: (await util.readFile(util.SSH_PRIVATE_KEY)).toString(), | ||
KNOWN_HOSTS_FILE: util.KNOWN_HOSTS, | ||
MESSAGE: 'This is another commit follow up with no content changes', | ||
TAG: 'foo-bar-tag-v0.1.2', | ||
}, | ||
's0/test', | ||
{}, | ||
's0', | ||
); | ||
|
||
{ | ||
// Check that the log of the branch is as expected | ||
let log = (await util.exec( | ||
'git log --pretty="format:msg:%B%ntree:%T%nauthor:%an <%ae>" branch-a', | ||
{ | ||
cwd: REPO_DIR | ||
} | ||
)).stdout; | ||
const fullSha = await util.getFullRepoSha(); | ||
const sha = fullSha.substr(0, 7); | ||
const cleanedLog = log.replace(fullSha, '<long-sha>').replace(sha, '<sha>'); | ||
expect(cleanedLog).toMatchSnapshot(); | ||
} | ||
|
||
{ | ||
// Check that the log got the tag is also as expected | ||
let log = (await util.exec( | ||
'git log --pretty="format:msg:%B%ntree:%T%nauthor:%an <%ae>" foo-bar-tag-v0.1.2', | ||
{ | ||
cwd: REPO_DIR | ||
} | ||
)).stdout; | ||
const fullSha = await util.getFullRepoSha(); | ||
const sha = fullSha.substr(0, 7); | ||
const cleanedLog = log.replace(fullSha, '<long-sha>').replace(sha, '<sha>'); | ||
expect(cleanedLog).toMatchSnapshot(); | ||
} | ||
|
||
// Ensure that commits for branch and tag are identical | ||
const tagSha = await git.resolveRef({ | ||
fs, | ||
gitdir: REPO_DIR, | ||
ref: 'refs/tags/foo-bar-tag-v0.1.2', | ||
}); | ||
const branchSha = await git.resolveRef({ | ||
fs, | ||
gitdir: REPO_DIR, | ||
ref: 'refs/heads/branch-a', | ||
}); | ||
expect(tagSha).toEqual(branchSha); | ||
|
||
}); |