Skip to content

Commit

Permalink
fix: Use GITHUB_REF to retrieve tag before checking the most recent t…
Browse files Browse the repository at this point in the history
…ag (#238)
  • Loading branch information
crazy-max committed Aug 27, 2020
1 parent 3093121 commit 666b32b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions __tests__/git.test.ts
Expand Up @@ -3,13 +3,15 @@ import * as git from '../src/git';
describe('git', () => {
it('returns git tag', async () => {
const tag: string = await git.getTag();
console.log(`tag: ${tag}`);
expect(tag).not.toEqual('');
});
it('checks if tag is dirty', async () => {
expect(await git.isTagDirty('v1.3.1')).toBe(true);
});
it('returns short commit', async () => {
const commit: string = await git.getShortCommit();
console.log(`commit: ${commit}`);
expect(commit).not.toEqual('');
});
});
1 change: 1 addition & 0 deletions __tests__/github.test.ts
Expand Up @@ -5,6 +5,7 @@ describe('github', () => {
const release = await github.getRelease('latest');
expect(release).not.toBeNull();
expect(release?.tag_name).not.toEqual('');
console.log(`tag_name: ${release?.tag_name}`);
});
it('returns v0.117.0 GoReleaser GitHub release', async () => {
const release = await github.getRelease('v0.117.0');
Expand Down
6 changes: 6 additions & 0 deletions dist/index.js

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

6 changes: 6 additions & 0 deletions src/git.ts
Expand Up @@ -11,6 +11,12 @@ const git = async (args: string[] = []): Promise<string> => {

export async function getTag(): Promise<string> {
try {
if ((process.env.GITHUB_REF || '').startsWith('refs/tags')) {
const tag = (process.env.GITHUB_REF || '').split('/').pop();
if (tag !== '' && tag !== undefined) {
return tag;
}
}
return await git(['describe', '--tags', '--abbrev=0']);
} catch (err) {
return '';
Expand Down

0 comments on commit 666b32b

Please sign in to comment.