Fix bugs found in E2E testing

This commit is contained in:
Nick Cipollo
2019-08-27 09:50:26 -04:00
parent 0280874154
commit 2b2c872297
10 changed files with 183 additions and 32 deletions

View File

@@ -1,6 +1,7 @@
import { Inputs } from "./Inputs";
import { Releases } from "./Releases";
import { basename } from "path";
import { readFileSync } from "fs";
export class Action {
private inputs: Inputs
@@ -21,12 +22,13 @@ export class Action {
)
if (this.inputs.artifact) {
const artifactData = this.inputs.readArtifact()
await this.releases.uploadArtifact(
createResult.data.assets_url,
createResult.data.upload_url,
this.inputs.artifactContentLength,
this.inputs.artifactContentType,
this.inputs.artifact,
basename(this.inputs.artifact)
artifactData,
this.inputs.artifactName
)
}
}

View File

@@ -1,9 +1,11 @@
import * as core from '@actions/core';
import { Context } from "@actions/github/lib/context";
import { readFileSync, statSync } from 'fs';
import { basename } from 'path';
export interface Inputs {
readonly artifact: string
readonly artifactName: string
readonly artifactContentType: string
readonly artifactContentLength: number
readonly body: string
@@ -12,6 +14,8 @@ export interface Inputs {
readonly name: string
readonly tag: string
readonly token: string
readArtifact(): Buffer
}
export class CoreInputs implements Inputs {
@@ -25,6 +29,10 @@ export class CoreInputs implements Inputs {
return core.getInput('artifact')
}
get artifactName(): string {
return basename(this.artifact)
}
get artifactContentType(): string {
const type = core.getInput('artifactContentType')
if(type) {
@@ -89,6 +97,10 @@ export class CoreInputs implements Inputs {
return core.getInput('token', { required: true })
}
readArtifact(): Buffer {
return readFileSync(this.artifact)
}
stringFromFile(path: string): string {
return readFileSync(path, 'utf-8')
}

View File

@@ -15,7 +15,7 @@ export interface Releases {
assetUrl: string,
contentLength: number,
contentType: string,
file: string,
file: string | object,
name: string
): Promise<Response<AnyResponse>>
}
@@ -51,7 +51,7 @@ export class GithubReleases implements Releases{
assetUrl: string,
contentLength: number,
contentType: string,
file: string,
file: string | object,
name: string
): Promise<Response<AnyResponse>> {
return this.git.repos.uploadReleaseAsset({