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:
Carlos Alexandro Becker 2022-12-13 10:18:53 -03:00 committed by GitHub
parent 23e0ed5919
commit 3b7d1ba946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 7 additions and 126 deletions

View File

@ -57,7 +57,7 @@ jobs:
with: with:
distribution: ${{ matrix.distribution }} distribution: ${{ matrix.distribution }}
version: ${{ matrix.version }} version: ${{ matrix.version }}
args: release --skip-publish --rm-dist args: release --skip-publish --rm-dist --snapshot
workdir: ./test workdir: ./test
install-only: install-only:
@ -138,7 +138,7 @@ jobs:
uses: ./ uses: ./
with: with:
version: latest 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 workdir: ./test
env: env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
@ -166,7 +166,7 @@ jobs:
name: GoReleaser name: GoReleaser
uses: ./ uses: ./
with: with:
args: release --skip-publish --rm-dist args: release --skip-publish --rm-dist --snapshot
workdir: ./test workdir: ./test
- -
name: Upload assets name: Upload assets
@ -175,28 +175,6 @@ jobs:
name: myapp name: myapp
path: ./test/dist/* 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: dist:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -214,7 +192,7 @@ jobs:
name: GoReleaser name: GoReleaser
uses: ./ uses: ./
with: with:
args: release --config .goreleaser-dist.yml --skip-publish --rm-dist args: release --config .goreleaser-dist.yml --skip-publish --rm-dist --snapshot
workdir: ./test workdir: ./test
- -
name: Check dist name: Check dist

View File

@ -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('');
});
});

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -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']);
}

View File

@ -2,7 +2,6 @@ import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import yargs from 'yargs'; import yargs from 'yargs';
import * as context from './context'; import * as context from './context';
import * as git from './git';
import * as goreleaser from './goreleaser'; import * as goreleaser from './goreleaser';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
@ -28,10 +27,6 @@ async function run(): Promise<void> {
process.chdir(inputs.workdir); process.chdir(inputs.workdir);
} }
const commit = await git.getShortCommit();
const tag = await git.getTag();
const isTagDirty = await git.isTagDirty(tag);
let yamlfile: string | unknown; let yamlfile: string | unknown;
const argv = yargs.parse(inputs.args); const argv = yargs.parse(inputs.args);
if (argv.config) { if (argv.config) {
@ -44,19 +39,7 @@ async function run(): Promise<void> {
}); });
} }
let snapshot = ''; await exec.exec(`${bin} ${inputs.args}`);
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}`);
if (typeof yamlfile === 'string') { if (typeof yamlfile === 'string') {
const artifacts = await goreleaser.getArtifacts(await goreleaser.getDistPath(yamlfile)); const artifacts = await goreleaser.getArtifacts(await goreleaser.getDistPath(yamlfile));