Skip to content

Commit

Permalink
chore: simplify the deprecation process
Browse files Browse the repository at this point in the history
  • Loading branch information
petertonysmith94 committed Feb 6, 2025
1 parent 36a13b8 commit 058fcdb
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 113 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/release-deprecate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ on:
type: string
description: Filter by package name
default: ""
filter_by_package_version:
type: string
description: Filter by package version
default: ""
chunk_size:
type: number
description: Chunk size
default: 1000

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -56,5 +48,3 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_DEPLOY_TOKEN }}
DEPRECATE_VERSIONS: ${{ github.event.inputs.deprecate_versions }}
FILTER_BY_PACKAGE_NAME: ${{ github.event.inputs.filter_by_package_name }}
FILTER_BY_VERSION: ${{ github.event.inputs.filter_by_package_version }}
CHUNK_SIZE: ${{ github.event.inputs.chunk_size }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"changeset:update-changelog": "tsx ./scripts/changeset/update-changelog.mts",
"changeset:get-latest-release": "tsx ./scripts/changeset/get-latest-release.mts",
"changeset:dependabot": "./scripts/changeset/dependabot-changeset.sh",
"release:deprecate": "tsx ./scripts/release-deprecate.ts",
"release:deprecate": "tsx ./scripts/release-deprecate.mts",
"forc:update": "tsx ./scripts/forc-update",
"forc:check": "./scripts/forc-check.sh",
"forc:format": "./scripts/forc-format.sh",
Expand Down
113 changes: 113 additions & 0 deletions scripts/release-deprecate.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { globSync } from "glob";
import { execSync } from "node:child_process";
import { readFileSync } from "node:fs";

const { log, error } = console;

/**
* Parse ENVS
*/
const SHOULD_DEPRECATE_VERSIONS: boolean =
process.env.DEPRECATE_VERSIONS === "true";
const FILTER_BY_PACKAGE_NAME: string = process.env.FILTER_BY_PACKAGE_NAME ?? "";

/**
* Restricted tags that can be deprecated
*/
const DEPRECIABLE_TAGS: string[] = ["0.0.0-next", "0.0.0-pr", "0.0.0-rc"];

/**
* Packages that are no longer published to npm
*
* TODO: Consider deprecating these packages
*/
const NO_LONGER_MAINTAINED_PACKAGES: string[] = [
"@fuel-ts/merkle-shared",
"@fuel-ts/merklesum",
"@fuel-ts/sparsemerkle",
"@fuel-ts/providers",
"@fuel-ts/example-contract",
"@fuel-ts/wallet",
"@fuel-ts/typechain-target-fuels",
"@fuel-ts/testcases",
"@fuel-ts/wordlists",
"@fuel-ts/mnemonic",
"@fuel-ts/signer",
"@fuel-ts/hdwallet",
"@fuel-ts/constants",
"@fuel-ts/interfaces",
"@fuel-ts/keystore",
"@fuel-ts/wallet-manager",
"@fuel-ts/predicate",
"@fuel-ts/asm",
"@fuel-ts/fuel-core",
"@fuel-ts/forc",
];

const MAINTAINED_PACKAGES: string[] = globSync("**/package.json")
// Read in the package.json file
.map((fileName) => {
const packageJson = JSON.parse(readFileSync(fileName, "utf-8"));
return {
path: fileName,
contents: packageJson,
};
})
// Filter out private packages
.filter((pkg) => !pkg.contents.private)
.map((pkg) => pkg.contents.name);

let packages: string[] = MAINTAINED_PACKAGES;

// Only by using filter by package name, are we allowed to deprecate the no longer maintained packages
if (FILTER_BY_PACKAGE_NAME !== "") {
const allPackages = [
...MAINTAINED_PACKAGES,
...NO_LONGER_MAINTAINED_PACKAGES,
];
packages = allPackages.filter((pkg) => pkg === FILTER_BY_PACKAGE_NAME);

// Ensure that we have found a package
if (packages.length === 0) {
error(`❌ No package found with name: ${FILTER_BY_PACKAGE_NAME}`);
process.exit(1);
}
}

/**
* Construct the depreciable package and versions
*/
const depreciablePackageAndVersions = packages.flatMap((pkgName) =>
DEPRECIABLE_TAGS.map((tag) => `${pkgName}@${tag}`),
);
log(
"The following packages and versions will be deprecated\n",
depreciablePackageAndVersions.join("\n"),
"----------------------------------\n",
);

/**
* Deprecate the packages and versions
*/
for await (const packageAndVersion of depreciablePackageAndVersions) {
log(`Deprecating ${packageAndVersion}`);

const dryRun = SHOULD_DEPRECATE_VERSIONS ? "" : "--dry-run ";
const command = `npm deprecate ${packageAndVersion} ${dryRun}"Version no longer supported."`;

try {
const result = execSync(command);
log(`✅ Deprecated ${packageAndVersion}`);
log(result.toString());
} catch (err) {
error(`❌ Error - unable to deprecate ${packageAndVersion}`);
error(err);
process.exit(1);
}

await new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, 1000);
});
}
102 changes: 0 additions & 102 deletions scripts/release-deprecate.ts

This file was deleted.

0 comments on commit 058fcdb

Please sign in to comment.