feat!: remove auto-snapshot on dirty tag (#382)
* feat!: remove auto-snapshot on dirty tag Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * feat!: remove the entire git thing Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: tests Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: fix Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: snapshto tests Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
23e0ed5919
commit
3b7d1ba946
|
@ -57,7 +57,7 @@ jobs:
|
|||
with:
|
||||
distribution: ${{ matrix.distribution }}
|
||||
version: ${{ matrix.version }}
|
||||
args: release --skip-publish --rm-dist
|
||||
args: release --skip-publish --rm-dist --snapshot
|
||||
workdir: ./test
|
||||
|
||||
install-only:
|
||||
|
@ -138,7 +138,7 @@ jobs:
|
|||
uses: ./
|
||||
with:
|
||||
version: latest
|
||||
args: -f .goreleaser-signing.yml release --skip-publish --rm-dist
|
||||
args: -f .goreleaser-signing.yml release --skip-publish --rm-dist --snapshot
|
||||
workdir: ./test
|
||||
env:
|
||||
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
|
||||
|
@ -166,7 +166,7 @@ jobs:
|
|||
name: GoReleaser
|
||||
uses: ./
|
||||
with:
|
||||
args: release --skip-publish --rm-dist
|
||||
args: release --skip-publish --rm-dist --snapshot
|
||||
workdir: ./test
|
||||
-
|
||||
name: Upload assets
|
||||
|
@ -175,28 +175,6 @@ jobs:
|
|||
name: myapp
|
||||
path: ./test/dist/*
|
||||
|
||||
current-tag:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.18
|
||||
-
|
||||
name: GoReleaser
|
||||
uses: ./
|
||||
with:
|
||||
args: release --skip-publish --rm-dist
|
||||
workdir: ./test
|
||||
env:
|
||||
GORELEASER_CURRENT_TAG: v99.99.99
|
||||
|
||||
dist:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
@ -214,7 +192,7 @@ jobs:
|
|||
name: GoReleaser
|
||||
uses: ./
|
||||
with:
|
||||
args: release --config .goreleaser-dist.yml --skip-publish --rm-dist
|
||||
args: release --config .goreleaser-dist.yml --skip-publish --rm-dist --snapshot
|
||||
workdir: ./test
|
||||
-
|
||||
name: Check dist
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
import {describe, expect, it} from '@jest/globals';
|
||||
import * as git from '../src/git';
|
||||
|
||||
describe('git', () => {
|
||||
it('returns git tag through describe', async () => {
|
||||
process.env.GITHUB_SHA = '309312125ed7a32fcd48f3a1e24dcafe669c186a';
|
||||
const tag: string = await git.getTag();
|
||||
expect(tag).not.toEqual('');
|
||||
});
|
||||
|
||||
it('returns git tag through GITHUB_SHA', async () => {
|
||||
process.env.GITHUB_SHA = '6389ff5bd287fd6948a7ccda8af8da4f0bbc856a';
|
||||
const tag: string = await git.getTag();
|
||||
expect(tag).toEqual('v2.2.1');
|
||||
});
|
||||
|
||||
it('returns git tag through GITHUB_REF', async () => {
|
||||
process.env.GITHUB_REF = 'refs/tags/v2.2.1';
|
||||
const tag: string = await git.getTag();
|
||||
expect(tag).toEqual('v2.2.1');
|
||||
});
|
||||
|
||||
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();
|
||||
expect(commit).not.toEqual('');
|
||||
});
|
||||
});
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
49
src/git.ts
49
src/git.ts
|
@ -1,49 +0,0 @@
|
|||
import * as exec from '@actions/exec';
|
||||
|
||||
const git = async (args: string[] = []): Promise<string> => {
|
||||
return await exec
|
||||
.getExecOutput(`git`, args, {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
})
|
||||
.then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
return res.stdout.trim();
|
||||
});
|
||||
};
|
||||
|
||||
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(['tag', '--points-at', `${process.env.GITHUB_SHA}`, '--sort', '-version:creatordate']).then(
|
||||
tags => {
|
||||
if (tags.length == 0) {
|
||||
return git(['describe', '--tags', '--abbrev=0']);
|
||||
}
|
||||
return tags.split('\n')[0];
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export async function isTagDirty(currentTag: string): Promise<boolean> {
|
||||
try {
|
||||
await git(['describe', '--exact-match', '--tags', '--match', currentTag]);
|
||||
} catch (err) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function getShortCommit(): Promise<string> {
|
||||
return await git(['show', "--format='%h'", 'HEAD', '--quiet']);
|
||||
}
|
19
src/main.ts
19
src/main.ts
|
@ -2,7 +2,6 @@ import * as fs from 'fs';
|
|||
import * as path from 'path';
|
||||
import yargs from 'yargs';
|
||||
import * as context from './context';
|
||||
import * as git from './git';
|
||||
import * as goreleaser from './goreleaser';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
@ -28,10 +27,6 @@ async function run(): Promise<void> {
|
|||
process.chdir(inputs.workdir);
|
||||
}
|
||||
|
||||
const commit = await git.getShortCommit();
|
||||
const tag = await git.getTag();
|
||||
const isTagDirty = await git.isTagDirty(tag);
|
||||
|
||||
let yamlfile: string | unknown;
|
||||
const argv = yargs.parse(inputs.args);
|
||||
if (argv.config) {
|
||||
|
@ -44,19 +39,7 @@ async function run(): Promise<void> {
|
|||
});
|
||||
}
|
||||
|
||||
let snapshot = '';
|
||||
if (inputs.args.split(' ').indexOf('release') > -1) {
|
||||
if (isTagDirty) {
|
||||
if (!inputs.args.includes('--snapshot') && !inputs.args.includes('--nightly')) {
|
||||
core.info(`No tag found for commit ${commit}. Snapshot forced`);
|
||||
snapshot = ' --snapshot';
|
||||
}
|
||||
} else {
|
||||
core.info(`${tag} tag found for commit ${commit}`);
|
||||
}
|
||||
}
|
||||
|
||||
await exec.exec(`${bin} ${inputs.args}${snapshot}`);
|
||||
await exec.exec(`${bin} ${inputs.args}`);
|
||||
|
||||
if (typeof yamlfile === 'string') {
|
||||
const artifacts = await goreleaser.getArtifacts(await goreleaser.getDistPath(yamlfile));
|
||||
|
|
Loading…
Reference in New Issue