diff --git a/.github/actions/build-info/action.yml b/.github/actions/build-info/action.yml deleted file mode 100644 index fd56840..0000000 --- a/.github/actions/build-info/action.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: 'Build Info' -description: 'Provide build information' -outputs: - name: - description: 'Name of project build' - version: - description: 'Version of build' -runs: - using: 'node12' - main: 'index.js' diff --git a/.github/actions/build-info/index.ts b/.github/actions/build-info/index.ts deleted file mode 100644 index c948f0d..0000000 --- a/.github/actions/build-info/index.ts +++ /dev/null @@ -1,88 +0,0 @@ -import * as core from "@actions/core"; - -import * as fs from "fs"; -import * as path from "path"; - -interface IPackageJson { - name: string; - version: string; -} - -const gitBranch: (branch?: string) => string = (branch?: string): string => { - if (branch && branch.length && branch !== "HEAD") { - const index: number = branch.lastIndexOf("/"); - if (index) { - return branch.substring(index + 1); - } - return branch; - } - if (process.env.GITHUB_BRANCH) { - return gitBranch(process.env.GITHUB_BRANCH); - } - if (process.env.TRAVIS_BRANCH) { - return gitBranch(process.env.TRAVIS_BRANCH); - } - if (process.env.APPVEYOR_REPO_BRANCH) { - return gitBranch(process.env.APPVEYOR_REPO_BRANCH); - } - return "unknownbranch"; -}; - -const gitCommit: (commit?: string) => string = (commit?: string): string => { - if (commit && commit.length) { - return commit; - } - if (process.env.GITHUB_COMMIT) { - return gitBranch(process.env.GITHUB_COMMIT); - } - if (process.env.TRAVIS_COMMIT) { - return gitBranch(process.env.TRAVIS_COMMIT); - } - if (process.env.APPVEYOR_REPO_COMMIT) { - return gitBranch(process.env.APPVEYOR_REPO_COMMIT); - } - return "unknowncommit"; -}; - -async function run(): Promise { - - try { - const basePath: fs.PathLike = path.resolve(fs.realpathSync(".")); - const packageJson: fs.PathLike = path.resolve(fs.realpathSync(path.join(basePath, "package.json"))); - - if (!packageJson || !packageJson.length) { - core.setFailed("Missing package.json"); - return; - } - - const content: Buffer = fs.readFileSync(packageJson); - const packageInfo: IPackageJson = JSON.parse(content.toString()); - - if (!packageInfo) { - core.setFailed("Invalid package.json"); - return; - } - - if (!packageInfo.name || !packageInfo.name.length) { - core.setFailed("Invalid name"); - return; - } - - if (!packageInfo.version || !packageInfo.version.length) { - core.setFailed("Invalid version"); - return; - } - - core.setOutput("name", packageInfo.name); - core.setOutput("version", packageInfo.version); - core.setOutput("branch", gitBranch()); - core.setOutput("commit", gitCommit()); - - console.log(gitBranch(), gitCommit(), packageInfo); - - } catch (error) { - core.setFailed(error); - } -} - -run(); diff --git a/.github/actions/build-info/tsconfig.json b/.github/actions/build-info/tsconfig.json deleted file mode 100644 index d542d0e..0000000 --- a/.github/actions/build-info/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compilerOptions": { - "target": "ES6", - "module": "commonjs", - "moduleResolution": "node", - "esModuleInterop": true, - "noImplicitAny": true, - "sourceMap": true, - "strict": true, - "outDir": "./", - }, - "include": [ - "./**/*" - ], - "exclude": [] -} diff --git a/.github/actions/create-release/action.yml b/.github/actions/create-release/action.yml deleted file mode 100644 index 7ce9747..0000000 --- a/.github/actions/create-release/action.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: 'Create a Release' -description: 'Create a release' -author: 'Gregor Anders ' -inputs: - tag: - description: 'Tag name' - required: true - name: - description: 'Release name' - required: true - body: - description: 'Release description' - required: false - draft: - description: '`true` for a draft. `false` to publish. Default: `false`' - required: false - default: false - prerelease: - description: '`true` for a prerelease. `false` for a full release. Default: `false`' - required: false - default: false - target: - description: 'Release target (branch name or commit id)' - required: false - default: 'master' -outputs: - id: - description: 'Release Id' - url: - description: 'Release Url' - upload_url: - description: 'Release Asset Upload Url' -runs: - using: 'node12' - main: 'index.js' diff --git a/.github/actions/create-release/index.ts b/.github/actions/create-release/index.ts deleted file mode 100644 index 065ba70..0000000 --- a/.github/actions/create-release/index.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as core from "@actions/core"; -import { context, GitHub } from "@actions/github"; - -import { Octokit } from "@actions/github/node_modules/@octokit/rest"; - -type IResponse = Octokit.Response; - -async function run(): Promise { - 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 response: undefined | IResponse; - - try { - response = await github.repos.getReleaseByTag({ - owner, - repo, - tag, - }); - } catch (error) { - try { - response = await github.repos.createRelease({ - body, - draft, - name, - owner, - prerelease, - repo, - tag_name: tag, - target_commitish, - }); - } catch (createError) { - core.setFailed("Error: " + JSON.stringify(createError)); - } - } - - 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"); - } -} - -run(); diff --git a/.github/actions/create-release/tsconfig.json b/.github/actions/create-release/tsconfig.json deleted file mode 100644 index d542d0e..0000000 --- a/.github/actions/create-release/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compilerOptions": { - "target": "ES6", - "module": "commonjs", - "moduleResolution": "node", - "esModuleInterop": true, - "noImplicitAny": true, - "sourceMap": true, - "strict": true, - "outDir": "./", - }, - "include": [ - "./**/*" - ], - "exclude": [] -} diff --git a/.github/actions/upload-asset/action.yml b/.github/actions/upload-asset/action.yml deleted file mode 100644 index 61716f3..0000000 --- a/.github/actions/upload-asset/action.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: 'Upload Asset' -description: 'Upload Asset to a Release' -inputs: - url: - description: 'Release upload url' - required: true - name: - description: 'Asset name' - required: true - path: - description: 'Asset path' - required: true -outputs: - url: - description: 'Asset download url' -runs: - using: 'node12' - main: 'index.js' diff --git a/.github/actions/upload-asset/index.ts b/.github/actions/upload-asset/index.ts deleted file mode 100644 index 6360943..0000000 --- a/.github/actions/upload-asset/index.ts +++ /dev/null @@ -1,56 +0,0 @@ -import * as core from "@actions/core"; -import { GitHub } from "@actions/github"; - -import { Octokit } from "@actions/github/node_modules/@octokit/rest"; - -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 { - const headers: Octokit.ReposUploadReleaseAssetParamsHeaders = { - "content-length": fs.statSync(filePath).size, - "content-type": getType(filePath.toString()) || "application/zip", - }; - - const response: Octokit.Response = await github.repos.uploadReleaseAsset({ - file: fs.readFileSync(filePath), - headers, - name, - url, - }); - - return response.data as any; -} - -async function run(): Promise { - 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)); - - if (!fs.existsSync(fullPathChecked)) { - core.setFailed("Asset path not found " + assetName); - } - - try { - const data: Octokit.ReposUploadReleaseAssetResponseValue - = await upload(github, fullPathChecked, assetName, assetUploadURL); - - core.setOutput("url", data.browser_download_url); - } catch (error) { - core.setFailed("Error"); - return; - } -} - -run(); diff --git a/.github/actions/upload-asset/tsconfig.json b/.github/actions/upload-asset/tsconfig.json deleted file mode 100644 index d542d0e..0000000 --- a/.github/actions/upload-asset/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compilerOptions": { - "target": "ES6", - "module": "commonjs", - "moduleResolution": "node", - "esModuleInterop": true, - "noImplicitAny": true, - "sourceMap": true, - "strict": true, - "outDir": "./", - }, - "include": [ - "./**/*" - ], - "exclude": [] -} diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index b012f5b..de937b3 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -22,24 +22,28 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - name: npm install and github actions + - name: nodejs project information + id: projectinfo + uses: gregoranders/nodejs-project-info@v0.0.4 + - name: npm install run: | npm install - npm run actions - - name: prebuild - id: prebuild - uses: ./.github/actions/build-info + - name: npm run build + run: | + npm run build env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_BRANCH: ${{ github.ref }} GITHUB_COMMIT: ${{ github.sha }} - - name: npm install, build, test and dist + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} + - name: npm test run: | - npm install - npm run build npm test - npm run dist + env: + GITHUB_BRANCH: ${{ github.ref }} + GITHUB_COMMIT: ${{ github.sha }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} - name: test coverage + if: matrix.os == 'ubuntu-latest' uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -56,10 +60,13 @@ jobs: uses: paambaati/codeclimate-action@v2.3.0 env: CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE }} + GITHUB_BRANCH: ${{ github.ref }} + GITHUB_COMMIT: ${{ github.sha }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} with: coverageCommand: npm run test debug: true - - name: integration test + - name: npm run it if: matrix.os == 'ubuntu-latest' run: | ls -lha /dev/shm @@ -68,3 +75,14 @@ jobs: sudo chmod 1777 /dev/shm npm run build xvfb-run --auto-servernum -- bash -c "npm run it" + env: + GITHUB_BRANCH: ${{ github.ref }} + GITHUB_COMMIT: ${{ github.sha }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} + - name: npm run dist + run: | + npm run dist + env: + GITHUB_BRANCH: ${{ github.ref }} + GITHUB_COMMIT: ${{ github.sha }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index fb2518e..da86d55 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -22,32 +22,29 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - name: npm install and github actions + - name: nodejs project information + id: projectinfo + uses: gregoranders/nodejs-project-info@v0.0.4 + - name: npm install run: | npm install - npm run actions - - name: prebuild - id: prebuild - uses: ./.github/actions/build-info + - name: npm run build + run: | + npm run build env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_BRANCH: ${{ github.ref }} GITHUB_COMMIT: ${{ github.sha }} - - name: npm install, build, test and dist + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} + - name: npm test run: | - npm install - npm run build npm test - npm run dist 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 }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} - name: test coverage uses: coverallsapp/github-action@master + if: matrix.os == 'ubuntu-latest' with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: ./coverage/lcov.info @@ -63,18 +60,38 @@ jobs: uses: paambaati/codeclimate-action@v2.3.0 env: CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE }} + GITHUB_BRANCH: ${{ github.ref }} + GITHUB_COMMIT: ${{ github.sha }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} with: coverageCommand: npm run test debug: true - - name: release - id: release - uses: ./.github/actions/create-release + - name: npm run it + if: matrix.os == 'ubuntu-latest' + run: | + ls -lha /dev/shm + sudo apt-get update + sudo apt-get install xvfb + sudo chmod 1777 /dev/shm + npm run build + xvfb-run --auto-servernum -- bash -c "npm run it" + env: + GITHUB_BRANCH: ${{ github.ref }} + GITHUB_COMMIT: ${{ github.sha }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} + - name: npm run dist + run: | + npm run dist + env: + GITHUB_BRANCH: ${{ github.ref }} + GITHUB_COMMIT: ${{ github.sha }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} + - name: create release + id: createrelease + uses: gregoranders/nodejs-create-release@v0.0.4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag: v${{ steps.prebuild.outputs.version }} - name: ${{ steps.prebuild.outputs.version }} Release - body: ${{ steps.prebuild.outputs.version }} + tag: v${{ steps.projectinfo.outputs.version }} + name: ${{ steps.projectinfo.outputs.name }} - ${{ steps.projectinfo.outputs.version }} Release target: ${{ github.ref }} - draft: true - prerelease: false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5b27cfc..c40372a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,58 +22,90 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - name: npm install and github actions + - name: nodejs project information + id: projectinfo + uses: gregoranders/nodejs-project-info@v0.0.4 + - name: npm install run: | npm install - npm run actions - - name: prebuild - id: prebuild - uses: ./.github/actions/build-info + - name: npm run build + run: | + npm run build env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_BRANCH: ${{ github.ref }} GITHUB_COMMIT: ${{ github.sha }} - - name: npm install, build, test and dist + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} + - name: npm test run: | - npm install - npm run build npm test - npm run dist 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 }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} - name: test coverage + if: matrix.os == 'ubuntu-latest' 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 + 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/codeclimate-action@v2.3.0 + env: + CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE }} + GITHUB_BRANCH: ${{ github.ref }} + GITHUB_COMMIT: ${{ github.sha }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} with: - path: ./dist/pkg - - name: release - id: release - uses: ./.github/actions/create-release + coverageCommand: npm run test + debug: true + - name: npm run it + if: matrix.os == 'ubuntu-latest' + run: | + ls -lha /dev/shm + sudo apt-get update + sudo apt-get install xvfb + sudo chmod 1777 /dev/shm + npm run build + xvfb-run --auto-servernum -- bash -c "npm run it" + env: + GITHUB_BRANCH: ${{ github.ref }} + GITHUB_COMMIT: ${{ github.sha }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} + - name: npm run dist + run: | + npm run dist + env: + GITHUB_BRANCH: ${{ github.ref }} + GITHUB_COMMIT: ${{ github.sha }} + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} + - name: create release + id: createrelease + uses: gregoranders/nodejs-create-release@v0.0.4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag: v${{ steps.prebuild.outputs.version }} - name: ${{ steps.prebuild.outputs.version }} Release - body: ${{ steps.prebuild.outputs.version }} + tag: v${{ steps.projectinfo.outputs.version }} + name: ${{ steps.projectinfo.outputs.name }} - ${{ steps.projectinfo.outputs.version }} Release target: ${{ github.ref }} - draft: true - prerelease: false - - name: upload - id: upload - uses: ./.github/actions/upload-asset + - name: prepare release + id: prepare + uses: ./.github/actions/prepare-release + with: + path: ./dist/pkg + - name: upload asset + id: uploadasset + uses: gregoranders/nodejs-upload-asset@v0.0.4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - url: ${{ steps.release.outputs.upload_url }} - name: ${{ steps.prepare.outputs.name }} + url: ${{ steps.createrelease.outputs.upload_url }} path: ${{ steps.prepare.outputs.path }} + name: ${{ steps.prepare.outputs.name }} diff --git a/gulpfile.ts b/gulpfile.ts index a24c626..db038ac 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -16,10 +16,6 @@ import { createProject, Project } from "gulp-typescript"; import * as sassLint from "gulp-sass-lint"; -import * as PackageJson from "./package.json"; - -import * as nccCompiler from "@zeit/ncc"; - const now: Date = new Date(); const basePath: fs.PathLike = fs.realpathSync(path.resolve(__dirname)); @@ -32,6 +28,8 @@ const stylesBuildPath: fs.PathLike = path.join(buildPath, "styles/"); const distPath: fs.PathLike = path.join(basePath, "dist/"); +import * as PackageJsonImported from "./package.json"; + const typeScriptProject: Project = createProject(path.join(srcPath, "tsconfig.json")); interface IProperties { @@ -39,11 +37,19 @@ interface IProperties { commit: string; } +interface IPackageJson { + author: string; + name: string; + version: string; +} + const gitProperties: IProperties = { branch: "", commit: "", }; +const PackageJson: IPackageJson = JSON.parse(process.env.PACKAGE_JSON || JSON.stringify(PackageJsonImported)); + const version: () => string = (): string => { if (gitProperties.branch === "master" || gitProperties.branch.startsWith("v")) { return "" + PackageJson.version; @@ -102,8 +108,8 @@ const gitCommit: (commit?: string) => string = (commit?: string): string => { gulp.task("init", (): Promise => { return new Promise((resolve: (properties: IProperties) => void, - reject: (reason: any) => void): void => { - git.revParse({ args: "--abbrev-ref HEAD", quiet: true }, (errorBranch: string, branch: string): void => { + reject: (reason: any) => void): void => { + git.revParse({ args: "--abbrev-ref HEAD", quiet: true }, (errorBranch: string, branch: string): void => { if (errorBranch) { reject(errorBranch); } else { @@ -220,6 +226,7 @@ gulp.task("electron", (): Promise => { archive.pipe(output); archive.directory(srcDirPath, pkgName()); archive.finalize().then((): void => { + process.env.PACKAGE_PATH = filePath; resolve(); }).catch((reason: any): void => { log("Failed", reason); @@ -234,8 +241,8 @@ gulp.task("electron", (): Promise => { gulp.task("clear", (): Promise => { return del([path.join(basePath, ".github", "**/*.js"), - path.join(basePath, "src", "**/*.js"), - path.join(basePath, "it", "**/*.js")]); + path.join(basePath, "src", "**/*.js"), + path.join(basePath, "it", "**/*.js")]); }); gulp.task("build", gulp.series("init", gulp.parallel("html", "styles", "typescript"))); diff --git a/package.json b/package.json index e9843fb..6dc1b5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typescript-react-electron-starter", - "version": "0.0.4", + "version": "0.0.5", "description": "TypeScript React Electron Starter", "main": "app/main.js", "scripts": {