Skip to content

Commit

Permalink
feat: enhancements to npm package migrate script
Browse files Browse the repository at this point in the history
- downloading silently, but show errors
- ignore npm lifecycle scripts on publish
- add note on permissions issues
- recommending to use ` | tee` to write output to separate log file
  • Loading branch information
joshjohanning committed Sep 5, 2024
1 parent 8127914 commit 65e958b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scripts/migrate-npm-packages-between-github-instances.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

# Usage: ./migrate-npm-packages-between-github-instances.sh <source-org> <source-host> <target-org> <target-host>
# Usage: ./migrate-npm-packages-between-github-instances.sh <source-org> <source-host> <target-org> <target-host> | tee output.log
#
#
# Prereqs:
# 1. [gh cli](https://cli.github.com) installed
# 2. Set the source GitHub PAT env var: `export GH_SOURCE_PAT=ghp_abc` (must have at least `read:packages`, `read:org` scope)
# 3. Set the target GitHub PAT env var: `export GH_TARGET_PAT=ghp_xyz` (must have at least `write:packages`, `read:org` scope)
#
# Example: ./migrate-npm-packages-between-github-instances.sh joshjohanning-org github.com joshjohanning-emu github.com
# Example: ./migrate-npm-packages-between-github-instances.sh joshjohanning-org github.com joshjohanning-emu github.com | tee output.log
#
# Notes:
# - Mapping the npm package to a repo is optional.
Expand Down Expand Up @@ -74,14 +74,15 @@ echo "$packages" | while IFS= read -r response; do
fi

# download
curl -H "Authorization: token $GH_SOURCE_PAT" -L -o $package_name-$version.tgz $url
curl -sS -H "Authorization: token $GH_SOURCE_PAT" -L -o $package_name-$version.tgz $url

# untar
mkdir -p ./$package_name-$version
# if you run into permissions issue, add a `sudo` here
tar xzf $package_name-$version.tgz -C $package_name-$version
cd $package_name-$version/package
perl -pi -e "s/$SOURCE_ORG/$TARGET_ORG/ig" package.json
npm publish --userconfig $temp_dir/.npmrc || echo "skipped package due to failure: $package_name-$version.tgz" >> ./failed-packages.txt
npm publish --ignore-scripts --userconfig $temp_dir/.npmrc || echo "skipped package due to failure: $package_name-$version.tgz" >> ./failed-packages.txt
cd ./../../

done
Expand Down

0 comments on commit 65e958b

Please sign in to comment.