Skip to content

Commit

Permalink
Revert "Update spec file license generating, deprecate old Webpack pl…
Browse files Browse the repository at this point in the history
…ugin"

This reverts commit 6848428.
  • Loading branch information
Etheryte committed May 15, 2024
1 parent 04a83bb commit 526ab8a
Show file tree
Hide file tree
Showing 18 changed files with 2,232 additions and 4,036 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/automatic-frontend-lint-fix-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ jobs:
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn --cwd web/html/src install --frozen-lockfile --prefer-offline

# Run lint with fixes
- name: Run lint
run: yarn lint
run: yarn --cwd web/html/src lint

# If there's any changes, create a PR, see https://github.com/marketplace/actions/create-pull-request
- name: Create PR
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend-dependency-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install:production
run: yarn --cwd web/html/src install --frozen-lockfile --prefer-offline

# Audit will exit with non-zero if there are any vulnerabilities, whoever triggered the run will get an email by default
- name: Run audit
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/frontend-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn --cwd web/html/src install --frozen-lockfile --prefer-offline

# Run lint without fixes so the job fails if there are fixes to be applied
- name: Run lint
run: yarn lint:production
run: yarn --cwd web/html/src lint:production
2 changes: 1 addition & 1 deletion .github/workflows/javascript-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

# We only install production dependencies here to simulate a situation similar to OBS/IBS
- name: Install production dependencies
run: yarn install:production
run: yarn install --force --ignore-optional --production=true --frozen-lockfile --prefer-offline

- name: Build application
run: yarn build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/javascript-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ jobs:
# `--prefer-offline` means we prefer the cache over fetching things from the network.
# See: https://stackoverflow.com/a/62244232/1470607
- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn --cwd web/html/src install --frozen-lockfile --prefer-offline

- name: Run tests
run: yarn test --no-cache
run: yarn --cwd web/html/src test --no-cache
env:
BABEL_ENV: 'test'
4 changes: 2 additions & 2 deletions .github/workflows/typescript-compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn --cwd web/html/src install --frozen-lockfile --prefer-offline

- name: Compile Typescript
run: yarn tsc
run: yarn --cwd web/html/src tsc
3 changes: 0 additions & 3 deletions .yarnrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ yarn-path "./web/html/src/build/yarn/yarn-1.22.17.js"
# Don't run package post-install etc scripts by default to reduce our vulnerable surface
# TODO: Reenable this once https://github.com/yarnpkg/yarn/issues/7338 gets fixed
# ignore-scripts true

--install.prefer-offline true
--install.ignore-optional true
103 changes: 47 additions & 56 deletions web/html/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,62 @@ const shell = require("shelljs");
const path = require("path");
const v8 = require("v8");
const webpack = require("webpack");
const { updateLicenses } = require("./build/update-licenses");
const { fillSpecFile } = require("./build/fill-spec-file");
const config = require("./build/webpack.config");

const args = process.argv.slice(2) || [];

