From d61fc87473667a67146a146a0e794e1da48da9a5 Mon Sep 17 00:00:00 2001 From: Omkar Phansopkar Date: Mon, 8 Jan 2024 23:46:03 +0530 Subject: [PATCH] Publish source code in release assets Signed-off-by: Omkar Phansopkar --- .github/workflows/Release.yml | 12 ++++-- buildSourceArchive.js | 42 +++++++++++++++++++ package-utils.js | 11 +++-- package.json | 1 + .../ImportFallback/ImportFallback.tsx | 3 +- 5 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 buildSourceArchive.js diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index a0f69ecd..361940ad 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -26,7 +26,7 @@ jobs: uses: softprops/action-gh-release@v1 with: tag_name: ${{steps.tag.outputs.tag}} - name: Release ${{steps.tag.outputs.tag}} + name: ${{steps.tag.outputs.tag}} body_path: ./Release.md draft: false prerelease: false @@ -50,12 +50,16 @@ jobs: node-version: 16.13.0 - name: Install dependencies run: npm install - - name: Build Workbench & create archive for ${{ matrix.os }} + - name: Create release assets directory + run: mkdir -p dist + - name: Build Workbench & create release archive for ${{ matrix.os }} run: npm run publish - - name: Verify Generated archive in dist/ + - name: Create source code archive (including node_modules) + run: npm run srcarchive + - name: Verify Generated archives in dist/ run: ls ./dist - name: Upload release assets uses: softprops/action-gh-release@v1 with: tag_name: ${{ github.ref_name }} - files: dist/* \ No newline at end of file + files: dist/* diff --git a/buildSourceArchive.js b/buildSourceArchive.js new file mode 100644 index 00000000..beccfcdd --- /dev/null +++ b/buildSourceArchive.js @@ -0,0 +1,42 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const os = require("os"); +const fs = require("fs"); +const path = require("path"); +const archiver = require("archiver"); +const version = require("./package.json").version; + +const archiveDirectory = "dist"; +const platform = os.platform(); +const arch = os.arch(); + +// Determine the packaging format based on the OS +const isWindows = platform === "win32"; +const archiveFormat = isWindows ? "zip" : "tar"; +const archiveExtension = isWindows ? "zip" : "tar.gz"; + +console.log("Building source archive ..."); + +// Ensure that the archive destination directory exists +if (!fs.existsSync(archiveDirectory)) { + fs.mkdirSync(archiveDirectory); +} + +// Create the archive file with the same name as the package directory +const archiveFileName = `ScanCode-Workbench-${version}-${platform}-${arch}-src.${archiveExtension}`; +const archiveFilePath = path.join(archiveDirectory, archiveFileName); +const output = fs.createWriteStream(archiveFilePath); +const archive = archiver(archiveFormat, { gzip: true }); + +output.on("close", () => { + console.log(`Created source archive at ${archiveFilePath}`); +}); + +archive.pipe(output); + +archive.glob("**/*", { + dot: true, + cwd: process.cwd(), + ignore: ["dist/**", "out/**", ".git/**"], +}); + +archive.finalize(); diff --git a/package-utils.js b/package-utils.js index 037da675..9f591c87 100644 --- a/package-utils.js +++ b/package-utils.js @@ -6,18 +6,20 @@ const archiver = require("archiver"); /** * @param {string[]} metaDataFiles * @param {string} packagePath -*/ + */ function addMetaDataFilesToPackage(packagePath, metaDataFiles) { metaDataFiles.forEach((file) => fs.copyFileSync(file, `${packagePath}/${file}`) ); - console.log(`Added ${metaDataFiles.length} metadata files to Packaged app at ${packagePath}`); + console.log( + `Added ${metaDataFiles.length} metadata files to Packaged app at ${packagePath}` + ); } -/** +/** * @param {string} packagePath * @param {string} archiveDirectory -*/ + */ function buildPackageArchive(packagePath, archiveDirectory) { // Get the base name of the package directory const packageName = path.basename(packagePath); @@ -49,6 +51,7 @@ function buildPackageArchive(packagePath, archiveDirectory) { archive.finalize(); } + module.exports = { addMetaDataFilesToPackage, buildPackageArchive, diff --git a/package.json b/package.json index 19d98edb..e2cb0b88 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "start": "electron-forge start", "postinstall": "electron-builder install-app-deps", "publish": "electron-forge package", + "srcarchive": "node buildSourceArchive.js", "lint": "eslint --ext .ts,.tsx .", "test": "jest", "test:watch": "jest --watch", diff --git a/src/components/ImportFallback/ImportFallback.tsx b/src/components/ImportFallback/ImportFallback.tsx index da1b12f2..16cb0aff 100644 --- a/src/components/ImportFallback/ImportFallback.tsx +++ b/src/components/ImportFallback/ImportFallback.tsx @@ -16,8 +16,7 @@ const ImportFallback = () => {

Please {" "} - import a scan {" "} - to view this page + import a scan