You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
4. Can use this one-liner to find the absolute path for [`gpr`](https://github.com/jcansdale/gpr) for the `<path-to-gpr>` parameter:
52
-
```bash
53
-
find / -wholename "*tools/gpr"2> /dev/null
54
-
```
55
-
{: .nolineno}
56
-
5.`<source-pat>` must have `read:packages` scope
57
-
6.`<target-pat>` must have `write:packages` scope
58
-
7. This assumes that the target org's repo name is the same as the source
59
-
60
-
We are passing [`gpr`](https://github.com/jcansdale/gpr) in as a parameter explicitly because sometimes [`gpr`](https://github.com/jcansdale/gpr) is aliased to `git pull --rebase` and that's not what we want here.
36
+
1.[gh cli](https://cli.github.com) installed
37
+
2. Set the source GitHub PAT env var: `export GH_SOURCE_PAT=ghp_abc` (must have at least `read:packages`, `read:org` scope)
38
+
3. Set the target GitHub PAT env var: `export GH_TARGET_PAT=ghp_xyz` (must have at least `write:packages`, `read:org` scope)
39
+
40
+
Notes:
41
+
42
+
- 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)
61
44
62
45
### Usage
63
46
@@ -67,29 +50,27 @@ You can call the script via:
67
50
./migrate-nuget-packages-between-orgs.sh \
68
51
<source-org>
69
52
<source-host> \
70
-
<source-pat> \
71
-
<target-org> \
72
-
<target-pat> \
73
-
<path-to-gpr>
53
+
<target-org>
74
54
```
75
55
76
56
### Example
77
57
78
58
An example of this in practice:
79
59
80
60
```bash
61
+
export GH_SOURCE_PAT=ghp_abc
62
+
export GH_TARGET_PAT=ghp_xyz
63
+
81
64
./migrate-nuget-packages-between-orgs.sh \
82
65
joshjohanning-org-packages \
83
66
github.com \
84
-
ghp_abc \
85
-
joshjohanning-org-packages-migrated \
86
-
ghp_xyz \
87
-
/home/codespace/.dotnet/tools/gpr
67
+
joshjohanning-org-packages-migrated
88
68
```
89
69
90
70
## Notes
91
71
92
-
- The script uses [`gpr`](https://github.com/jcansdale/gpr) to re-push the packages to the target org. It assumes that the target org's repo has the same name as the source.
72
+
- The script assumes that the target org's repo has the same name as the source - it's not required, but the package won't be mapped to a repo if the target repo doesn't exist
73
+
- The script uses [`gpr`](https://github.com/jcansdale/gpr) to re-push the packages to the target org
93
74
+ I initially tried writing this with [`dotnet nuget push`](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push), but that doesn't seem to work since the package's `<RepositoryUrl>` element would still be referencing the original repository. See error:
94
75
95
76
```
@@ -107,9 +88,9 @@ An example of this in practice:
107
88
{: file='\'dotnet nuget push\' error'}
108
89
109
90
+ [`gpr`](https://github.com/jcansdale/gpr) works because it rewrites the `<repository url="..." />` element in the `.nuspec`{: .filepath} file in the `.nupkg`{: .filepath} before pushing
110
-
+ There is an item on [GitHub's roadmap](https://github.com/github/roadmap/issues/589) to support pushing packages directly to an organization; this should allow [`dotnet nuget push`](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push) to work instead of [`gpr`](https://github.com/jcansdale/gpr)
91
+
+ Update Dec 2022: Now that NuGet Packages has supports granular permissions and organization sharing ([GitHub's roadmap item](https://github.com/github/roadmap/issues/589)), [`dotnet nuget push`](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push) should work - but using [`gpr`](https://github.com/jcansdale/gpr) for mapping convenience
111
92
- [`gpr`](https://github.com/jcansdale/gpr) still might be preferred since you would have to tie the NuGet package to the repository manually post-migration
112
-
- For [`dotnet nuget push`](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push) to work, you will have to add the feed first using this command:
93
+
- If attempting to use [`dotnet nuget push`](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push), you will have to add the feed first using this command:
113
94
```bash
114
95
dotnet nuget add source \
115
96
--username my-github-username \
@@ -122,15 +103,15 @@ An example of this in practice:
122
103
- Also, in the script, I had to delete `_rels/.rels`{: .filepath} and `[Content_Types].xml`{: .filepath} because there was somehow two copies of each file in the package and it causes gpr to fail when extracting/zipping the package to re-push
123
104
- To clean up the working directory when done, run this one-liner:
124
105
```bash
125
-
rm *.nupkg *.zip
106
+
rm -rf ./temp
126
107
```
127
108
{: .nolineno}
128
109
129
110
## Improvement Ideas
130
111
131
-
*[] Add a source folder input instead of relying on current directory
132
-
*[ ] Map between repositories where the target repo is named differently than the source repo
133
-
*[] Dynamically determine out where [`gpr`](https://github.com/jcansdale/gpr) is installed instead of passing in a parameter (right now we are passing the `gpr` path in as a parameter explicitly because sometimes `gpr` is aliased to `git pull --rebase`)
112
+
*[x] Add a source folder input instead of relying on current directory (just using `./temp`{: .filepath})
113
+
*[ ] 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)
114
+
*[x] Dynamically determine out where [`gpr`](https://github.com/jcansdale/gpr) is installed instead of passing in a parameter (right now we are passing the `gpr` path in as a parameter explicitly because sometimes `gpr` is aliased to `git pull --rebase`) (installing `gpr` locally to the `./temp/tools`{: .filepath} directory)
134
115
*[x] Update script because of GitHub Packages GraphQL [deprecation](https://github.blog/changelog/2022-08-18-deprecation-notice-graphql-for-packages/)
0 commit comments