Skip to content
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/build-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ jobs:
needs: gate
uses: ./.github/workflows/artifactoryTests.yml
secrets: inherit
choco:
needs: gate
uses: ./.github/workflows/chocoTests.yml
secrets: inherit
conan:
needs: gate
uses: ./.github/workflows/conanTests.yml
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/chocoTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Chocolatey Tests

on:
workflow_call:
workflow_dispatch:

jobs:
Choco-Tests:
name: Chocolatey tests (windows)
# Chocolatey is a Windows-only package manager, so unlike the other package
# manager suites this one does not run on a matrix.
runs-on: windows-2022
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
# Safe: this workflow only runs after human approval via the build-gate environment.
allow-unsafe-pr-checkout: true

- name: Setup FastCI
uses: jfrog-fastci/fastci@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
fastci_otel_token: ${{ secrets.FASTCI_TOKEN }}

# Chocolatey is pre-installed on GitHub-hosted Windows runners (2.7.4 on windows-2022).
# 'jf setup choco' needs 2.0+ for the 'apikey add' verb - on 1.x, a bare 'choco apikey'
# only lists keys - so fail here with a clear message rather than letting every setup
# test fail later on an argument-parsing error.
- name: Verify Chocolatey
shell: pwsh
run: |
$version = (choco --version).Trim()
Write-Host "Chocolatey version: $version"
if ([int]($version -split '\.')[0] -lt 2) {
Write-Error "'jf setup choco' requires Chocolatey 2.0+ for the 'apikey add' verb; found $version"
exit 1
}

- name: Setup Go with cache
uses: jfrog/.github/actions/install-go-with-cache@main

- name: Install local Artifactory
uses: jfrog/.github/actions/install-local-artifactory@main
with:
RTLIC: ${{ secrets.RTLIC }}
RT_CONNECTION_TIMEOUT_SECONDS: ${{ env.RT_CONNECTION_TIMEOUT_SECONDS || '1200' }}

- name: Run Chocolatey tests
run: >-
go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.choco
${{ env.JFROG_TESTS_IS_EXTERNAL == 'true' && format('--jfrog.url={0} --jfrog.adminToken={1}', env.JFROG_TESTS_URL, env.JFROG_TESTS_LOCAL_ACCESS_TOKEN) || '' }}

# The OS gate is the one behaviour that can only be observed where Chocolatey cannot run, so it
# needs a non-Windows job. Deliberately cheap: no Artifactory and no Chocolatey, just the two
# tests asserting that 'jf choco' refuses to run and that 'jf choco --help' still works anyway.
Choco-OS-Gate:
name: Chocolatey OS gate (linux)
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
# Safe: this workflow only runs after human approval via the build-gate environment.
allow-unsafe-pr-checkout: true

- name: Setup Go with cache
uses: jfrog/.github/actions/install-go-with-cache@main

- name: Assert jf choco refuses to run on a non-Windows host
run: >-
go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.choco
-run 'TestChocoNonWindowsGate|TestChocoHelpWorksOnAllPlatforms'
68 changes: 68 additions & 0 deletions buildtools/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
alpinecommand "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/alpine"
aptcommand "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/apt"
cargocommand "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/cargo"
chococommand "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/choco"
conancommand "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/conan"
nixcommand "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/nix"
nugetcommand "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/nuget"
Expand Down Expand Up @@ -64,6 +65,7 @@ import (
"github.com/jfrog/jfrog-cli/docs/buildtools/apkcommand"
aptdocs "github.com/jfrog/jfrog-cli/docs/buildtools/apt"
"github.com/jfrog/jfrog-cli/docs/buildtools/cargo"
chocodocs "github.com/jfrog/jfrog-cli/docs/buildtools/choco"
"github.com/jfrog/jfrog-cli/docs/buildtools/conan"
"github.com/jfrog/jfrog-cli/docs/buildtools/conanconfig"
"github.com/jfrog/jfrog-cli/docs/buildtools/docker"
Expand Down Expand Up @@ -248,6 +250,21 @@ func GetCommands() []cli.Command {
Category: buildToolsCategory,
Action: NugetCmd,
},
{
Name: "choco",
Flags: cliutils.GetCommandFlags(cliutils.Choco),
Usage: corecommon.ResolveDescription(chocodocs.GetDescription(), chocodocs.GetAIDescription()),
HelpName: corecommon.CreateUsage("choco", corecommon.ResolveDescription(chocodocs.GetDescription(), chocodocs.GetAIDescription()), chocodocs.Usage),
UsageText: chocodocs.GetArguments(),
ArgsUsage: common.CreateEnvVars(),
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Category: buildToolsCategory,
Action: func(c *cli.Context) error {
cmdName, _ := getCommandName(c.Args())
return securityCLI.WrapCmdWithCurationPostFailureRun(c, ChocoCmd, techutils.Nuget, cmdName)
},
},
{
Name: "dotnet-config",
Flags: cliutils.GetCommandFlags(cliutils.DotnetConfig),
Expand Down Expand Up @@ -1094,6 +1111,52 @@ func NugetCmd(c *cli.Context) error {
return commands.ExecWithPackageManager(nugetCmd, project.Nuget.String())
}

func ChocoCmd(c *cli.Context) error {
if show, err := cliutils.ShowGenericCmdHelpIfNeeded(c, c.Args(), c.Command.Name); show || err != nil {
return err
}
if c.NArg() < 1 {
return cliutils.WrongNumberOfArgumentsHandler(c)
}
args := cliutils.ExtractCommand(c)
args, serverID, err := coreutils.ExtractServerIdFromCommand(args)
if err != nil {
return fmt.Errorf("extract server ID: %w", err)
}
filteredArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(args)
if err != nil {
return err
}
filteredArgs, repoResolve, err := coreutils.ExtractStringOptionFromArgs(filteredArgs, "repo-resolve")
if err != nil {
return fmt.Errorf("extract --repo-resolve: %w", err)
}
filteredArgs, repoDeploy, err := coreutils.ExtractStringOptionFromArgs(filteredArgs, "repo")
if err != nil {
return fmt.Errorf("extract --repo: %w", err)
}
commandName, commandArgs := getCommandName(filteredArgs)
workingDirectory, err := filepath.Abs(".")
if err != nil {
return err
}
command := chococommand.NewChocoFlexPackCommand().
SetSubCommand(commandName).
SetArgs(commandArgs).
SetRepoResolve(repoResolve).
SetRepoDeploy(repoDeploy).
SetBuildConfiguration(buildConfiguration).
SetWorkingDirectory(workingDirectory)
serverDetails, err := coreConfig.GetSpecificConfig(serverID, true, false)
if err != nil && serverID != "" {
return fmt.Errorf("server-id %q not found: %w", serverID, err)
}
if err == nil {
command.SetServerDetails(serverDetails)
}
return commands.ExecWithPackageManager(command, "choco")
}

func DotnetCmd(c *cli.Context) error {
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
return err
Expand Down Expand Up @@ -1946,6 +2009,11 @@ func setupCmd(c *cli.Context) (err error) {
return
}
}
if packageManager == project.Choco {
if err = setup.ValidateChocoPlatform(); err != nil {
return err
}
}
setupCmd := setup.NewSetupCommand(packageManager)
artDetails, err := cliutils.CreateArtifactoryDetailsByFlags(c)
if err != nil {
Expand Down
Loading
Loading