if (args.includes("--licenses-only")) {
updateLicenses();
} else {
webpack(config(process.env, { mode: "production" }), (err, stats) => {
// See https://webpack.js.org/api/node/#error-handling
if (err) {
console.error("Webpack error");
console.error(err.stack || err);
if (err.message.toLowerCase().match(/\bmemory\b/)) {
// See https://stackoverflow.com/a/38049633/1470607
console.error("Process memory usage:");
console.error(process.memoryUsage());
console.error("V8 heap statistics:");
console.error(v8.getHeapStatistics());
}
process.exitCode = err.code || 1;
return;
}

if (stats.hasErrors()) {
console.error("Build error");
console.error(stats.toJson().errors);
process.exitCode = stats.code || 1;
return;
webpack(config(process.env, { mode: "production" }), (err, stats) => {
// See https://webpack.js.org/api/node/#error-handling
if (err) {
console.error("Webpack error");
console.error(err.stack || err);
if (err.message.toLowerCase().match(/\bmemory\b/)) {
// See https://stackoverflow.com/a/38049633/1470607
console.error("Process memory usage:");
console.error(process.memoryUsage());
console.error("V8 heap statistics:");
console.error(v8.getHeapStatistics());
}
process.exitCode = err.code || 1;
return;
}

const editedLicenseFilesByBuild = ["web/spacewalk-web.spec", "web/html/src/vendors/npm.licenses.txt"];
if (stats.hasErrors()) {
console.error("Build error");
console.error(stats.toJson().errors);
process.exitCode = stats.code || 1;
return;
}

const shouldValidateBuild = process.env.BUILD_VALIDATION !== "false";
const editedLicenseFilesByBuild = [
"web/spacewalk-web.spec",
"web/html/src/vendors/npm.licenses.structured.js",
"web/html/src/vendors/npm.licenses.txt",
];

updateLicenses().then(() => {
if (shouldValidateBuild) {
// Check whether the updated specfile and licenses are committed on git
const rootDir = path.resolve(__dirname, "../../../");
const { code: gitCheckCode, stdout } = shell.exec("git ls-files -m", {
cwd: rootDir,
});
const shouldValidateBuild = process.env.BUILD_VALIDATION !== "false";

if (gitCheckCode !== 0) {
process.exitCode = gitCheckCode;
return;
}
fillSpecFile().then(() => {
if (shouldValidateBuild) {
// Check whether the updated specfile and licenses are committed on git
const rootDir = path.resolve(__dirname, "../../../");
const { code: gitCheckCode, stdout } = shell.exec("git ls-files -m", {
cwd: rootDir,
});

const uncommittedFiles = editedLicenseFilesByBuild.filter((fileName) => stdout.includes(fileName));
if (gitCheckCode !== 0) {
process.exitCode = gitCheckCode;
return;
}

if (uncommittedFiles.length) {
if (true || process.env.debug) {
const { stdout: diff } = shell.exec("git diff", {
cwd: rootDir,
});
console.error(diff);
}
const uncommittedFiles = editedLicenseFilesByBuild.filter((fileName) => stdout.includes(fileName));

console.error(`
It seems changes to license and/or spec files haven't been committed.
Please run "yarn update-licenses" and commit the following files: ${uncommittedFiles.join(", ")}`);
process.exitCode = 1;
return;
}
if (uncommittedFiles.length) {
console.error(`
It seems changes to license and/or spec files haven't been committed.
Please run "yarn build" again and commit the following files: ${uncommittedFiles.join(", ")}`);
process.exitCode = 1;
return;
}
});
}
});
}
});
10 changes: 4 additions & 6 deletions web/html/src/build/check-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ import semver from "semver";
await fs.promises.readFile(path.resolve(nodeModules, dependency, "package.json"), "utf8")
);

const expected = resolutions[dependency] || expectedVersion;
const satisfies = semver.satisfies(installedPkg.version, expected);
const coerced = semver.coerce(expected)?.version;
const satisfiesCoerced = Boolean(coerced && semver.satisfies(installedPkg.version, coerced));
const satisfies = semver.satisfies(installedPkg.version, expectedVersion);
const satisfiesCoerced = semver.satisfies(installedPkg.version, semver.coerce(expectedVersion).version);
if (!satisfies && satisfiesCoerced) {
console.warn(
`WARN: Currently installed ${dependency} version ${installedPkg.version} only matches expected version ${expected} when coerced`
`WARN: Currently installed ${dependency} version ${installedPkg.version} only matches expected version ${expectedVersion} when coerced`
);
}

if (!satisfies && !satisfiesCoerced) {
console.error(
`ERROR: Currently installed ${dependency} version ${installedPkg.version} does not satisfy expected version ${expected}`
`ERROR: Currently installed ${dependency} version ${installedPkg.version} does not satisfy expected version ${expectedVersion}`
);
process.exitCode = 1;
}
Expand Down
60 changes: 60 additions & 0 deletions web/html/src/build/fill-spec-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const fs = require("fs");
const path = require("path");

function fillSpecFile() {
delete require.cache[require.resolve("../vendors/npm.licenses.structured")];
const { npmLicensesArray } = require("../vendors/npm.licenses.structured");

// Keep the original base license
npmLicensesArray.push("GPL-2.0-only");
// Files under `web/html/javascript` are MIT licensed but won't be inferred from the automatic list
npmLicensesArray.push("MIT");

//https://github.com/metal/metal.js/issues/411
const processedLicenses = npmLicensesArray.map((item) => {
if (item === "BSD") {
return "0BSD";
}
return item;
});
const mappedProcessedLicenses = Array.from(new Set(processedLicenses)).sort().join(" AND ");

const specFileLocation = "../../spacewalk-web.spec";

return new Promise(function (resolve, reject) {
fs.readFile(specFileLocation, "utf8", function (err, specFile) {
if (err) {
reject(err);
throw err;
}
const editedSpecFile = specFile.replace(
/(?<=%package -n spacewalk-html[\s\S]*?)License:.*/m,
`License: ${mappedProcessedLicenses}`
);

if (editedSpecFile === specFile) {
console.log(`${path.basename(specFileLocation)} is already up to date.`);
resolve();
return;
}

fs.writeFile(specFileLocation, editedSpecFile, "utf8", function (err) {
if (err) {
reject(err);
throw err;
}

console.log(
`${path.basename(
specFileLocation
)} was updated successfully with the following licenses for spacewalk-html: ${mappedProcessedLicenses}`
);
resolve();
});
});
});
}

module.exports = {
fillSpecFile,
};
104 changes: 0 additions & 104 deletions web/html/src/build/update-licenses.js

This file was deleted.

Loading

0 comments on commit 526ab8a

Please sign in to comment.