Skip to content

Commit 4550aed

Browse files
authored
Merge pull request #9 from gregoranders/development
Development
2 parents b4d9493 + 0453c1e commit 4550aed

File tree

13 files changed

+195
-246
lines changed

13 files changed

+195
-246
lines changed

.eslintrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint', 'plugin:prettier/recommended'],
4+
parserOptions: {
5+
ecmaVersion: 2016,
6+
sourceType: 'module',
7+
ecmaFeatures: {},
8+
},
9+
rules: {
10+
'@typescript-eslint/explicit-function-return-type': 'off',
11+
},
12+
settings: {},
13+
};

.prettierrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: true,
3+
trailingComma: "all",
4+
singleQuote: true,
5+
printWidth: 120,
6+
tabWidth: 2
7+
};

.vscode/launch.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Launch Program",
8+
"program": "${workspaceFolder}/src/index.ts",
9+
"preLaunchTask": "tsc: build - tsconfig.json",
10+
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
11+
}
12+
]
13+
}

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": true
4+
},
5+
"eslint.validate": ["javascript", { "language": "typescript", "autoFix": true }],
6+
"editor.formatOnSave": true,
7+
"[javascript]": {
8+
"editor.formatOnSave": false
9+
},
10+
"[typescript]": {
11+
"editor.formatOnSave": false
12+
}
13+
}

.vscode/workspace.code-workspace

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "../"
5+
}
6+
],
7+
"settings": {
8+
"editor.defaultFormatter": "vscode.typescript-language-features",
9+
"workbench.colorTheme": "Nord Deep",
10+
"workbench.iconTheme": "material-icon-theme",
11+
"editor.codeActionsOnSave": {
12+
"source.fixAll.eslint": true
13+
},
14+
"eslint.validate": ["javascript", { "language": "typescript", "autoFix": true }]
15+
},
16+
"extensions": {
17+
"recommendations": [
18+
"coenraads.bracket-pair-colorizer",
19+
"msjsdiag.debugger-for-chrome",
20+
"editorconfig.editorconfig",
21+
"dsznajder.es7-react-js-snippets",
22+
"dbaeumer.vscode-eslint",
23+
"orta.vscode-jest",
24+
"pkief.material-icon-theme",
25+
"marlosirapuan.nord-deep",
26+
"eg2.vscode-npm-script",
27+
"esbenp.prettier-vscode",
28+
"rvest.vs-code-prettier-eslint",
29+
"pflannery.vscode-versionlens",
30+
"visualstudioexptteam.vscodeintellicode"
31+
]
32+
}
33+
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ This action uploads an asset to a release, so your workflow can access it.
2424
...
2525
- name: nodejs project information
2626
id: projectinfo
27-
uses: gregoranders/nodejs-project-info@v0.0.4
27+
uses: gregoranders/nodejs-project-info@v0.0.5
2828
- name: create release
2929
id: createrelease
30-
uses: gregoranders/nodejs-create-release@v0.0.4
30+
uses: gregoranders/nodejs-create-release@v0.0.5
3131
env:
3232
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3333
with:
@@ -36,7 +36,7 @@ This action uploads an asset to a release, so your workflow can access it.
3636
target: ${{ github.ref }}
3737
- name: upload asset
3838
id: uploadasset
39-
uses: gregoranders/nodejs-upload-asset@v0.0.4
39+
uses: gregoranders/nodejs-upload-asset@v0.0.5
4040
env:
4141
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4242
with:

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "nodejs-upload-asset",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "NodeJS Upload Asset",
55
"main": "./dist/index.js",
66
"scripts": {
77
"clear": "rimraf ./node_modules ./dist ./coverage ./package-lock.json",
88
"prestart": "npm run build",
99
"start": "node ./dist/index.js",
10-
"prebuild": "tslint --project ./",
10+
"prebuild": "tsc --noEmit --project ./ && eslint ./src/**/*.ts --quiet --fix",
1111
"build": "ncc build ./src/index.ts -m -o ./dist/",
1212
"pretest": "rimraf ./coverage",
1313
"test": "jest",
@@ -21,6 +21,11 @@
2121
"jest",
2222
"typescript"
2323
],
24+
"husky": {
25+
"hooks": {
26+
"pre-commit": "tsc --noEmit --project ./ && eslint ./src/**/*.ts --quiet && npm run test"
27+
}
28+
},
2429
"jest": {
2530
"collectCoverage": true,
2631
"coveragePathIgnorePatterns": [
@@ -64,13 +69,18 @@
6469
"@types/jest": "25.2.1",
6570
"@types/mime": "2.0.1",
6671
"@zeit/ncc": "0.22.1",
67-
"jest": "25.3.0",
72+
"@typescript-eslint/eslint-plugin": "2.28.0",
73+
"@typescript-eslint/parser": "2.28.0",
74+
"eslint": "6.8.0",
75+
"eslint-config-prettier": "6.10.1",
76+
"eslint-plugin-prettier": "3.1.3",
77+
"husky": "4.2.5",
78+
"jest": "25.4.0",
79+
"prettier": "2.0.4",
6880
"mime": "2.4.4",
6981
"rimraf": "3.0.2",
70-
"ts-jest": "25.3.1",
71-
"ts-loader": "6.2.2",
82+
"ts-jest": "25.4.0",
7283
"ts-node": "8.8.2",
73-
"tslint": "6.1.1",
7484
"typescript": "3.8.3"
7585
}
7686
}

