Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to fetch the nugetforunity packages during CI/CD in a github action? #522

Open
gotchipete opened this issue May 17, 2023 · 5 comments

Comments

@gotchipete
Copy link

Has anyone done this?

@JoC0de
Copy link
Collaborator

JoC0de commented May 17, 2023

Hi,
In the CI of NuGetForUnity we use it to verify that it works.

- name: Install NuGetForUnity.Cli Tool
run: dotnet tool install --add-source . NuGetForUnity.Cli --version ${{ needs.determineVersionNumber.outputs.version }}
- name: Restore NuGet packages using NuGetForUnity.Cli
run: dotnet nugetforunity restore '${{ matrix.projectPath }}'

Note: When you do it in your own CI you don't need the --add-source. Normally you would install the tool locally and than do dotnet tool restore (just look at the official documentation for global tools).

@JoC0de
Copy link
Collaborator

JoC0de commented May 18, 2023

See also the documentation in the ReadMe.md. I thought that this is "enough" to understand how to use it in CI/CD. Do you have any suggestion on how we can improve the documentation?

@gotchipete
Copy link
Author

gotchipete commented May 18, 2023

Not sure yet how to improve it but I'm trying to follow it unsuccessfully thus far (including the comments in this thread).. tried multiple things, most recent is

locally:

dotnet new tool-manifest
dotnet tool install NuGetForUnity.Cli
# (succeeds)

in build action (after checkout - trying to do what you say here: #522 (comment))

      # setup .NET for package resolution
      - name: Setup dotnet
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: 2.1

      # Install NuGetForUnity.Cli
      - name: Restore dotnet tool - NuGetForUnity.Cli
        run: dotnet tool restore

      # Restore NuGetForUnity packages
      - name: Restore NuGetForUnity packages
        run: dotnet nugetforunity restore ./apps/myapp

... build output gives me (from the Install NuGetForUnity.Cli step)

Required command was not provided.
tnet tool [options] [command]

Options:
  -h, --help   Show command line help.

Commands:
  install <PACKAGE_ID>     Install a tool for use on the command line.
  uninstall <PACKAGE_ID>   Uninstall a tool from the current development environment.
  update <PACKAGE_ID>      Update a tool to the latest stable version.
  list                     List tools installed in the current development environment.
Error: Process completed with exit code 1.

@gotchipete
Copy link
Author

gotchipete commented May 18, 2023

aha this is working but i have an issue with one of my packages now. @JoC0de if there is a way i can improve this lmk

      # setup .NET for package resolution
      - name: Setup dotnet
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: 7.0

      # Install NuGetForUnity.Cli
      - name: Restore dotnet tool - NuGetForUnity.Cli
        run: dotnet new tool-manifest; dotnet tool install NuGetForUnity.Cli

      # Restore NuGetForUnity packages
      - name: Restore NuGetForUnity packages
        run: dotnet nugetforunity restore ./apps/myapp

@JoC0de
Copy link
Collaborator

JoC0de commented May 19, 2023

dotnet new tool-manifest creates a file .config/dotnet-tools.json see e.g. .config/dotnet-tools.json.
wenn you commit this file to your repository, so it is available to the GitHub action, you can call dotnet tool restore -> it will restore all tools defined in .config/dotnet-tools.json. Normally I would do it this way as it provides a easy way of managing what version of NuGetForUnity.Cli is used in a clear way so you can update the version with dotnet tool update NuGetForUnity.Cli. Also dependabot can handle updating tools defined in .config/dotnet-tools.json see: dependabot/dependabot-core#7028.
Alternative you can do dotnet tool install --global NuGetForUnity.Cli inside the action to always use the latest version, or specify the version by adding the --version argument. But as I said I don't prefer it as you need to update the workflow to update the tool. Not specifying the version is also not recommended as you don't see when something changes / you can't roll back if something is failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants