-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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: Delete NPM Versions | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
|
||
jobs: | ||
delete-npm-versions: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 'lts/*' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run deleteVersions script | ||
env: | ||
PACKAGE_NAME: ${{ secrets.NPM_PACKAGE_NAME }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: | | ||
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc | ||
node deleteVersions.js |
This file contains 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,31 @@ | ||
const { execSync } = require('child_process'); | ||
|
||
function getPackageVersions(packageName) { | ||
const result = execSync(`npm view ${packageName} versions --json`); | ||
return JSON.parse(result); | ||
} | ||
|
||
function deletePackageVersion(packageName, version) { | ||
try { | ||
execSync(`npm unpublish ${packageName}@${version}`); | ||
console.log(`Successfully deleted ${packageName}@${version}`); | ||
} catch (error) { | ||
console.error(`Failed to delete ${packageName}@${version}: ${error.message}`); | ||
} | ||
} | ||
|
||
function main() { | ||
const packageName = process.env.PACKAGE_NAME; | ||
if (!packageName) { | ||
console.error('PACKAGE_NAME environment variable is not set'); | ||
process.exit(1); | ||
} | ||
|
||
const versions = getPackageVersions(packageName); | ||
const versionsToDelete = versions.filter(version => /alpha|beta|canary/.test(version)); | ||
|
||
console.log(JSON.stringify(versionsToDelete,null,2)); | ||
// versionsToDelete.forEach(version => deletePackageVersion(packageName, version)); | ||
} | ||
|
||
main(); |