src/action.spec.ts

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,77 @@
1-
import { clearTestEnvironment, uploadReleaseAssetMock, setInput, setOutputMock } from "./testUtils";
1+
/* eslint-disable @typescript-eslint/camelcase */
2+
import { clearTestEnvironment, uploadReleaseAssetMock, setInput, setOutputMock } from './testUtils';
23

3-
import { run as testSubject } from "./action";
4-
5-
describe("nodejs-upload-asset", () => {
4+
import { run as testSubject } from './action';
65

6+
describe('nodejs-upload-asset', () => {
77
beforeEach(() => {
88
clearTestEnvironment();
9-
Reflect.deleteProperty(process.env, "GITHUB_TOKEN");
9+
Reflect.deleteProperty(process.env, 'GITHUB_TOKEN');
1010
});
1111

12-
it("no url provided", async () => {
13-
setInput("path", "bar");
14-
return expect(testSubject()).rejects.toStrictEqual(Error("Input required and not supplied: url"));
12+
it('no url provided', async () => {
13+
setInput('path', 'bar');
14+
return expect(testSubject()).rejects.toStrictEqual(Error('Input required and not supplied: url'));
1515
});
1616

17-
it("no path provided", async () => {
18-
setInput("url", "foo");
19-
return expect(testSubject()).rejects.toStrictEqual(Error("Input required and not supplied: path"));
17+
it('no path provided', async () => {
18+
setInput('url', 'foo');
19+
return expect(testSubject()).rejects.toStrictEqual(Error('Input required and not supplied: path'));
2020
});
2121

22-
it("missing GITHUB_TOKEN", async () => {
23-
setInput("url", "foo");
24-
setInput("path", "bar");
22+
it('missing GITHUB_TOKEN', async () => {
23+
setInput('url', 'foo');
24+
setInput('path', 'bar');
2525
return expect(testSubject()).resolves.toHaveCoreError(/Missing GITHUB_TOKEN/);
2626
});
2727

28-
it("invalid path", async () => {
29-
setInput("url", "foo");
30-
setInput("path", "bar");
31-
process.env.GITHUB_TOKEN = "abcd";
28+
it('invalid path', async () => {
29+
setInput('url', 'foo');
30+
setInput('path', 'bar');
31+
process.env.GITHUB_TOKEN = 'abcd';
3232
return expect(testSubject()).resolves.toHaveCoreError(/lstat/);
3333
});
3434

35-
it("valid input and GITHUB_TOKEN - upload", async () => {
36-
setInput("url", "foo");
37-
setInput("path", ".editorconfig");
38-
process.env.GITHUB_TOKEN = "abcd";
35+
it('valid input and GITHUB_TOKEN - upload', async () => {
36+
setInput('url', 'foo');
37+
setInput('path', '.editorconfig');
38+
process.env.GITHUB_TOKEN = 'abcd';
3939
uploadReleaseAssetMock.mockReturnValue({
4040
data: {
41-
browser_download_url: "download_url",
41+
browser_download_url: 'download_url',
4242
id: 1,
4343
},
4444
});
4545
return testSubject().then(() => {
4646
expect(uploadReleaseAssetMock).toHaveBeenCalledNthWith(1, {
47-
name: ".editorconfig",
48-
url: "foo",
47+
name: '.editorconfig',
48+
url: 'foo',
4949
});
5050
expect(setOutputMock).toHaveBeenCalledTimes(2);
51-
expect(setOutputMock).toHaveCoreOutput("id", "1");
52-
expect(setOutputMock).toHaveCoreOutput("url", "download_url");
51+
expect(setOutputMock).toHaveCoreOutput('id', '1');
52+
expect(setOutputMock).toHaveCoreOutput('url', 'download_url');
5353
});
5454
});
5555

56-
it("valid input and GITHUB_TOKEN - upload - custom mime type", async () => {
57-
setInput("url", "foo");
58-
setInput("path", "package.json");
59-
setInput("mime", "application/json");
60-
process.env.GITHUB_TOKEN = "abcd";
56+
it('valid input and GITHUB_TOKEN - upload - custom mime type', async () => {
57+
setInput('url', 'foo');
58+
setInput('path', 'package.json');
59+
setInput('mime', 'application/json');
60+
process.env.GITHUB_TOKEN = 'abcd';
6161
uploadReleaseAssetMock.mockReturnValue({
6262
data: {
63-
browser_download_url: "download_url",
63+
browser_download_url: 'download_url',
6464
id: 1,
6565
},
6666
});
6767
return testSubject().then(() => {
6868
expect(uploadReleaseAssetMock).toHaveBeenCalledNthWith(1, {
69-
name: "package.json",
70-
url: "foo",
69+
name: 'package.json',
70+
url: 'foo',
7171
});
7272
expect(setOutputMock).toHaveBeenCalledTimes(2);
73-
expect(setOutputMock).toHaveCoreOutput("id", "1");
74-
expect(setOutputMock).toHaveCoreOutput("url", "download_url");
73+
expect(setOutputMock).toHaveCoreOutput('id', '1');
74+
expect(setOutputMock).toHaveCoreOutput('url', 'download_url');
7575
});
7676
});
77-
78-
7977
});

src/action.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
import * as core from "@actions/core";
2-
import { GitHub } from "@actions/github";
1+
import * as core from '@actions/core';
2+
import { GitHub } from '@actions/github';
33

4-
import * as fs from "fs";
5-
import { getType } from "mime";
6-
import { basename, resolve } from "path";
4+
import * as fs from 'fs';
5+
import { getType } from 'mime';
6+
import { basename, resolve } from 'path';
77

8-
import { Octokit } from "@octokit/rest";
8+
import { Octokit } from '@octokit/rest';
99

1010
type ReposUploadReleaseAssetParams = Octokit.ReposUploadReleaseAssetParams;
1111

1212
const uploadAsset = async (client: GitHub, params: ReposUploadReleaseAssetParams) => {
1313
core.startGroup(`Uploading asset ${params.name} to release ${params.url}`);
1414
// tslint:disable-next-line: no-any
15-
const response = await client.repos.uploadReleaseAsset(params) as any;
15+
const response = (await client.repos.uploadReleaseAsset(params)) as any;
1616
core.info(`Release asset ${response.data.name} created [id: ${response.data.id}]`);
1717
core.endGroup();
1818
return response.data;
1919
};
2020

2121
const prepareHeaders = (fullPathChecked: string, mime: string) => {
2222
return {
23-
"content-length": fs.statSync(fullPathChecked).size,
24-
"content-type": mime || getType(fullPathChecked.toString()) || "application/zip",
23+
'content-length': fs.statSync(fullPathChecked).size,
24+
'content-type': mime || getType(fullPathChecked.toString()) || 'application/zip',
2525
};
2626
};
2727

28-
const prepareParams = (data: Buffer, headers: { "content-length": number; "content-type": string; },
29-
label: string, name: string, url: string): Octokit.ReposUploadReleaseAssetParams => {
28+
const prepareParams = (
29+
data: Buffer,
30+
headers: { 'content-length': number; 'content-type': string },
31+
label: string,
32+
name: string,
33+
url: string,
34+
): Octokit.ReposUploadReleaseAssetParams => {
3035
return {
3136
data,
3237
headers,
@@ -37,16 +42,16 @@ const prepareParams = (data: Buffer, headers: { "content-length": number; "conte
3742
};
3843

3944
export const run = async () => {
40-
const path = core.getInput("path", { required: true });
45+
const path = core.getInput('path', { required: true });
4146

42-
const name = core.getInput("name", { required: false }) || basename(path);
43-
const label = core.getInput("label", { required: false });
44-
const url = core.getInput("url", { required: true });
45-
const mime = core.getInput("mime", { required: false });
47+
const name = core.getInput('name', { required: false }) || basename(path);
48+
const label = core.getInput('label', { required: false });
49+
const url = core.getInput('url', { required: true });
50+
const mime = core.getInput('mime', { required: false });
4651

4752
try {
4853
if (!process.env.GITHUB_TOKEN) {
49-
throw Error("Missing GITHUB_TOKEN");
54+
throw Error('Missing GITHUB_TOKEN');
5055
}
5156

5257
const github = new GitHub(process.env.GITHUB_TOKEN);
@@ -56,10 +61,9 @@ export const run = async () => {
5661

5762
const asset = await uploadAsset(github, prepareParams(data, headers, label, name, url));
5863

59-
core.setOutput("id", asset.id.toString());
60-
core.setOutput("url", asset.browser_download_url);
64+
core.setOutput('id', asset.id.toString());
65+
core.setOutput('url', asset.browser_download_url);
6166
} catch (error) {
6267
core.setFailed(error);
6368
}
6469
};
65-

0 commit comments

Comments
 (0)