Skip to content

Commit d61fc87

Browse files
committed
Publish source code in release assets
Signed-off-by: Omkar Phansopkar <omkarphansopkar@gmail.com>
1 parent 8b0703b commit d61fc87

5 files changed

Lines changed: 59 additions & 10 deletions

File tree

.github/workflows/Release.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
uses: softprops/action-gh-release@v1
2727
with:
2828
tag_name: ${{steps.tag.outputs.tag}}
29-
name: Release ${{steps.tag.outputs.tag}}
29+
name: ${{steps.tag.outputs.tag}}
3030
body_path: ./Release.md
3131
draft: false
3232
prerelease: false
@@ -50,12 +50,16 @@ jobs:
5050
node-version: 16.13.0
5151
- name: Install dependencies
5252
run: npm install
53-
- name: Build Workbench & create archive for ${{ matrix.os }}
53+
- name: Create release assets directory
54+
run: mkdir -p dist
55+
- name: Build Workbench & create release archive for ${{ matrix.os }}
5456
run: npm run publish
55-
- name: Verify Generated archive in dist/
57+
- name: Create source code archive (including node_modules)
58+
run: npm run srcarchive
59+
- name: Verify Generated archives in dist/
5660
run: ls ./dist
5761
- name: Upload release assets
5862
uses: softprops/action-gh-release@v1
5963
with:
6064
tag_name: ${{ github.ref_name }}
61-
files: dist/*
65+
files: dist/*

buildSourceArchive.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const os = require("os");
3+
const fs = require("fs");
4+
const path = require("path");
5+
const archiver = require("archiver");
6+
const version = require("./package.json").version;
7+
8+
const archiveDirectory = "dist";
9+
const platform = os.platform();
10+
const arch = os.arch();
11+
12+
// Determine the packaging format based on the OS
13+
const isWindows = platform === "win32";
14+
const archiveFormat = isWindows ? "zip" : "tar";
15+
const archiveExtension = isWindows ? "zip" : "tar.gz";
16+
17+
console.log("Building source archive ...");
18+
19+
// Ensure that the archive destination directory exists
20+
if (!fs.existsSync(archiveDirectory)) {
21+
fs.mkdirSync(archiveDirectory);
22+
}
23+
24+
// Create the archive file with the same name as the package directory
25+
const archiveFileName = `ScanCode-Workbench-${version}-${platform}-${arch}-src.${archiveExtension}`;
26+
const archiveFilePath = path.join(archiveDirectory, archiveFileName);
27+
const output = fs.createWriteStream(archiveFilePath);
28+
const archive = archiver(archiveFormat, { gzip: true });
29+
30+
output.on("close", () => {
31+
console.log(`Created source archive at ${archiveFilePath}`);
32+
});
33+
34+
archive.pipe(output);
35+
36+
archive.glob("**/*", {
37+
dot: true,
38+
cwd: process.cwd(),
39+
ignore: ["dist/**", "out/**", ".git/**"],
40+
});
41+
42+
archive.finalize();

package-utils.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ const archiver = require("archiver");
66
/**
77
* @param {string[]} metaDataFiles
88
* @param {string} packagePath
9-
*/
9+
*/
1010
function addMetaDataFilesToPackage(packagePath, metaDataFiles) {
1111
metaDataFiles.forEach((file) =>
1212
fs.copyFileSync(file, `${packagePath}/${file}`)
1313
);
14-
console.log(`Added ${metaDataFiles.length} metadata files to Packaged app at ${packagePath}`);
14+
console.log(
15+
`Added ${metaDataFiles.length} metadata files to Packaged app at ${packagePath}`
16+
);
1517
}
1618

17-
/**
19+
/**
1820
* @param {string} packagePath
1921
* @param {string} archiveDirectory
20-
*/
22+
*/
2123
function buildPackageArchive(packagePath, archiveDirectory) {
2224
// Get the base name of the package directory
2325
const packageName = path.basename(packagePath);
@@ -49,6 +51,7 @@ function buildPackageArchive(packagePath, archiveDirectory) {
4951
archive.finalize();
5052
}
5153

54+
5255
module.exports = {
5356
addMetaDataFilesToPackage,
5457
buildPackageArchive,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"start": "electron-forge start",
2323
"postinstall": "electron-builder install-app-deps",
2424
"publish": "electron-forge package",
25+
"srcarchive": "node buildSourceArchive.js",
2526
"lint": "eslint --ext .ts,.tsx .",
2627
"test": "jest",
2728
"test:watch": "jest --watch",

src/components/ImportFallback/ImportFallback.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const ImportFallback = () => {
1616
</Link>
1717
<h2>
1818
Please {" "}
19-
<Link to={ROUTES.HOME}>import a scan</Link> {" "}
20-
to view this page
19+
<Link to={ROUTES.HOME}>import a scan</Link>
2120
</h2>
2221
</div>
2322
</div>

0 commit comments

Comments
 (0)