Post

GitHub Packages: Migrate Maven Packages Between GitHub Instances

Overview

I have been working with more customers who are migrating GitHub instances and want to be able to migrate GitHub Packages. There is not an easy lift-and-shift approach to migrate GitHub Packages between instances; each ecosystem is independent. To go along with my NuGet and npm solutions, I also scripted out the Maven package migration. Take a look and let me know what you think!

See my other GitHub Package –> GitHub Package migration posts:

The script

The script can be found in my github-misc-scripts repo here:

Running the script

Prerequisites

  1. gh cli 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, repo scope)

Notes:

  • Until Maven supports the new GitHub Packages type, mvnfeed requires the target repo to exist
  • Link to GitHub public roadmap item
  • This scripts creates the repo if it doesn’t exist
  • Otherwise, if the repo doesn’t exist, receive “example-1.0.5.jar was not found in the repository” error
  • Currently mvnfeed-cli only supports migrating .jar and .pom files (not .war)

Usage

You can call the script via:

1
2
3
4
5
./migrate-maven-packages-between-github-instances.sh \
  <source-org> \
  <source-host> \
  <target-org> \
  <target-host>

Example

An example of this in practice:

1
2
3
4
5
6
7
8
export GH_SOURCE_PAT=ghp_abc
export GH_TARGET_PAT=ghp_xyz

./migrate-maven-packages-between-github-instances.sh \
  joshjohanning-org \
  github.com \
  joshjohanning-org-packages \
  github.com

Notes

  • This script assumes that the target org’s repo name is the same as the source
  • If the repo doesn’t exist, the package will still import but won’t be mapped to a repo
  • The script uses mvnfeed-cli to migrate Maven packages to the target org
  • Currently mvnfeed-cli only supports migrating .jar + .pom files (not .war)
  • To clean up the working directory when done, run this one-liner:
    1
    
    rm -rf ./temp
    

Improvement Ideas

  • Add a source folder input instead of relying on current directory (just using ./temp)
  • Map between repositories where the target repo is named differently than the source repo
  • Update script because of GitHub Packages GraphQL deprecation
  • Fork mvnfeed-cli to support migrating .war files (issue) - this only supports .jar files currently

Summary

Drop a comment here or an issue or PR on my github-misc-scripts repo if you have any feedback or suggestions! Happy packaging! 📦

This post is licensed under CC BY 4.0 by the author.