cuelang.org/go@v0.10.1/internal/ci/goreleaser/goreleaser_tool.cue (about)

     1  package goreleaser
     2  
     3  import (
     4  	"encoding/yaml"
     5  	"path"
     6  	"strings"
     7  
     8  	"tool/file"
     9  	"tool/exec"
    10  	"tool/os"
    11  	"tool/cli"
    12  
    13  	"cuelang.org/go/internal/ci/repo"
    14  )
    15  
    16  command: release: {
    17  	env: os.Environ
    18  
    19  	let _env = env
    20  
    21  	let _githubRef = env.GITHUB_REF | "refs/no_ref_kind/not_a_release" // filled when running in CI
    22  	let _githubRefName = path.Base(_githubRef)
    23  
    24  	tempDir: file.MkdirTemp & {
    25  		path: string
    26  	}
    27  
    28  	goMod: file.Create & {
    29  		contents: "module mod.test"
    30  		filename: path.Join([tempDir.path, "go.mod"])
    31  	}
    32  
    33  	latestCUE: exec.Run & {
    34  		env: {
    35  			_env
    36  
    37  			GOPROXY: "direct" // skip proxy.golang.org in case its @latest is lagging behind
    38  		}
    39  		$after: goMod
    40  		dir:    tempDir.path
    41  		cmd: ["go", "list", "-m", "-f", "{{.Version}}", "cuelang.org/go@latest"]
    42  		stdout: string
    43  	}
    44  
    45  	let latestCUEVersion = strings.TrimSpace(latestCUE.stdout)
    46  
    47  	tidyUp: file.RemoveAll & {
    48  		$after: latestCUE
    49  		path:   tempDir.path
    50  	}
    51  
    52  	cueModRoot: exec.Run & {
    53  		cmd: ["go", "list", "-m", "-f", "{{.Dir}}", "cuelang.org/go"]
    54  		stdout: string
    55  	}
    56  
    57  	let goreleaserCmd = [
    58  		"goreleaser", "release", "-f", "-", "--clean",
    59  
    60  		// Only run the full release when running on GitHub actions for a release tag.
    61  		// Keep in sync with repo.releaseTagPattern, which is a globbing pattern
    62  		// rather than a regular expression.
    63  		//
    64  		// TODO: Once there is a "goreleaser test" command,
    65  		// switch to that instead of our workaround via "goreleaser release --snapshot".
    66  		// See: https://github.com/goreleaser/goreleaser/issues/2355
    67  		if _githubRef !~ "refs/tags/\(repo.releaseTagPrefix).*" {
    68  			"--snapshot"
    69  		},
    70  	]
    71  	let goreleaserConfigYAML = yaml.Marshal(config & {
    72  		#latest: _githubRefName == strings.TrimSpace(latestCUE.stdout)
    73  	})
    74  
    75  	info: cli.Print & {
    76  		text: """
    77  			latest CUE version: \(latestCUEVersion)
    78  			git ref: \(_githubRef)
    79  			release name: \(_githubRefName)
    80  			goreleaser cmd: \(strings.Join(goreleaserCmd, " "))
    81  
    82  			goreleaser config yaml, indented for readability:
    83  			  \(strings.Replace(goreleaserConfigYAML, "\n", "\n  ", -1))
    84  			"""
    85  	}
    86  
    87  	goreleaser: exec.Run & {
    88  		$after: info
    89  
    90  		// Set the goreleaser configuration to be stdin
    91  		stdin: goreleaserConfigYAML
    92  
    93  		// Run at the root of the module
    94  		dir: strings.TrimSpace(cueModRoot.stdout)
    95  
    96  		cmd: goreleaserCmd
    97  	}
    98  }