Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: release deprecation script #3465

Merged
merged 11 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/lucky-flies-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: release deprecation script
danielbate marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions .github/workflows/release-deprecate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Deprecate Old Versions"

on:
workflow_dispatch:
danielbate marked this conversation as resolved.
Show resolved Hide resolved

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
deprecate-npm-versions:
name: Deprecate versions next, pr and rc
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Checkout
uses: actions/checkout@v4

- name: CI Setup
uses: ./.github/actions/ci-setup

- name: Deprecate
run: pnpm release:deprecate
28 changes: 0 additions & 28 deletions .github/workflows/release-unpublish.yaml

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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",
"forc:update": "tsx ./scripts/forc-update",
"forc:check": "./scripts/forc-check.sh",
"forc:format": "./scripts/forc-format.sh",
Expand Down
75 changes: 75 additions & 0 deletions scripts/release-deprecate.ts
danielbate marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { compare } from 'compare-versions';
import { exec } from 'node:child_process';
import { readFileSync, readdirSync } from 'node:fs';
import { join } from 'node:path';

const { log, error } = console;

const UNPUBLISH_TAGS = /next|pr|rc/;
const { version: CURRENT_VERSION } = JSON.parse(
readFileSync(join(process.cwd(), '/packages/fuels/package.json')).toString()
);

const getPublicPackages = () => {
const packagesDir = join(__dirname, '../packages');
const packages = readdirSync(packagesDir, { withFileTypes: true });
const packagesNames = packages.map((p) => {
try {
const packageContent = readFileSync(join(packagesDir, p.name, 'package.json'), 'utf8');
const packageJson = JSON.parse(packageContent.toString());
return packageJson.private ? null : packageJson.name;
} catch (err) {
return null;
}
});
return packagesNames.filter((p) => !!p);
};

const main = async () => {
const packages = getPublicPackages();
await Promise.all(
petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved
packages.map(async (packageName) => {
const { versions: packageVersions } = await fetch(
`https://registry.npmjs.org/${packageName}`
).then((resp) => resp.json());

const versionsToDelete = Object.keys(packageVersions).filter(
(packageVersion) =>
packageVersion.search(UNPUBLISH_TAGS) > -1 &&
!compare(packageVersion, CURRENT_VERSION, '>=')
);
log('The following versions will be deprecated:');
log(versionsToDelete.map((v) => ` - ${v}`).join('\n'));

await Promise.all(
danielbate marked this conversation as resolved.
Show resolved Hide resolved
versionsToDelete.map(
async (versionToDelete) =>
new Promise((resolve, reject) => {
exec(
`npm deprecate ${packageName}@${versionToDelete} "Version no longer supported."`,
(err, _stdout, stderr) => {
if (err) {
log(`❌ Error ${packageName}@${versionToDelete} not deprecated!\n`);
reject(err);
return;
}
if (stderr) {
log(`❌ Error ${packageName}@${versionToDelete} not deprecated!\n`);
reject(new Error(stderr));
return;
}
log(`✅ Package ${packageName}@${versionToDelete} deprecated!\n`);
resolve(true);
}
);
})
)
);
})
);
};

main().catch((err) => {
error(err);
process.exit(1);
});
59 changes: 0 additions & 59 deletions scripts/release-unpublish.js

This file was deleted.

Loading