Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Publish plugin to public UPM feed #34

Merged
merged 23 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Pipelines/Templates/Package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ jobs:
displayName: Copy .npmrc for Public Feed
inputs:
script: copy $(Build.SourcesDirectory)\Tools\PublicFeed.npmrc $(Build.SourcesDirectory)\Source\Plugins\IsacPluginGenerator\Assets\Microsoft.SpatialAudio.Spatializer.Unity\.npmrc
- task: npmAuthenticate@0
displayName: Public NPM Feed Authentication
inputs:
workingFile: Source\Plugins\IsacPluginGenerator\Assets\Microsoft.SpatialAudio.Spatializer.Unity\.npmrc
customEndpoint: 'AIPMR SC MixedReality-Unity-Packages'
- script: python tools\upm_package.py -s $(Pipeline.Workspace) -o "$(Pipeline.Workspace)\npm" -v $(ProductVersion)
displayName: Build Public NPM Package
- task: PublishBuildArtifacts@1
Expand All @@ -101,6 +96,6 @@ jobs:
- task: PublishBuildArtifacts@1
displayName: 'Publish NPM Package to Build Artifacts'
inputs:
PathtoPublish: '$(Pipeline.Workspace)\npm'
PathtoPublish: '$(Build.SourcesDirectory)\Source\Plugins\IsacPluginGenerator\Assets\Microsoft.SpatialAudio.Spatializer.Unity\'
ArtifactName: 'NpmPackage'

14 changes: 14 additions & 0 deletions Pipelines/Templates/Publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ jobs:
- script: echo Syncing Source
- checkout: self
submodules: true
- script: echo Downloading NPM Artifacts
- task: DownloadPipelineArtifact@2
inputs:
artifactName: 'NpmPackage'
buildType: 'current'
targetPath: '$(Pipeline.Workspace)\npm'
- task: npmAuthenticate@0
displayName: Public NPM Feed Authentication
inputs:
workingFile: '$(Pipeline.Workspace)\npm\.npmrc'
customEndpoint: 'AIPMR SC MixedReality-Unity-Packages'
- script: npm publish $(Pipeline.Workspace)\npm
displayName: Publish NPM Package to Public UPM Feed

- script: echo Downloading Nuget Artifacts
- task: DownloadPipelineArtifact@2
inputs:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
registry=https://pkgs.dev.azure.com/aipmr/MixedReality-Unity-Packages/_packaging/Unity-packages/npm/registry/
registry=https://microsoft.pkgs.visualstudio.com/Analog/_packaging/MixedReality-UPM-Internal/npm/registry/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the name of the feed includes the word "Internal". Is this a staging feed before the package goes to an external feed? It's obvious that I don't know how all of this works.

Copy link
Contributor Author

@ashtat ashtat Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the packaging stage we publish to an internal feed, which can be then tested to make sure everything is good. Once the build is "approved" after the packaging phase, the publishing phase then pushes the plugin to both nuget and UPM public feeds. There are two separate .npmrc files that correspond to internal and public feeds, these are under "tools" subdir. These get placed (and renamed to ".npmrc") under the plugin hierarchy depending on which feed we need to publish to.


always-auth=true
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "%version%",
"unity": "2019.4",
"description": "Audio Spatializer for HoloLens and Windows Mixed Reality applications",
"msftFeatureCategory": "Spatial Audio",
"keywords": [
"microsoft",
"mixed",
Expand Down
82 changes: 51 additions & 31 deletions Tools/upm_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,65 @@ def main():
parser.add_argument("-o", "--output", help="Output location, will use default build/npm location if unspecified", type=str.lower)
parser.add_argument("-v", "--version", help="Semantic version string for the package", type=str.lower)
parser.add_argument("-p", "--publish", help="Publish the package to NPM feed", action='store_true')
parser.add_argument("-t", "--tarball", help="Publish specified tarball", type=str.lower)
parser.add_argument("-d", "--dryrun", help="Simulate publishing without pushing", action='store_true')
args = parser.parse_args()

# Copy plugin binaries to project location
if not args.stage:
stage.stage_binaries()
else:
stage.stage_binaries(args.stage)
if not args.tarball:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why you start with !tarball instead of checking for args=tarball? It's easier for me to think in the positive case instead of negating the comparator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the script takes the plugin folder into a tarball which then gets pushed to the feed or it can just pack it as a tarball to be pushed later. The initial idea was to push to the internal feed during the packaging stage and store the tarball as an artifact which can be then downloaded during the "publish" stage to be pushed to the public feed. Unfortunately pushing the tarball is cryptically failing on the CI build machine. Long winded way to say this wasn't super intentional. :)

