Skip to content

Commit 7230163

Browse files
committed
#1 - Initial code commit
Signed-off-by: Gregor Anders <[email protected]>
0 parents  commit 7230163

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2118
-0
lines changed

.editorconfig

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
9+
# Change these settings to your own preference
10+
indent_style = space
11+
indent_size = 2
12+
13+
# We recommend you to keep these unchanged
14+
end_of_line = lf
15+
charset = utf-8
16+
trim_trailing_whitespace = true
17+
insert_final_newline = true
18+
19+
[*.md]
20+
trim_trailing_whitespace = false
21+
22+
[*.scss]
23+
indent_style = space
24+
indent_size = 2
25+
26+
[*.ts]
27+
indent_style = space
28+
indent_size = 2
29+
30+
[*.tsx]
31+
indent_style = space
32+
indent_size = 2
33+
34+
[*.json]
35+
indent_style = space
36+
indent_size = 2
37+
38+
[*.yml]
39+
indent_style = space
40+
indent_size = 2
41+
42+
[*.html]
43+
indent_style = space
44+
indent_size = 2

.github/actions/build-info/action.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: 'Build Info'
2+
description: 'Provide build information'
3+
outputs:
4+
name:
5+
description: 'Name of project build'
6+
version:
7+
description: 'Version of build'
8+
runs:
9+
using: 'node12'
10+
main: 'index.js'

.github/actions/build-info/index.ts

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import * as core from "@actions/core";
2+
3+
import * as fs from "fs";
4+
import * as path from "path";
5+
6+
interface IPackageJson {
7+
name: string;
8+
version: string;
9+
}
10+
11+
const gitBranch: (branch?: string) => string = (branch?: string): string => {
12+
if (branch && branch.length && branch !== "HEAD") {
13+
const index: number = branch.lastIndexOf("/");
14+
if (index) {
15+
return branch.substring(index + 1);
16+
}
17+
return branch;
18+
}
19+
if (process.env.GITHUB_BRANCH) {
20+
return gitBranch(process.env.GITHUB_BRANCH);
21+
}
22+
if (process.env.TRAVIS_BRANCH) {
23+
return gitBranch(process.env.TRAVIS_BRANCH);
24+
}
25+
if (process.env.APPVEYOR_REPO_BRANCH) {
26+
return gitBranch(process.env.APPVEYOR_REPO_BRANCH);
27+
}
28+
return "unknownbranch";
29+
};
30+
31+
const gitCommit: (commit?: string) => string = (commit?: string): string => {
32+
if (commit && commit.length) {
33+
return commit;
34+
}
35+
if (process.env.GITHUB_COMMIT) {
36+
return gitBranch(process.env.GITHUB_COMMIT);
37+
}
38+
if (process.env.TRAVIS_COMMIT) {
39+
return gitBranch(process.env.TRAVIS_COMMIT);
40+
}
41+
if (process.env.APPVEYOR_REPO_COMMIT) {
42+
return gitBranch(process.env.APPVEYOR_REPO_COMMIT);
43+
}
44+
return "unknowncommit";
45+
};
46+
47+
async function run(): Promise<void> {
48+
49+
try {
50+
const basePath: fs.PathLike = path.resolve(fs.realpathSync("."));
51+
const packageJson: fs.PathLike = path.resolve(fs.realpathSync(path.join(basePath, "package.json")));
52+
53+
if (!packageJson || !packageJson.length) {
54+
core.setFailed("Missing package.json");
55+
return;
56+
}
57+
58+
const content: Buffer = fs.readFileSync(packageJson);
59+
const packageInfo: IPackageJson = JSON.parse(content.toString());
60+
61+
if (!packageInfo) {
62+
core.setFailed("Invalid package.json");
63+
return;
64+
}
65+
66+
if (!packageInfo.name || !packageInfo.name.length) {
67+
core.setFailed("Invalid name");
68+
return;
69+
}
70+
71+
if (!packageInfo.version || !packageInfo.version.length) {
72+
core.setFailed("Invalid version");
73+
return;
74+
}
75+
76+
core.setOutput("name", packageInfo.name);
77+
core.setOutput("version", packageInfo.version);
78+
core.setOutput("branch", gitBranch());
79+
core.setOutput("commit", gitCommit());
80+
81+
console.log(gitBranch(), gitCommit(), packageInfo);
82+
83+
} catch (error) {
84+
core.setFailed(error);
85+
}
86+
}
87+
88+
run();
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"noImplicitAny": true,
8+
"sourceMap": true,
9+
"outDir": "./",
10+
},
11+
"include": [
12+
"./**/*"
13+
],
14+
"exclude": []
15+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: 'Create a Release'
2+
description: 'Create a release'
3+
author: 'Gregor Anders <[email protected]>'
4+
inputs:
5+
tag:
6+
description: 'Tag name'
7+
required: true
8+
name:
9+
description: 'Release name'
10+
required: true
11+
body:
12+
description: 'Release description'
13+
required: false
14+
draft:
15+
description: '`true` for a draft. `false` to publish. Default: `false`'
16+
required: false
17+
default: false
18+
prerelease:
19+
description: '`true` for a prerelease. `false` for a full release. Default: `false`'
20+
required: false
21+
default: false
22+
target:
23+
description: 'Release target (branch name or commit id)'
24+
required: false
25+
default: 'master'
26+
outputs:
27+
id:
28+
description: 'Release Id'
29+
url:
30+
description: 'Release Url'
31+
upload_url:
32+
description: 'Release Asset Upload Url'
33+
runs:
34+
using: 'node12'
35+
main: 'index.js'
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as core from "@actions/core";
2+
import { context, GitHub } from "@actions/github";
3+
4+
import * as Octokit from "@octokit/rest";
5+
6+
async function run(): Promise<void> {
7+
const tag: string = core.getInput("tag", {required: true});
8+
const name: string = core.getInput("name", {required: true});
9+
const body: string = core.getInput("body");
10+
const draft: boolean = core.getInput("draft") === "true";
11+
const prerelease: boolean = core.getInput("prerelease") === "true";
12+
const target_commitish: string = core.getInput("target");
13+
14+
const { owner, repo } = context.repo;
15+
16+
const github: GitHub = new GitHub(process.env.GITHUB_TOKEN);
17+
18+
let releaseID: number = -1;
19+
let releaseURL: string = "";
20+
let releaseUploadURL: string = "";
21+
22+
try {
23+
const response: Octokit.Response<Octokit.ReposGetLatestReleaseResponse> = await github.repos.getReleaseByTag({
24+
owner,
25+
repo,
26+
tag,
27+
});
28+
releaseID = response.data.id;
29+
releaseURL = response.data.html_url;
30+
releaseUploadURL = response.data.upload_url;
31+
} catch (error) {
32+
try {
33+
const response: Octokit.Response<Octokit.ReposCreateReleaseResponse> = await github.repos.createRelease({
34+
body,
35+
draft,
36+
name,
37+
owner,
38+
prerelease,
39+
repo,
40+
tag_name: tag,
41+
target_commitish,
42+
});
43+
44+
releaseID = response.data.id;
45+
releaseURL = response.data.html_url;
46+
releaseUploadURL = response.data.assets_url;
47+
} catch (createError) {
48+
core.setFailed("Error");
49+
return;
50+
}
51+
}
52+
53+
if (releaseID < 0) {
54+
core.setFailed("Invalid release id " + releaseID);
55+
return;
56+
}
57+
58+
if (!releaseURL || !releaseURL.length) {
59+
core.setFailed("Invalid release URL");
60+
return;
61+
}
62+
63+
if (!releaseUploadURL || !releaseUploadURL.length) {
64+
core.setFailed("Invalid release URL");
65+
return;
66+
}
67+
68+
core.setOutput("id", releaseID.toString());
69+
core.setOutput("url", releaseURL);
70+
core.setOutput("upload_url", releaseUploadURL);
71+
}
72+
73+
run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"noImplicitAny": true,
8+
"sourceMap": true,
9+
"outDir": "./",
10+
},
11+
"include": [
12+
"./**/*"
13+
],
14+
"exclude": []
15+
}

