Add tests

This commit is contained in:
CrazyMax 2019-09-22 07:17:07 +02:00 committed by GitHub
parent 79b6548141
commit bb450e4e69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 5069 additions and 30 deletions

View File

@ -1,16 +1,16 @@
name: test
name: ci
on:
pull_request:
branches: master
push:
branches: master
tags:
jobs:
test:
ci:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest

33
.github/workflows/test.yml vendored Normal file
View File

@ -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
.gitignore vendored
View File

@ -1,4 +1,5 @@
/.dev
/dist
# Jetbrains
/.idea

View File

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

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module github.com/crazy-max/ghaction-goreleaser
go 1.12

11
jest.config.js Normal file
View File

@ -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
}

View File

@ -45,7 +45,7 @@ function getGoReleaser(version) {
else {
extPath = yield tc.extractTar(`${tmpdir}/${fileName}`);
}
return path.join(extPath, 'goreleaser');
return path.join(extPath, osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser');
});
}
exports.getGoReleaser = getGoReleaser;

View File

@ -19,14 +19,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
const installer = __importStar(require("./installer"));
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
function run() {
function run(silent) {
return __awaiter(this, void 0, void 0, function* () {
try {
const version = core.getInput('version') || 'latest';
const args = core.getInput('args');
const goreleaser = yield installer.getGoReleaser(version);
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`);
if (!args.includes('--snapshot')) {
snapshot = ' --snapshot';
@ -36,11 +37,14 @@ function run() {
console.log(`${process.env.GITHUB_REF.split('/')[2]} tag found`);
}
console.log('🏃 Running GoReleaser...');
yield exec.exec(`${goreleaser} ${args}${snapshot}`);
yield exec.exec(`${goreleaser} ${args}${snapshot}`, undefined, {
silent: silent
});
}
catch (error) {
core.setFailed(error.message);
}
});
}
exports.run = run;
run();

View File

@ -22,7 +22,8 @@
"fetchSpec": "1.0.2"
},
"_requiredBy": [
"/readable-stream"
"/readable-stream",
"/verror"
],
"_resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"_spec": "1.0.2",

View File

@ -22,7 +22,8 @@
"fetchSpec": "0.2.0"
},
"_requiredBy": [
"/query-string"
"/query-string",
"/source-map-resolve"
],
"_resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz",
"_spec": "0.2.0",

View File

@ -22,6 +22,7 @@
"fetchSpec": "1.4.1"
},
"_requiredBy": [
"/pump",
"/tar-stream"
],
"_resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz",

View File

@ -22,6 +22,7 @@
"fetchSpec": "1.0.5"
},
"_requiredBy": [
"/chalk",
"/strip-outer",
"/trim-repeated"
],

View File

@ -22,7 +22,16 @@
"fetchSpec": "4.2.2"
},
"_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",
"_spec": "4.2.2",

1
node_modules/inherits/package.json generated vendored
View File

@ -23,6 +23,7 @@
},
"_requiredBy": [
"/from2",
"/glob",
"/readable-stream"
],
"_resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",

View File

@ -24,7 +24,8 @@
"_requiredBy": [
"/decompress-tar",
"/decompress-tarbz2",
"/decompress-targz"
"/decompress-targz",
"/execa"
],
"_resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
"_spec": "1.1.0",

3
node_modules/isarray/package.json generated vendored
View File

@ -22,7 +22,8 @@
"fetchSpec": "1.0.0"
},
"_requiredBy": [
"/readable-stream"
"/readable-stream",
"/unset-value/has-value/isobject"
],
"_resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"_spec": "1.0.0",

5
node_modules/once/package.json generated vendored
View File

@ -22,7 +22,10 @@
"fetchSpec": "1.4.0"
},
"_requiredBy": [
"/end-of-stream"
"/end-of-stream",
"/glob",
"/inflight",
"/pump"
],
"_resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"_spec": "1.4.0",

View File

@ -22,6 +22,7 @@
"fetchSpec": "1.0.0"
},
"_requiredBy": [
"/execa",
"/p-timeout"
],
"_resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",

4
node_modules/pify/package.json generated vendored
View File

@ -24,8 +24,10 @@
"_requiredBy": [
"/download",
"/got",
"/load-json-file",
"/make-dir",
"/npm-conf"
"/npm-conf",
"/path-type"
],
"_resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
"_spec": "3.0.0",

View File

@ -24,6 +24,7 @@
"_requiredBy": [
"/bl",
"/got",
"/request",
"/tunnel-agent"
],
"_resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",

4
node_modules/semver/package.json generated vendored
View File

@ -22,7 +22,9 @@
"fetchSpec": "6.3.0"
},
"_requiredBy": [
"/@actions/tool-cache"
"/@actions/tool-cache",
"/istanbul-lib-instrument",
"/jest-snapshot"
],
"_resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"_spec": "6.3.0",

View File

@ -22,7 +22,8 @@
"fetchSpec": "0.6.0"
},
"_requiredBy": [
"/caw"
"/caw",
"/request"
],
"_resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
"_spec": "0.6.0",

3
node_modules/uuid/package.json generated vendored
View File

@ -22,7 +22,8 @@
"fetchSpec": "3.3.3"
},
"_requiredBy": [
"/@actions/tool-cache"
"/@actions/tool-cache",
"/request"
],
"_resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz",
"_spec": "3.3.3",

1
node_modules/wrappy/package.json generated vendored
View File

@ -22,6 +22,7 @@
"fetchSpec": "1.0.2"
},
"_requiredBy": [
"/inflight",
"/once"
],
"_resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",

4932
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,12 @@
"directories": {
"lib": "lib"
},
"scripts": {
"build": "tsc",
"test": "jest",
"format": "prettier --write **/*.ts",
"prune": "npm prune --production"
},
"repository": {
"type": "git",
"url": "git+https://github.com/crazy-max/ghaction-goreleaser.git"
@ -24,16 +30,14 @@
"typed-rest-client": "^1.4.0"
},
"devDependencies": {
"@actions/io": "^1.0.0",
"@types/jest": "^24.0.13",
"@types/node": "^12.0.4",
"@types/download": "^6.2.4",
"jest": "^24.8.0",
"jest-circus": "^24.7.1",
"prettier": "^1.17.1",
"typescript": "^3.5.1"
},
"scripts": {
"build": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"prune": "npm prune --production"
"ts-jest": "^24.0.2",
"typescript": "^3.5.1",
"typescript-formatter": "^7.2.2"
}
}

View File

@ -35,7 +35,10 @@ export async function getGoReleaser(version: string): Promise<string> {
extPath = await tc.extractTar(`${tmpdir}/${fileName}`);
}
return path.join(extPath, 'goreleaser');
return path.join(
extPath,
osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser'
);
}
function getFileName(): string {

View File

@ -2,14 +2,17 @@ import * as installer from './installer';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
async function run() {
export async function run(silent?: boolean) {
try {
const version = core.getInput('version') || 'latest';
const args = core.getInput('args');
const goreleaser = await installer.getGoReleaser(version);
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`);
if (!args.includes('--snapshot')) {
snapshot = ' --snapshot';
@ -19,7 +22,9 @@ async function run() {
}
console.log('🏃 Running GoReleaser...');
await exec.exec(`${goreleaser} ${args}${snapshot}`);
await exec.exec(`${goreleaser} ${args}${snapshot}`, undefined, {
silent: silent
});
} catch (error) {
core.setFailed(error.message);
}

View File

@ -9,7 +9,8 @@
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true
},
"exclude": ["node_modules"]
"exclude": ["node_modules", "**/*.test.ts"]
}