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

Twine support #2699

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/pythonTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ jobs:
if: ${{ matrix.suite == 'pipenv' }}
run: python -m pip install pipenv

- name: Setup Twine
if: ${{ matrix.suite == 'pip' }}
run: python -m pip install twine

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

Expand Down
126 changes: 88 additions & 38 deletions buildtools/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/jfrog/jfrog-cli-security/commands/scan"
terraformdocs "github.com/jfrog/jfrog-cli/docs/artifactory/terraform"
"github.com/jfrog/jfrog-cli/docs/artifactory/terraformconfig"
twinedocs "github.com/jfrog/jfrog-cli/docs/artifactory/twine"
"github.com/jfrog/jfrog-cli/docs/buildtools/docker"
dotnetdocs "github.com/jfrog/jfrog-cli/docs/buildtools/dotnet"
"github.com/jfrog/jfrog-cli/docs/buildtools/dotnetconfig"
Expand Down Expand Up @@ -402,6 +403,18 @@ func GetCommands() []cli.Command {
Category: buildToolsCategory,
Action: terraformCmd,
},
{
Name: "twine",
Flags: cliutils.GetCommandFlags(cliutils.Twine),
Usage: twinedocs.GetDescription(),
HelpName: corecommon.CreateUsage("twine", twinedocs.GetDescription(), twinedocs.Usage),
UsageText: twinedocs.GetArguments(),
ArgsUsage: common.CreateEnvVars(),
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Category: buildToolsCategory,
Action: twineCmd,
},
})
}

Expand All @@ -410,13 +423,11 @@ func MvnCmd(c *cli.Context) (err error) {
return err
}

configFilePath, exists, err := project.GetProjectConfFilePath(project.Maven)
configFilePath, err := getProjectConfigPathOrThrow(project.Maven, "mvn", "mvn-config")
if err != nil {
return err
}
if !exists {
return errors.New("no config file was found! Before running the mvn command on a project for the first time, the project should be configured with the mvn-config command")
}

if c.NArg() < 1 {
return cliutils.WrongNumberOfArgumentsHandler(c)
}
Expand Down Expand Up @@ -469,13 +480,11 @@ func GradleCmd(c *cli.Context) (err error) {
return err
}

configFilePath, exists, err := project.GetProjectConfFilePath(project.Gradle)
configFilePath, err := getProjectConfigPathOrThrow(project.Gradle, "gradle", "gradle-config")
if err != nil {
return err
}
if !exists {
return errors.New("no config file was found! Before running the gradle command on a project for the first time, the project should be configured with the gradle-config command")
}