.github/actions/gulpfile.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as fs from "fs";
2+
import * as os from "os";
3+
import * as path from "path";
4+
5+
import * as gulp from "gulp";
6+
7+
import * as through from "through2";
8+
9+
import * as ncc from "@zeit/ncc";
10+
11+
const basePath: fs.PathLike = fs.realpathSync(path.resolve(__dirname, "../.."));
12+
13+
interface INCCCompileOptions {
14+
cache?: boolean;
15+
debugLog?: boolean;
16+
externals?: string[];
17+
filterAssetBase?: string;
18+
minify?: boolean;
19+
quiet?: boolean;
20+
v8cache?: boolean;
21+
}
22+
23+
function nccCompile(options?: INCCCompileOptions): any {
24+
return through.obj((chunk: any, encoding: string, callback: through.TransformCallback): any => {
25+
if (chunk.isBuffer()) {
26+
ncc(chunk.path, Object.assign(options, {
27+
sourceMap: false,
28+
sourceMapRegister: false,
29+
})).then((result: any): void => {
30+
chunk.path = chunk.path.replace(".ts", ".js");
31+
chunk.contents = Buffer.from(result.code);
32+
callback(undefined, chunk);
33+
}).catch((reason: any): void => {
34+
callback(reason, undefined);
35+
});
36+
}
37+
});
38+
}
39+
40+
gulp.task("default", (): NodeJS.ReadWriteStream => {
41+
return gulp.src(path.join(basePath, ".github/actions/**/*.ts"))
42+
.pipe(nccCompile({
43+
cache: false,
44+
minify: false,
45+
quiet: false,
46+
}))
47+
.pipe(gulp.dest(path.resolve(basePath, ".github/actions/")));
48+
});
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: 'Prepare Release'
2+
description: 'Prepare Asset for a Release'
3+
inputs:
4+
path:
5+
description: 'Path containing asset'
6+
required: true
7+
outputs:
8+
name:
9+
description: 'Basename of asset'
10+
path:
11+
description: 'Realpath of asset'
12+
runs:
13+
using: 'node12'
14+
main: 'index.js'
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as core from "@actions/core";
2+
3+
import * as fs from "fs";
4+
import * as path from "path";
5+
6+
async function run(): Promise<void> {
7+
const assetPath: string = core.getInput("path");
8+
9+
const basePath: fs.PathLike = path.resolve(fs.realpathSync(assetPath));
10+
const files: string[] = fs.readdirSync(basePath);
11+
12+
if (files && files.length === 1) {
13+
core.setOutput("name", files[0]);
14+
core.setOutput("path", path.join(basePath, "/", files[0]));
15+
} else {
16+
if (!files || files.length === 0) {
17+
core.setFailed("No files found in " + basePath);
18+
} else {
19+
core.setFailed("Found more than one file in " + basePath);
20+
}
21+
}
22+
}
23+
24+
run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"noImplicitAny": true,
8+
"sourceMap": true,
9+
"outDir": "./",
10+
},
11+
"include": [
12+
"./**/*"
13+
],
14+
"exclude": []
15+
}

0 commit comments

Comments
 (0)