Skip to content

Commit 102f8f4

Browse files
adding maven package migration post
1 parent 12af741 commit 102f8f4

File tree

5 files changed

+119
-16
lines changed

5 files changed

+119
-16
lines changed

_posts/2022-11-23-github-packages-migrate-nuget-packages.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ I recently had a customer ask me how they could migrate their NuGet packages fro
2222
> - [Migrate NuGet Packages to GitHub Packages](/posts/github-packages-migrate-nuget-packages-to-github-packages/)
2323
{: .prompt-info }
2424

25+
> See my other GitHub Package --> GitHub Package migration posts:
26+
> - [Migrate npm Packages Between GitHub Instances](/posts/github-packages-migrate-npm-packages/)
27+
> - [Migrate Maven Packages Between GitHub Instances](/posts/github-packages-migrate-maven-packages/)
28+
{: .prompt-info }
29+
30+
2531
## The script
2632

2733
The repo and docs can be found here:
@@ -33,14 +39,15 @@ I decided to store the script in a separate GitHub repo than my [github-misc-scr
3339

3440
### Prerequisites
3541

36-
1. [gh cli](https://cli.github.com) installed
42+
1. [`gh cli`](https://cli.github.com) installed
3743
2. Set the source GitHub PAT env var: `export GH_SOURCE_PAT=ghp_abc` (must have at least `read:packages`, `read:org` scope)
3844
3. Set the target GitHub PAT env var: `export GH_TARGET_PAT=ghp_xyz` (must have at least `write:packages`, `read:org` scope)
3945

4046
Notes:
4147

4248
- This script installs [gpr](https://github.com/jcansdale/gpr) locally to the `./temp/tools`{: .filepath} directory
43-
- This script assumes that the target org's repo name is the same as the source (the target repo doesn't _need_ to exist, the package just won't be mapped to a repo)
49+
- This script assumes that the target org's repo name is the same as the source
50+
- If the repo doesn't exist, the package will still import but won't be mapped to a repo
4451

4552
### Usage
4653

_posts/2023-09-08-github-packages-migrate-npm-packages.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ image:
1515

1616
## Overview
1717

18-
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](/posts/github-packages-migrate-nuget-packages/) solution, I also scripted out npm package migration. Take a look and let me know what you think!
18+
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](/posts/github-packages-migrate-nuget-packages/) solution, I also scripted out the npm package migration. Take a look and let me know what you think!
1919

20-
> See my other GitHub Package --> GitHub Package migration post:
20+
> See my other GitHub Package --> GitHub Package migration posts:
2121
> - [Migrate NuGet Packages Between GitHub Instances](/posts/github-packages-migrate-nuget-packages/)
22+
> - [Migrate Maven Packages Between GitHub Instances](/posts/github-packages-migrate-maven-packages/)
2223
{: .prompt-info }
2324

2425
## The script
@@ -30,14 +31,14 @@ The script can be found in my [github-misc-scripts](/posts/github-misc-scripts/)
3031

3132
### Prerequisites
3233

33-
1. [`gh cli`](https://cli.github.com) installed and logged in to be able to access the source GitHub instance:
34-
```bash
35-
gh auth login
36-
```
37-
{: .nolineno}
38-
2. `<source-pat>` must have `read:packages` scope (defined as environment variable `GH_SOURCE_PAT`)
39-
3. `<target-pat>` must have `write:packages` scope (defined as environment variable `GH_SOURCE_PAT`)
40-
4. This assumes that the target org's repo name is the same as the source
34+
1. [`gh cli`](https://cli.github.com) installed
35+
2. Set the source GitHub PAT env var: `export GH_SOURCE_PAT=ghp_abc` (must have at least `read:packages`, `read:org` scope)
36+
3. Set the target GitHub PAT env var: `export GH_TARGET_PAT=ghp_xyz` (must have at least `write:packages`, `read:org` scope)
37+
38+
Notes:
39+
40+
- This script assumes that the target org's repo name is the same as the source
41+
- If the repo doesn't exist, the package will still import but won't be mapped to a repo
4142

4243
### Usage
4344

@@ -68,7 +69,8 @@ export GH_TARGET_PAT=ghp_xyz
6869

6970
## Notes
7071

71-
- The script assumes that the target org's repo has the same name as the source
72+
- This script assumes that the target org's repo name is the same as the source
73+
- If the repo doesn't exist, the package will still import but won't be mapped to a repo
7274
- This script uses RegEx to find/replace source org with target org in the package's `package.json`{: .filepath} (see the [GitHub docs](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#publishing-a-package) for more info)
7375
- To clean up the working directory when done, run this one-liner:
7476
```bash
@@ -78,10 +80,10 @@ export GH_TARGET_PAT=ghp_xyz
7880

7981
## Improvement Ideas
8082

81-
* [ ] Add a source folder input instead of relying on current directory
82-
* [ ] Map between repositories where the target repo is named differently than the source repo
83+
* [x] Add a source folder input instead of relying on current directory (just using `./temp`{: .filepath})
84+
* [ ] Map between repositories where the target repo is named differently than the source repo (likely this isn't needed since if repo doesn't exist, packages will still be pushed, the package just won't be linked to a repository)
8385
* [x] Update script because of GitHub Packages GraphQL [deprecation](https://github.blog/changelog/2022-08-18-deprecation-notice-graphql-for-packages/)
8486

8587
## Summary
8688

87-
Drop a comment here or an issue or PR on the [repo](https://github.com/joshjohanning/github-misc-scripts/blob/main/scripts/migrate-npm-packages-between-github-instances.sh) if you have any feedback or suggestions! Happy packaging! 📦
89+
Drop a comment here or an issue or PR on my [github-misc-scripts repo](https://github.com/joshjohanning/github-misc-scripts/blob/main/scripts/migrate-npm-packages-between-github-instances.sh) if you have any feedback or suggestions! Happy packaging! 📦
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: 'GitHub Packages: Migrate Maven Packages Between GitHub Instances'
3+
author: Josh Johanning
4+
date: 2023-09-25 14:30:00 -0500
5+
description: Migrating Maven packages stored in GitHub Packages from one instance to another
6+
categories: [GitHub, Migrations]
7+
tags: [GitHub, Scripts, GitHub Packages, gh cli, Maven, Migrations]
8+
img_path: /assets/screenshots/2023-09-25-github-packages-migrate-maven-packages
9+
image:
10+
path: maven-packages-light.png
11+
width: 100%
12+
height: 100%
13+
alt: Maven packages in GitHub Packages
14+
---
15+
16+
## Overview
17+
18+
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](/posts/github-packages-migrate-nuget-packages/) and [npm](/posts/github-packages-migrate-npm-packages/) solutions, I also scripted out the Maven package migration. Take a look and let me know what you think!
19+
20+
> See my other GitHub Package --> GitHub Package migration posts:
21+
> - [Migrate NuGet Packages Between GitHub Instances](/posts/github-packages-migrate-nuget-packages/)
22+
> - [Migrate npm Packages Between GitHub Instances](/posts/github-packages-migrate-npm-packages/)
23+
{: .prompt-info }
24+
25+
## The script
26+
27+
The script can be found in my [github-misc-scripts](/posts/github-misc-scripts/) repo here:
28+
- **[https://github.com/joshjohanning/github-misc-scripts/blob/main/scripts/migrate-maven-packages-between-github-instances.sh](https://github.com/joshjohanning/github-misc-scripts/blob/main/scripts/migrate-maven-packages-between-github-instances.sh)**
29+
30+
## Running the script
31+
32+
### Prerequisites
33+
34+
1. [`gh cli`](https://cli.github.com) installed
35+
2. Set the source GitHub PAT env var: `export GH_SOURCE_PAT=ghp_abc` (must have at least `read:packages`, `read:org` scope)
36+
3. Set the target GitHub PAT env var: `export GH_TARGET_PAT=ghp_xyz` (must have at least `write:packages`, `read:org`, `repo` scope)
37+
38+
Notes:
39+
40+
- Until Maven supports the new GitHub Packages type, `mvnfeed` requires the target repo to exist
41+
- Link to [GitHub public roadmap item](https://github.com/github/roadmap/issues/578)
42+
- This scripts creates the repo if it doesn't exist
43+
- Otherwise, if the repo doesn't exist, receive "`example-1.0.5.jar`{: .filepath} was not found in the repository" error
44+
- Currently [`mvnfeed-cli`](https://github.com/microsoft/mvnfeed-cli) only supports migrating `.jar`{: .filepath} and `.pom`{: .filepath} files (not `.war`{: .filepath})
45+
46+
### Usage
47+
48+
You can call the script via:
49+
50+
```bash
51+
./migrate-maven-packages-between-github-instances.sh \
52+
<source-org> \
53+
<source-host> \
54+
<target-org> \
55+
<target-host>
56+
```
57+
58+
### Example
59+
60+
An example of this in practice:
61+
62+
```bash
63+
export GH_SOURCE_PAT=ghp_abc
64+
export GH_TARGET_PAT=ghp_xyz
65+
66+
./migrate-maven-packages-between-github-instances.sh \
67+
joshjohanning-org \
68+
github.com \
69+
joshjohanning-org-packages \
70+
github.com
71+
```
72+
73+
## Notes
74+
75+
- This script assumes that the target org's repo name is the same as the source
76+
- If the repo doesn't exist, the package will still import but won't be mapped to a repo
77+
- The script uses [`mvnfeed-cli`](https://github.com/microsoft/mvnfeed-cli) to migrate Maven packages to the target org
78+
- Currently `mvnfeed-cli` only supports migrating `.jar`{: .filepath} + `.pom`{: .filepath} files (not `.war`{: .filepath})
79+
- To clean up the working directory when done, run this one-liner:
80+
```bash
81+
rm -rf ./temp
82+
```
83+
{: .nolineno}
84+
85+
## Improvement Ideas
86+
87+
* [x] Add a source folder input instead of relying on current directory (just using `./temp`{: .filepath})
88+
* [ ] Map between repositories where the target repo is named differently than the source repo
89+
* [x] Update script because of GitHub Packages GraphQL [deprecation](https://github.blog/changelog/2022-08-18-deprecation-notice-graphql-for-packages/)
90+
* [ ] Fork [`mvnfeed-cli`](https://github.com/microsoft/mvnfeed-cli) to support migrating `.war`{: .filepath} files ([issue](https://github.com/microsoft/mvnfeed-cli/issues/16)) - this only supports `.jar`{: .filepath} files currently
91+
92+
## Summary
93+
94+
Drop a comment here or an issue or PR on my [github-misc-scripts repo](https://github.com/joshjohanning/github-misc-scripts/blob/main/scripts/migrate-maven-packages-between-github-instances.sh) if you have any feedback or suggestions! Happy packaging! 📦
123 KB
Loading
128 KB
Loading

0 commit comments

Comments
 (0)