# Copy plugin binaries to project location
if not args.stage:
stage.stage_binaries()
else:
stage.stage_binaries(args.stage)

git_root = oshelpers.fixpath(githelpers.get_root())
git_root = oshelpers.fixpath(githelpers.get_root())

# Default output path is under build/unity
npm_package_location = oshelpers.fixpath(git_root, constants.build_root, "npm")
if args.output:
npm_package_location = args.output
# Default output path is under build/unity
npm_package_location = oshelpers.fixpath(git_root, constants.build_root, "npm")
if args.output:
npm_package_location = args.output

if not os.path.isdir(npm_package_location):
os.mkdir(npm_package_location)
if not os.path.isdir(npm_package_location):
os.mkdir(npm_package_location)

unity_project_full_path = oshelpers.fixpath(git_root, constants.unity_project_dir, "Assets", constants.spatializer_plugin_name)
npm_package_full_path = oshelpers.fixpath(npm_package_location, constants.spatializer_plugin_name + "." + args.version)
# Specify the package version before packing
result = subprocess.run(["cmd", "/c", "npm version", args.version, "--allow-same-version"], cwd=unity_project_full_path)
local_copy = False
if args.publish:
npm_command = ["cmd", "/c", "npm publish"]
else:
local_copy = True
npm_command = ["cmd", "/c", "npm pack"]
result = subprocess.run(npm_command, cwd=unity_project_full_path)
if (result.returncode != 0):
print("Package generation failed!")
print(result.stdout)
print(result.stderr)
unity_project_full_path = oshelpers.fixpath(git_root, constants.unity_project_dir, "Assets", constants.spatializer_plugin_name)
# Specify the package version before packing
result = subprocess.run(["cmd", "/c", "npm version", args.version, "--allow-same-version"], cwd=unity_project_full_path)
local_copy = False
if args.publish:
npm_command = ["cmd", "/c", "npm publish", "--dry-run" if args.dryrun else ""]
else:
local_copy = True
npm_command = ["cmd", "/c", "npm pack"]
print(npm_command)
result = subprocess.run(npm_command, cwd=unity_project_full_path)
if (result.returncode != 0):
print("Package generation failed!")
print(result.stdout)
print(result.stderr)
else:
if local_copy:
npm_package_full_path = oshelpers.fixpath(unity_project_full_path, constants.spatializer_npm_package_name + "-" + args.version + ".tgz")
shutil.move(npm_package_full_path, npm_package_location)
print("Package successfully generated: " + npm_package_full_path)
for file in os.listdir(npm_package_location):
if file.endswith(".tgz"):
print("Package successfully moved to " + oshelpers.fixpath(npm_package_location, file))
else:
print("Package successfully published")
else:
if local_copy:
shutil.move(oshelpers.fixpath(unity_project_full_path, constants.spatializer_npm_package_name + "-" + args.version + ".tgz"), npm_package_location)
print("Package successfully generated: " + npm_package_full_path)
if not os.path.exists(args.tarball):
print("Can't find tarball " + args.tarball)
exit
npm_command = ["cmd", "/c", "npm publish", args.tarball, "--dry-run" if args.dryrun else ""]
print(npm_command)
result = subprocess.run(npm_command)
if (result.returncode != 0):
print("Package generation failed!")
print(result.stdout)
print(result.stderr)
else:
print("Package successfully published")
print("Published tarball!")

if __name__ == '__main__':
main()