// Found a config file. Continue as native command.
if c.NArg() < 1 {
return cliutils.WrongNumberOfArgumentsHandler(c)
Expand Down Expand Up @@ -525,13 +534,10 @@ func YarnCmd(c *cli.Context) error {
return err
}

configFilePath, exists, err := project.GetProjectConfFilePath(project.Yarn)
configFilePath, err := getProjectConfigPathOrThrow(project.Yarn, "yarn", "yarn-config")
if err != nil {
return err
}
if !exists {
return fmt.Errorf("no config file was found! Before running the yarn command on a project for the first time, the project should be configured using the yarn-config command")
}

yarnCmd := yarn.NewYarnCommand().SetConfigFilePath(configFilePath).SetArgs(c.Args())
return commands.Exec(yarnCmd)
Expand All @@ -544,15 +550,12 @@ func NugetCmd(c *cli.Context) error {
if c.NArg() < 1 {
return cliutils.WrongNumberOfArgumentsHandler(c)
}
configFilePath, exists, err := project.GetProjectConfFilePath(project.Nuget)

configFilePath, err := getProjectConfigPathOrThrow(project.Nuget, "nuget", "nuget-config")
if err != nil {
return err
}

if !exists {
return fmt.Errorf("no config file was found! Before running the nuget command on a project for the first time, the project should be configured using the nuget-config command")
}

rtDetails, targetRepo, useNugetV2, err := getNugetAndDotnetConfigFields(configFilePath)
if err != nil {
return err
Expand Down Expand Up @@ -584,13 +587,10 @@ func DotnetCmd(c *cli.Context) error {
}

// Get configuration file path.
configFilePath, exists, err := project.GetProjectConfFilePath(project.Dotnet)
configFilePath, err := getProjectConfigPathOrThrow(project.Dotnet, "dotnet", "dotnet-config")
if err != nil {
return err
}
if !exists {
return fmt.Errorf("no config file was found! Before running the dotnet command on a project for the first time, the project should be configured using the dotnet-config command")
}

rtDetails, targetRepo, useNugetV2, err := getNugetAndDotnetConfigFields(configFilePath)
if err != nil {
Expand Down Expand Up @@ -690,14 +690,12 @@ func goCmdVerification(c *cli.Context) (string, error) {
if c.NArg() < 1 {
return "", cliutils.WrongNumberOfArgumentsHandler(c)
}
configFilePath, exists, err := project.GetProjectConfFilePath(project.Go)

configFilePath, err := getProjectConfigPathOrThrow(project.Go, "go", "go-config")
if err != nil {
return "", err
}
// Verify config file is found.
if !exists {
return "", fmt.Errorf("no config file was found! Before running the go command on a project for the first time, the project should be configured using the go-config command")
}

log.Debug("Go config file was found in:", configFilePath)
return configFilePath, nil
}
Expand Down Expand Up @@ -887,13 +885,9 @@ func NpmPublishCmd(c *cli.Context) (err error) {
}

func GetNpmConfigAndArgs(c *cli.Context) (configFilePath string, args []string, err error) {
configFilePath, exists, err := project.GetProjectConfFilePath(project.Npm)
configFilePath, err = getProjectConfigPathOrThrow(project.Npm, "npm", "npm-config")
if err != nil {
return "", nil, err
}

if !exists {
return "", nil, errorutils.CheckErrorf("no config file was found! Before running the npm command on a project for the first time, the project should be configured using the npm-config command")
return
}
_, args = getCommandName(c.Args())
return
Expand Down Expand Up @@ -970,13 +964,9 @@ func terraformCmd(c *cli.Context) error {
}

func getTerraformConfigAndArgs(c *cli.Context) (configFilePath string, args []string, err error) {
configFilePath, exists, err := project.GetProjectConfFilePath(project.Terraform)
configFilePath, err = getProjectConfigPathOrThrow(project.Terraform, "terraform", "terraform-config")
if err != nil {
return "", nil, err
}

if !exists {
return "", nil, errors.New("no config file was found! Before running the terraform command on a project for the first time, the project should be configured using the terraform-config command")
return
}
args = cliutils.ExtractCommand(c)
return
Expand All @@ -992,3 +982,63 @@ func terraformPublishCmd(configFilePath string, args []string, c *cli.Context) e
result := terraformCmd.Result()
return cliutils.PrintBriefSummaryReport(result.SuccessCount(), result.FailCount(), cliutils.IsFailNoOp(c), err)
}

func getProjectConfigPathOrThrow(projectType project.ProjectType, cmdName, configCmdName string) (configFilePath string, err error) {
configFilePath, exists, err := project.GetProjectConfFilePath(projectType)
if err != nil {
return
}
if !exists {
return "", errorutils.CheckErrorf(getMissingConfigErrMsg(cmdName, configCmdName))
}
return
}

func getMissingConfigErrMsg(cmdName, configCmdName string) string {
return fmt.Sprintf("no config file was found! Before running the 'jf %s' command on a project for the first time, the project should be configured with the 'jf %s' command", cmdName, configCmdName)
}

func twineCmd(c *cli.Context) error {
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
return err
}
serverDetails, targetRepo, err := getTwineConfigAndArgs()
if err != nil {
return err
}
cmdName, filteredArgs := getCommandName(cliutils.ExtractCommand(c))
return python.NewTwineCommand(cmdName).SetServerDetails(serverDetails).SetTargetRepo(targetRepo).SetArgs(filteredArgs).Run()
}

func getTwineConfigAndArgs() (serverDetails *coreConfig.ServerDetails, targetRepo string, err error) {
configFilePath, err := getTwineConfigPath()
if err != nil {
return
}

vConfig, err := project.ReadConfigFile(configFilePath, project.YAML)
if err != nil {
return nil, "", fmt.Errorf("failed while reading configuration file '%s'. Error: %s", configFilePath, err.Error())
}
projectConfig, err := project.GetRepoConfigByPrefix(configFilePath, project.ProjectConfigDeployerPrefix, vConfig)
if err != nil {
return nil, "", err
}
serverDetails, err = projectConfig.ServerDetails()
if err != nil {
return nil, "", err
}
targetRepo = projectConfig.TargetRepo()
return
}

func getTwineConfigPath() (configFilePath string, err error) {
var exists bool
for _, projectType := range []project.ProjectType{project.Pip, project.Pipenv} {
configFilePath, exists, err = project.GetProjectConfFilePath(projectType)
if err != nil || exists {
return
}
}
return "", errorutils.CheckErrorf(getMissingConfigErrMsg("twine", "pip-config OR pipenv-config"))
}
12 changes: 12 additions & 0 deletions docs/artifactory/twine/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package twinedocs

var Usage = []string{"twine <twine arguments> [command options]"}

func GetDescription() string {
return "Runs twine "
}

func GetArguments() string {
return ` twine commands
Arguments and options for the twine command.`
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/testcontainers/testcontainers-go v0.33.0
github.com/urfave/cli v1.22.15
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -156,7 +156,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
Expand All @@ -170,12 +170,12 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240909132328-33f3a1ec52c1
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20240918080841-438d95167529

// replace github.com/jfrog/jfrog-cli-security => github.com/attiasas/jfrog-cli-security v0.0.0-20240904061406-f368939ce3a0

// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240806162439-01bb7dcd43fc

// replace github.com/jfrog/build-info-go => github.com/asafambar/build-info-go v1.8.9-0.20240819133117-c3f52700927d
replace github.com/jfrog/build-info-go => github.com/RobiNino/build-info-go v1.0.1-0.20240918080333-a131da7e4042

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog dev
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78=
github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/RobiNino/build-info-go v1.0.1-0.20240918080333-a131da7e4042 h1:MmSPq3dv6S22M2hiNOigzYab+AZnHQlYOIRpm61p0QQ=
github.com/RobiNino/build-info-go v1.0.1-0.20240918080333-a131da7e4042/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20240918080841-438d95167529 h1:KY8m/cZKiRxjN1sCSLwTJ1PFQCF//jThzT/s8mpB310=
github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20240918080841-438d95167529/go.mod h1:BslxzCW/niTFExBn4ynRtn3Hz1zs1Gk1jPLQtp1hQCU=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
Expand Down Expand Up @@ -931,8 +935,6 @@ github.com/jedib0t/go-pretty/v6 v6.5.9 h1:ACteMBRrrmm1gMsXe9PSTOClQ63IXDUt03H5U+
github.com/jedib0t/go-pretty/v6 v6.5.9/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
github.com/jfrog/build-info-go v1.9.36 h1:bKoYW3o+U70Zbz2kt5NT84N5JWNxdDXHOf+kVdzK+j4=
github.com/jfrog/build-info-go v1.9.36/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
github.com/jfrog/froggit-go v1.16.1 h1:FBIM1qevX/ag9unfmpGzfmZ36D8ulOJ+DPTSFUk3l5U=
github.com/jfrog/froggit-go v1.16.1/go.mod h1:TEJSzgiV+3D/GVGE8Y6j46ut1jrBLD1FL6WdMdKwwCE=
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
Expand All @@ -941,8 +943,6 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
github.com/jfrog/jfrog-cli-artifactory v0.1.6 h1:bMfJsrLQJw0dZp4nqUf1xOmtY0rpCatW/I5q88x+fhQ=
github.com/jfrog/jfrog-cli-artifactory v0.1.6/go.mod h1:jbNb22ebtupcjdhrdGq0VBew2vWG6VUK04xxGNDfynE=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240909132328-33f3a1ec52c1 h1:+eqMs31Ms+O9nm4gondTNIj3scd69Kmag6zzuF1Bi3k=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240909132328-33f3a1ec52c1/go.mod h1:24P424ysZzA0kVw/xESKELRJ+rFybRVf5zJiH18p72k=
github.com/jfrog/jfrog-cli-platform-services v1.3.0 h1:IblSDZFBjL7WLRi37Ni2DmHrXJJ6ysSMxx7t41AvyDA=
github.com/jfrog/jfrog-cli-platform-services v1.3.0/go.mod h1:Ky4SDXuMeaiNP/5zMT1YSzIuXG+cNYYOl8BaEA7Awbc=
github.com/jfrog/jfrog-cli-security v1.8.0 h1:jp/AVaQcItUNXRCud5PMyl8VVjPuzfrNHJWQvWAMnms=
Expand Down Expand Up @@ -1249,8 +1249,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk=
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand Down Expand Up @@ -1356,8 +1356,8 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1608,8 +1608,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
Loading
Loading