Add tests
This commit is contained in:
parent
79b6548141
commit
bb450e4e69
|
@ -1,16 +1,16 @@
|
||||||
name: test
|
name: ci
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: master
|
branches: master
|
||||||
push:
|
push:
|
||||||
branches: master
|
branches: master
|
||||||
tags:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
ci:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
|
@ -0,0 +1,33 @@
|
||||||
|
name: test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: master
|
||||||
|
push:
|
||||||
|
branches: master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
# https://github.com/actions/checkout
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
-
|
||||||
|
name: Install
|
||||||
|
run: npm ci
|
||||||
|
-
|
||||||
|
name: Build
|
||||||
|
run: npm run build
|
||||||
|
-
|
||||||
|
name: Test
|
||||||
|
run: npm run test
|
||||||
|
-
|
||||||
|
name: Check for uncommitted changes
|
||||||
|
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
|
||||||
|
run: |
|
||||||
|
git diff --exit-code --stat -- . ':!node_modules' \
|
||||||
|
|| (echo "##[error] found changed files after build. please 'npm run build && npm run format'" \
|
||||||
|
"and check in all changes" \
|
||||||
|
&& exit 1)
|
|
@ -1,4 +1,5 @@
|
||||||
/.dev
|
/.dev
|
||||||
|
/dist
|
||||||
|
|
||||||
# Jetbrains
|
# Jetbrains
|
||||||
/.idea
|
/.idea
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
import fs = require('fs');
|
||||||
|
import * as installer from '../src/installer';
|
||||||
|
|
||||||
|
describe('installer', () => {
|
||||||
|
it('acquires v0.117.0 version of GoReleaser', async () => {
|
||||||
|
const goreleaser = await installer.getGoReleaser('v0.117.0');
|
||||||
|
expect(fs.existsSync(goreleaser)).toBe(true);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('acquires latest version of GoReleaser', async () => {
|
||||||
|
const goreleaser = await installer.getGoReleaser('latest');
|
||||||
|
expect(fs.existsSync(goreleaser)).toBe(true);
|
||||||
|
}, 100000);
|
||||||
|
});
|
|
@ -0,0 +1,3 @@
|
||||||
|
module github.com/crazy-max/ghaction-goreleaser
|
||||||
|
|
||||||
|
go 1.12
|
|
@ -0,0 +1,11 @@
|
||||||
|
module.exports = {
|
||||||
|
clearMocks: true,
|
||||||
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
|
testEnvironment: 'node',
|
||||||
|
testMatch: ['**/*.test.ts'],
|
||||||
|
testRunner: 'jest-circus/runner',
|
||||||
|
transform: {
|
||||||
|
'^.+\\.ts$': 'ts-jest'
|
||||||
|
},
|
||||||
|
verbose: true
|
||||||
|
}
|
|
@ -45,7 +45,7 @@ function getGoReleaser(version) {
|
||||||
else {
|
else {
|
||||||
extPath = yield tc.extractTar(`${tmpdir}/${fileName}`);
|
extPath = yield tc.extractTar(`${tmpdir}/${fileName}`);
|
||||||
}
|
}
|
||||||
return path.join(extPath, 'goreleaser');
|
return path.join(extPath, osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getGoReleaser = getGoReleaser;
|
exports.getGoReleaser = getGoReleaser;
|
||||||
|
|
10
lib/main.js
10
lib/main.js
|
@ -19,14 +19,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const installer = __importStar(require("./installer"));
|
const installer = __importStar(require("./installer"));
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const exec = __importStar(require("@actions/exec"));
|
const exec = __importStar(require("@actions/exec"));
|
||||||
function run() {
|
function run(silent) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const version = core.getInput('version') || 'latest';
|
const version = core.getInput('version') || 'latest';
|
||||||
const args = core.getInput('args');
|
const args = core.getInput('args');
|
||||||
const goreleaser = yield installer.getGoReleaser(version);
|
const goreleaser = yield installer.getGoReleaser(version);
|
||||||
let snapshot = '';
|
let snapshot = '';
|
||||||
if (!process.env.GITHUB_REF.startsWith('refs/tags/')) {
|
if (!process.env.GITHUB_REF ||
|
||||||
|
!process.env.GITHUB_REF.startsWith('refs/tags/')) {
|
||||||
console.log(`⚠️ No tag found. Snapshot forced`);
|
console.log(`⚠️ No tag found. Snapshot forced`);
|
||||||
if (!args.includes('--snapshot')) {
|
if (!args.includes('--snapshot')) {
|
||||||
snapshot = ' --snapshot';
|
snapshot = ' --snapshot';
|
||||||
|
@ -36,11 +37,14 @@ function run() {
|
||||||
console.log(`✅ ${process.env.GITHUB_REF.split('/')[2]} tag found`);
|
console.log(`✅ ${process.env.GITHUB_REF.split('/')[2]} tag found`);
|
||||||
}
|
}
|
||||||
console.log('🏃 Running GoReleaser...');
|
console.log('🏃 Running GoReleaser...');
|
||||||
yield exec.exec(`${goreleaser} ${args}${snapshot}`);
|
yield exec.exec(`${goreleaser} ${args}${snapshot}`, undefined, {
|
||||||
|
silent: silent
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
exports.run = run;
|
||||||
run();
|
run();
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
"fetchSpec": "1.0.2"
|
"fetchSpec": "1.0.2"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/readable-stream"
|
"/readable-stream",
|
||||||
|
"/verror"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
"_resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||||
"_spec": "1.0.2",
|
"_spec": "1.0.2",
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
"fetchSpec": "0.2.0"
|
"fetchSpec": "0.2.0"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/query-string"
|
"/query-string",
|
||||||
|
"/source-map-resolve"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz",
|
"_resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz",
|
||||||
"_spec": "0.2.0",
|
"_spec": "0.2.0",
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"fetchSpec": "1.4.1"
|
"fetchSpec": "1.4.1"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
|
"/pump",
|
||||||
"/tar-stream"
|
"/tar-stream"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz",
|
"_resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz",
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"fetchSpec": "1.0.5"
|
"fetchSpec": "1.0.5"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
|
"/chalk",
|
||||||
"/strip-outer",
|
"/strip-outer",
|
||||||
"/trim-repeated"
|
"/trim-repeated"
|
||||||
],
|
],
|
||||||
|
|
|
@ -22,7 +22,16 @@
|
||||||
"fetchSpec": "4.2.2"
|
"fetchSpec": "4.2.2"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/decompress"
|
"/@jest/core",
|
||||||
|
"/@jest/source-map",
|
||||||
|
"/@jest/transform",
|
||||||
|
"/decompress",
|
||||||
|
"/jest-haste-map",
|
||||||
|
"/jest-runner",
|
||||||
|
"/jest-runtime",
|
||||||
|
"/jest-util",
|
||||||
|
"/load-json-file",
|
||||||
|
"/write-file-atomic"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.2.tgz",
|
"_resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.2.tgz",
|
||||||
"_spec": "4.2.2",
|
"_spec": "4.2.2",
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/from2",
|
"/from2",
|
||||||
|
"/glob",
|
||||||
"/readable-stream"
|
"/readable-stream"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
"_resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/decompress-tar",
|
"/decompress-tar",
|
||||||
"/decompress-tarbz2",
|
"/decompress-tarbz2",
|
||||||
"/decompress-targz"
|
"/decompress-targz",
|
||||||
|
"/execa"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
"_resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||||
"_spec": "1.1.0",
|
"_spec": "1.1.0",
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
"fetchSpec": "1.0.0"
|
"fetchSpec": "1.0.0"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/readable-stream"
|
"/readable-stream",
|
||||||
|
"/unset-value/has-value/isobject"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
"_resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||||
"_spec": "1.0.0",
|
"_spec": "1.0.0",
|
||||||
|
|
|
@ -22,7 +22,10 @@
|
||||||
"fetchSpec": "1.4.0"
|
"fetchSpec": "1.4.0"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/end-of-stream"
|
"/end-of-stream",
|
||||||
|
"/glob",
|
||||||
|
"/inflight",
|
||||||
|
"/pump"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"_resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
"_spec": "1.4.0",
|
"_spec": "1.4.0",
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"fetchSpec": "1.0.0"
|
"fetchSpec": "1.0.0"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
|
"/execa",
|
||||||
"/p-timeout"
|
"/p-timeout"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
|
"_resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
|
||||||
|
|
|
@ -24,8 +24,10 @@
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/download",
|
"/download",
|
||||||
"/got",
|
"/got",
|
||||||
|
"/load-json-file",
|
||||||
"/make-dir",
|
"/make-dir",
|
||||||
"/npm-conf"
|
"/npm-conf",
|
||||||
|
"/path-type"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
|
"_resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
|
||||||
"_spec": "3.0.0",
|
"_spec": "3.0.0",
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/bl",
|
"/bl",
|
||||||
"/got",
|
"/got",
|
||||||
|
"/request",
|
||||||
"/tunnel-agent"
|
"/tunnel-agent"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",
|
"_resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",
|
||||||
|
|
|
@ -22,7 +22,9 @@
|
||||||
"fetchSpec": "6.3.0"
|
"fetchSpec": "6.3.0"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/@actions/tool-cache"
|
"/@actions/tool-cache",
|
||||||
|
"/istanbul-lib-instrument",
|
||||||
|
"/jest-snapshot"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
"_resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
||||||
"_spec": "6.3.0",
|
"_spec": "6.3.0",
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
"fetchSpec": "0.6.0"
|
"fetchSpec": "0.6.0"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/caw"
|
"/caw",
|
||||||
|
"/request"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
|
"_resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
|
||||||
"_spec": "0.6.0",
|
"_spec": "0.6.0",
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
"fetchSpec": "3.3.3"
|
"fetchSpec": "3.3.3"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/@actions/tool-cache"
|
"/@actions/tool-cache",
|
||||||
|
"/request"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz",
|
"_resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz",
|
||||||
"_spec": "3.3.3",
|
"_spec": "3.3.3",
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"fetchSpec": "1.0.2"
|
"fetchSpec": "1.0.2"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
|
"/inflight",
|
||||||
"/once"
|
"/once"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
"_resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
|
@ -5,6 +5,12 @@
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "lib"
|
"lib": "lib"
|
||||||
},
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"test": "jest",
|
||||||
|
"format": "prettier --write **/*.ts",
|
||||||
|
"prune": "npm prune --production"
|
||||||
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/crazy-max/ghaction-goreleaser.git"
|
"url": "git+https://github.com/crazy-max/ghaction-goreleaser.git"
|
||||||
|
@ -24,16 +30,14 @@
|
||||||
"typed-rest-client": "^1.4.0"
|
"typed-rest-client": "^1.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@actions/io": "^1.0.0",
|
"@types/jest": "^24.0.13",
|
||||||
"@types/node": "^12.0.4",
|
"@types/node": "^12.0.4",
|
||||||
"@types/download": "^6.2.4",
|
"@types/download": "^6.2.4",
|
||||||
|
"jest": "^24.8.0",
|
||||||
|
"jest-circus": "^24.7.1",
|
||||||
"prettier": "^1.17.1",
|
"prettier": "^1.17.1",
|
||||||
"typescript": "^3.5.1"
|
"ts-jest": "^24.0.2",
|
||||||
},
|
"typescript": "^3.5.1",
|
||||||
"scripts": {
|
"typescript-formatter": "^7.2.2"
|
||||||
"build": "tsc",
|
|
||||||
"format": "prettier --write **/*.ts",
|
|
||||||
"format-check": "prettier --check **/*.ts",
|
|
||||||
"prune": "npm prune --production"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,10 @@ export async function getGoReleaser(version: string): Promise<string> {
|
||||||
extPath = await tc.extractTar(`${tmpdir}/${fileName}`);
|
extPath = await tc.extractTar(`${tmpdir}/${fileName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.join(extPath, 'goreleaser');
|
return path.join(
|
||||||
|
extPath,
|
||||||
|
osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFileName(): string {
|
function getFileName(): string {
|
||||||
|
|
11
src/main.ts
11
src/main.ts
|
@ -2,14 +2,17 @@ import * as installer from './installer';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
async function run() {
|
export async function run(silent?: boolean) {
|
||||||
try {
|
try {
|
||||||
const version = core.getInput('version') || 'latest';
|
const version = core.getInput('version') || 'latest';
|
||||||
const args = core.getInput('args');
|
const args = core.getInput('args');
|
||||||
const goreleaser = await installer.getGoReleaser(version);
|
const goreleaser = await installer.getGoReleaser(version);
|
||||||
|
|
||||||
let snapshot = '';
|
let snapshot = '';
|
||||||
if (!process.env.GITHUB_REF!.startsWith('refs/tags/')) {
|
if (
|
||||||
|
!process.env.GITHUB_REF ||
|
||||||
|
!process.env.GITHUB_REF.startsWith('refs/tags/')
|
||||||
|
) {
|
||||||
console.log(`⚠️ No tag found. Snapshot forced`);
|
console.log(`⚠️ No tag found. Snapshot forced`);
|
||||||
if (!args.includes('--snapshot')) {
|
if (!args.includes('--snapshot')) {
|
||||||
snapshot = ' --snapshot';
|
snapshot = ' --snapshot';
|
||||||
|
@ -19,7 +22,9 @@ async function run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('🏃 Running GoReleaser...');
|
console.log('🏃 Running GoReleaser...');
|
||||||
await exec.exec(`${goreleaser} ${args}${snapshot}`);
|
await exec.exec(`${goreleaser} ${args}${snapshot}`, undefined, {
|
||||||
|
silent: silent
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
"outDir": "./lib",
|
"outDir": "./lib",
|
||||||
"rootDir": "./src",
|
"rootDir": "./src",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"noImplicitAny": false,
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules", "**/*.test.ts"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue