Skip to content

Commit

Permalink
Publish source code in release assets
Browse files Browse the repository at this point in the history
Signed-off-by: Omkar Phansopkar <omkarphansopkar@gmail.com>
  • Loading branch information
OmkarPh committed Jan 10, 2024
1 parent 8b0703b commit d61fc87
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/*
files: dist/*
42 changes: 42 additions & 0 deletions buildSourceArchive.js
Original file line number Diff line number Diff line change
@@ -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();
11 changes: 7 additions & 4 deletions package-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -49,6 +51,7 @@ function buildPackageArchive(packagePath, archiveDirectory) {
archive.finalize();
}


module.exports = {
addMetaDataFilesToPackage,
buildPackageArchive,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/components/ImportFallback/ImportFallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const ImportFallback = () => {
</Link>
<h2>
Please {" "}
<Link to={ROUTES.HOME}>import a scan</Link> {" "}
to view this page
<Link to={ROUTES.HOME}>import a scan</Link>
</h2>
</div>
</div>
Expand Down

0 comments on commit d61fc87

Please sign in to comment.