From 44e01c4fbee46d0dd336ded69128c5386373e1a3 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 21 Jan 2025 15:44:43 +0000 Subject: [PATCH 1/6] chore: added chunk size to deprecation script --- scripts/release-deprecate.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/release-deprecate.ts b/scripts/release-deprecate.ts index 922b967cc76..567785bcd6b 100644 --- a/scripts/release-deprecate.ts +++ b/scripts/release-deprecate.ts @@ -10,6 +10,7 @@ const { version: currentVersion } = JSON.parse( readFileSync(join(process.cwd(), '/packages/fuels/package.json')).toString() ); const deprecateVersions = process.env.DEPRECATE_VERSIONS === 'true'; +const CHUNK_SIZE = process.env.CHUNK_SIZE ? parseInt(process.env.CHUNK_SIZE, 10) : 1000; const getPublicPackages = () => { const packagesDir = join(__dirname, '../packages'); @@ -45,7 +46,8 @@ const main = async () => { const packages = getPublicPackages(); await Promise.allSettled( packages.map(async (packageName) => { - const versionsToDeprecate = await getVersionsToDeprecate(packageName); + const allVersions = await getVersionsToDeprecate(packageName); + const versionsToDeprecate = allVersions.splice(0, CHUNK_SIZE); log('The following versions will be deprecated:'); log(versionsToDeprecate.map((v) => ` - ${v}`).join('\n')); From 8e9e36182bfa293c59a0a35200e38864a2d60300 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 21 Jan 2025 16:32:21 +0000 Subject: [PATCH 2/6] chore: filtering for deprecations --- .github/workflows/release-deprecate.yaml | 10 +++++++++ scripts/release-deprecate.ts | 26 +++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release-deprecate.yaml b/.github/workflows/release-deprecate.yaml index 61807d69d16..6b241c0154a 100644 --- a/.github/workflows/release-deprecate.yaml +++ b/.github/workflows/release-deprecate.yaml @@ -7,6 +7,14 @@ on: type: boolean description: Deprecate versions? Otherwise dry-run mode will be used. default: false + filter_by_package_name: + type: string + description: Filter by package name + default: "" + filter_by_package_version: + type: string + description: Filter by package version + default: "" concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -27,3 +35,5 @@ jobs: run: pnpm release:deprecate env: 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 }} diff --git a/scripts/release-deprecate.ts b/scripts/release-deprecate.ts index 567785bcd6b..9209a88a167 100644 --- a/scripts/release-deprecate.ts +++ b/scripts/release-deprecate.ts @@ -9,10 +9,12 @@ const deprecateTags = /next|pr|rc/; const { version: currentVersion } = JSON.parse( readFileSync(join(process.cwd(), '/packages/fuels/package.json')).toString() ); -const deprecateVersions = process.env.DEPRECATE_VERSIONS === 'true'; -const CHUNK_SIZE = process.env.CHUNK_SIZE ? parseInt(process.env.CHUNK_SIZE, 10) : 1000; +const SHOULD_DEPRECATE_VERSIONS: boolean = process.env.DEPRECATE_VERSIONS === 'true'; +const CHUNK_SIZE: number = process.env.CHUNK_SIZE ? parseInt(process.env.CHUNK_SIZE, 10) : 1000; +const FILTER_BY_PACKAGE_NAME: string = process.env.FILTER_BY_PACKAGE_NAME ?? ''; +const FILTER_BY_VERSION: string = process.env.FILTER_BY_VERSION ?? ''; -const getPublicPackages = () => { +const getPublicPackages = (): string[] => { const packagesDir = join(__dirname, '../packages'); const packages = readdirSync(packagesDir, { withFileTypes: true }); const packagesNames = packages.map((p) => { @@ -27,7 +29,7 @@ const getPublicPackages = () => { return packagesNames.filter((p) => !!p); }; -const getVersionsToDeprecate = async (packageName: string) => { +const getVersionsToDeprecate = async (packageName: string): Promise => { const { versions } = await fetch(`https://registry.npmjs.org/${packageName}`).then((resp) => resp.json() ); @@ -43,16 +45,26 @@ const getVersionsToDeprecate = async (packageName: string) => { }; const main = async () => { - const packages = getPublicPackages(); + let packages = getPublicPackages(); + if (FILTER_BY_PACKAGE_NAME !== '') { + packages = packages.filter((packageName) => packageName === FILTER_BY_PACKAGE_NAME); + } + await Promise.allSettled( packages.map(async (packageName) => { const allVersions = await getVersionsToDeprecate(packageName); - const versionsToDeprecate = allVersions.splice(0, CHUNK_SIZE); + + let versionsToDeprecate = allVersions.splice(0, CHUNK_SIZE); + if (FILTER_BY_VERSION !== '') { + versionsToDeprecate = versionsToDeprecate.filter( + (version) => version === FILTER_BY_VERSION + ); + } log('The following versions will be deprecated:'); log(versionsToDeprecate.map((v) => ` - ${v}`).join('\n')); - if (deprecateVersions) { + if (SHOULD_DEPRECATE_VERSIONS) { await Promise.allSettled( versionsToDeprecate.map( async (versionToDelete) => From 7cf83565e81472faa33aebb297fd24b75f3e782f Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 21 Jan 2025 16:39:51 +0000 Subject: [PATCH 3/6] chore: log error messages --- scripts/release-deprecate.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/release-deprecate.ts b/scripts/release-deprecate.ts index 9209a88a167..297fa01b620 100644 --- a/scripts/release-deprecate.ts +++ b/scripts/release-deprecate.ts @@ -74,11 +74,13 @@ const main = async () => { (err, _stdout, stderr) => { if (err) { log(`❌ Error ${packageName}@${versionToDelete} not deprecated!\n`); + error(err); reject(err); return; } if (stderr) { log(`❌ Error ${packageName}@${versionToDelete} not deprecated!\n`); + error(stderr); reject(new Error(stderr)); return; } From 3e9217e1965ed420bb4f435dd64b8e8d6f6fdaaf Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 21 Jan 2025 16:56:42 +0000 Subject: [PATCH 4/6] chore: setup npm --- .github/workflows/release-deprecate.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/release-deprecate.yaml b/.github/workflows/release-deprecate.yaml index 6b241c0154a..eaccc086b4a 100644 --- a/.github/workflows/release-deprecate.yaml +++ b/.github/workflows/release-deprecate.yaml @@ -31,6 +31,11 @@ jobs: - name: CI Setup uses: ./.github/actions/ci-setup + - name: Setup NPM registry + uses: FuelLabs/github-actions/setups/npm@master + with: + npm-token: ${{ secrets.NPM_TOKEN }} + - name: Deprecate run: pnpm release:deprecate env: From 7910aa88f81d5ab1d0afb6a5377015172ef37398 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Wed, 5 Feb 2025 16:18:55 +0000 Subject: [PATCH 5/6] chore: upload action to allow for deprecations --- .github/workflows/release-deprecate.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-deprecate.yaml b/.github/workflows/release-deprecate.yaml index eaccc086b4a..3c4517bdfcb 100644 --- a/.github/workflows/release-deprecate.yaml +++ b/.github/workflows/release-deprecate.yaml @@ -24,6 +24,7 @@ jobs: deprecate-npm-versions: name: Deprecate versions next, pr and rc runs-on: buildjet-4vcpu-ubuntu-2204 + environment: npm-deploy steps: - name: Checkout uses: actions/checkout@v4 @@ -34,7 +35,7 @@ jobs: - name: Setup NPM registry uses: FuelLabs/github-actions/setups/npm@master with: - npm-token: ${{ secrets.NPM_TOKEN }} + npm-token: ${{ secrets.NPM_DEPLOY_TOKEN }} - name: Deprecate run: pnpm release:deprecate From 605806c18cae0a6d25c0a12006dadd055bf4dfe7 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Wed, 5 Feb 2025 18:43:10 +0000 Subject: [PATCH 6/6] added missing input --- .github/workflows/release-deprecate.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/release-deprecate.yaml b/.github/workflows/release-deprecate.yaml index 3c4517bdfcb..1a6a3584143 100644 --- a/.github/workflows/release-deprecate.yaml +++ b/.github/workflows/release-deprecate.yaml @@ -15,6 +15,10 @@ on: type: string description: Filter by package version default: "" + chunk_size: + type: number + description: Chunk size + default: 1000 concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -43,3 +47,4 @@ jobs: 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 }}