Skip to content

Commit

Permalink
Merge pull request #3 from gregoranders/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
gregoranders authored Jan 6, 2020
2 parents 7230163 + f3812bc commit 91c015e
Show file tree
Hide file tree
Showing 28 changed files with 399 additions and 156 deletions.
1 change: 1 addition & 0 deletions .github/actions/build-info/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"esModuleInterop": true,
"noImplicitAny": true,
"sourceMap": true,
"strict": true,
"outDir": "./",
},
"include": [
Expand Down
52 changes: 19 additions & 33 deletions .github/actions/create-release/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,36 @@ import { context, GitHub } from "@actions/github";

import * as Octokit from "@octokit/rest";

type IResponse = Octokit.Response<Octokit.ReposGetLatestReleaseResponse | Octokit.ReposCreateReleaseResponse>;

async function run(): Promise<void> {
const tag: string = core.getInput("tag", {required: true});
const name: string = core.getInput("name", {required: true});
const tag: string = core.getInput("tag", { required: true });
const name: string = core.getInput("name", { required: true });
const body: string = core.getInput("body");
const draft: boolean = core.getInput("draft") === "true";
const prerelease: boolean = core.getInput("prerelease") === "true";
const target_commitish: string = core.getInput("target");

const { owner, repo } = context.repo;

if (!process.env.GITHUB_TOKEN) {
core.setFailed("Missing GitHub token");
return;
}

const github: GitHub = new GitHub(process.env.GITHUB_TOKEN);

let releaseID: number = -1;
let releaseURL: string = "";
let releaseUploadURL: string = "";
let response: undefined | IResponse;

try {
const response: Octokit.Response<Octokit.ReposGetLatestReleaseResponse> = await github.repos.getReleaseByTag({
response = await github.repos.getReleaseByTag({
owner,
repo,
tag,
});
releaseID = response.data.id;
releaseURL = response.data.html_url;
releaseUploadURL = response.data.upload_url;
} catch (error) {
try {
const response: Octokit.Response<Octokit.ReposCreateReleaseResponse> = await github.repos.createRelease({
response = await github.repos.createRelease({
body,
draft,
name,
Expand All @@ -40,34 +42,18 @@ async function run(): Promise<void> {
tag_name: tag,
target_commitish,
});

releaseID = response.data.id;
releaseURL = response.data.html_url;
releaseUploadURL = response.data.assets_url;
} catch (createError) {
core.setFailed("Error");
return;
core.setFailed("Error: " + JSON.stringify(createError));
}
}

if (releaseID < 0) {
core.setFailed("Invalid release id " + releaseID);
return;
if (response) {
core.setOutput("id", response.data.id.toString());
core.setOutput("url", response.data.html_url);
core.setOutput("upload_url", response.data.upload_url);
} else {
core.setFailed("Invalid release");
}

if (!releaseURL || !releaseURL.length) {
core.setFailed("Invalid release URL");
return;
}

if (!releaseUploadURL || !releaseUploadURL.length) {
core.setFailed("Invalid release URL");
return;
}

core.setOutput("id", releaseID.toString());
core.setOutput("url", releaseURL);
core.setOutput("upload_url", releaseUploadURL);
}

run();
1 change: 1 addition & 0 deletions .github/actions/create-release/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"esModuleInterop": true,
"noImplicitAny": true,
"sourceMap": true,
"strict": true,
"outDir": "./",
},
"include": [
Expand Down
27 changes: 8 additions & 19 deletions .github/actions/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,16 @@ import * as ncc from "@zeit/ncc";

const basePath: fs.PathLike = fs.realpathSync(path.resolve(__dirname, "../.."));

interface INCCCompileOptions {
cache?: boolean;
debugLog?: boolean;
externals?: string[];
filterAssetBase?: string;
minify?: boolean;
quiet?: boolean;
v8cache?: boolean;
}

function nccCompile(options?: INCCCompileOptions): any {
function nccCompile(): any {
return through.obj((chunk: any, encoding: string, callback: through.TransformCallback): any => {
if (chunk.isBuffer()) {
ncc(chunk.path, Object.assign(options, {
ncc(chunk.path, {
cache: false,
minify: false,
quiet: false,
sourceMap: false,
sourceMapRegister: false,
})).then((result: any): void => {
}).then((result: any): void => {
chunk.path = chunk.path.replace(".ts", ".js");
chunk.contents = Buffer.from(result.code);
callback(undefined, chunk);
Expand All @@ -38,11 +31,7 @@ function nccCompile(options?: INCCCompileOptions): any {
}

gulp.task("default", (): NodeJS.ReadWriteStream => {
return gulp.src(path.join(basePath, ".github/actions/**/*.ts"))
.pipe(nccCompile({
cache: false,
minify: false,
quiet: false,
}))
return gulp.src(path.join(basePath, ".github/actions/**/index.ts"))
.pipe(nccCompile())
.pipe(gulp.dest(path.resolve(basePath, ".github/actions/")));
});
1 change: 1 addition & 0 deletions .github/actions/prepare-release/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"esModuleInterop": true,
"noImplicitAny": true,
"sourceMap": true,
"strict": true,
"outDir": "./",
},
"include": [
Expand Down
39 changes: 25 additions & 14 deletions .github/actions/upload-asset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,33 @@ import * as fs from "fs";
import { getType } from "mime";
import * as path from "path";

async function upload(github: GitHub, filePath: fs.PathLike,
name: string, url: string): Promise<Octokit.ReposUploadReleaseAssetResponseValue> {
const headers: Octokit.ReposUploadReleaseAssetParamsHeaders = {
"content-length": fs.statSync(filePath).size,
"content-type": getType(filePath.toString()) || "application/zip",
};

const response: Octokit.Response<Octokit.ReposUploadReleaseAssetResponse> = await github.repos.uploadReleaseAsset({
file: fs.readFileSync(filePath),
headers,
name,
url,
});

return response.data as any;
}

async function run(): Promise<void> {
const assetUploadURL: string = core.getInput("url", {required: true});
const assetName: string = core.getInput("name", {required: true});
const assetPath: string = core.getInput("path", {required: true});

if (!process.env.GITHUB_TOKEN) {
core.setFailed("Missing GitHub token");
return;
}

const github: GitHub = new GitHub(process.env.GITHUB_TOKEN);

const fullPathChecked: fs.PathLike = path.resolve(fs.realpathSync(assetPath));
Expand All @@ -21,21 +43,10 @@ async function run(): Promise<void> {
}

try {
const headers: Octokit.ReposUploadReleaseAssetParamsHeaders = {
"content-length": fs.statSync(fullPathChecked).size,
"content-type": getType(fullPathChecked),
};

const response: Octokit.Response<Octokit.ReposUploadReleaseAssetResponse> = await github.repos.uploadReleaseAsset({
file: fs.readFileSync(fullPathChecked),
headers,
name: assetName,
url: assetUploadURL,
});

console.log(response.data);
const data: Octokit.ReposUploadReleaseAssetResponseValue
= await upload(github, fullPathChecked, assetName, assetUploadURL);

core.setOutput("url", "abc");
core.setOutput("url", data.browser_download_url);
} catch (error) {
core.setFailed("Error");
return;
Expand Down
1 change: 1 addition & 0 deletions .github/actions/upload-asset/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"esModuleInterop": true,
"noImplicitAny": true,
"sourceMap": true,
"strict": true,
"outDir": "./",
},
"include": [
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,23 @@ jobs:
npm run build
npm test
npm run dist
- name: test coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage/lcov.info
env:
CI: true
GITHUB_CONTEXT: ${{ toJson(github) }}
GITHUB_BRANCH: ${{ github.ref }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_BASE_REF: ${{ github.base_ref }}
GITHUB_COMMIT: ${{ github.sha }}
- name: publish code coverage to code climate
if: matrix.os == 'ubuntu-latest'
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE }}
with:
coverageCommand: npm run test
debug: true
20 changes: 20 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ jobs:
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_BASE_REF: ${{ github.base_ref }}
GITHUB_COMMIT: ${{ github.sha }}
- name: test coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage/lcov.info
env:
CI: true
GITHUB_CONTEXT: ${{ toJson(github) }}
GITHUB_BRANCH: ${{ github.ref }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_BASE_REF: ${{ github.base_ref }}
GITHUB_COMMIT: ${{ github.sha }}
- name: publish code coverage to code climate
if: matrix.os == 'ubuntu-latest'
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE }}
with:
coverageCommand: npm run test
debug: true
- name: release
id: release
uses: ./.github/actions/create-release
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ jobs:
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_BASE_REF: ${{ github.base_ref }}
GITHUB_COMMIT: ${{ github.sha }}
- name: test coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage/lcov.info
- name: prepare release
id: prepare
uses: ./.github/actions/prepare-release
Expand Down
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"workbench.colorTheme": "Electron Highlighter",
"workbench.iconTheme": "material-icon-theme",
"terminal.integrated.copyOnSelection": true,
"jest.pathToJest": "node_modules/.bin/jest",
"jest.pathToJest": "npm test --",
"jest.showCoverageOnLoad": true,
"git.alwaysSignOff": true,
"git.autofetch": true,
"git.enableCommitSigning": true,
"git.fetchOnPull": true
"git.fetchOnPull": true,
"jest.runAllTestsFirst": false,
"jest.enableInlineErrorMessages": true
}
7 changes: 5 additions & 2 deletions .vscode/workspace.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"settings": {
"workbench.colorTheme": "Nord",
"workbench.iconTheme": "material-icon-theme",
"terminal.integrated.copyOnSelection": true
"terminal.integrated.copyOnSelection": true,
"jest.enableInlineErrorMessages": true,
"jest.rootPath": "./src",
"jest.showCoverageOnLoad": true
},
"extensions": {
"recommendations": [
Expand All @@ -20,4 +23,4 @@
"visualstudioexptteam.vscodeintellicode"
]
}
}
}
Loading

0 comments on commit 91c015e

Please sign in to comment.