-
Notifications
You must be signed in to change notification settings - Fork 1.4k
chore: release deprecation script #3465
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f88774b
chore: migrate unpublish script -> deprecation script
danielbate 07d5962
chore: add deprecation workflow
danielbate f0de548
chore: changeset
danielbate 2655877
chore: rename workflow
danielbate c5ef167
chore: rebuild
danielbate 82caf3a
chore: use allSettled
danielbate 5c35c71
chore: add dry run
danielbate 8cb124f
chore: refactor
danielbate d1d0fa0
chore: filter out latest next tag
danielbate a0175f0
chore: remove hardcoded package
danielbate d0d1537
Merge branch 'master' into db/chore/release-deprecation
danielbate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
--- | ||
|
||
chore: release deprecation script | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: "Deprecate Old Versions" | ||
|
||
on: | ||
workflow_dispatch: | ||
danielbate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
inputs: | ||
deprecate_versions: | ||
type: boolean | ||
description: Deprecate versions? Otherwise dry-run mode will be used. | ||
default: false | ||
|
||
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 | ||
env: | ||
DEPRECATE_VERSIONS: ${{ github.event.inputs.deprecate_versions }} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
danielbate marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
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 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 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 getVersionsToDeprecate = async (packageName: string) => { | ||
const { versions } = await fetch(`https://registry.npmjs.org/${packageName}`).then((resp) => | ||
danielbate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
resp.json() | ||
); | ||
|
||
// Only deprecate certain tags | ||
const validVersions = Object.keys(versions).filter( | ||
(version) => version.search(deprecateTags) > -1 && !compare(version, currentVersion, '>=') | ||
); | ||
|
||
// Remove the latest next tag from the deprecation list | ||
const latestNextVersion = validVersions.filter((version) => version.search('next') > -1).pop(); | ||
return validVersions.filter((version) => version !== latestNextVersion); | ||
}; | ||
|
||
const main = async () => { | ||
const packages = getPublicPackages(); | ||
await Promise.allSettled( | ||
packages.map(async (packageName) => { | ||
const versionsToDeprecate = await getVersionsToDeprecate(packageName); | ||
|
||
log('The following versions will be deprecated:'); | ||
log(versionsToDeprecate.map((v) => ` - ${v}`).join('\n')); | ||
|
||
if (deprecateVersions) { | ||
await Promise.allSettled( | ||
versionsToDeprecate.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); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.