mirror of
https://github.com/RustyRaptor/deploy-sourcegraph-docker.git
synced 2026-12-03 15:55:17 -07:00
add verify-release to docker deployments (#363)
This commit is contained in:
1 parent
3f0b901d7a
commit
9eeff73741
6 files changed
+183
No files matched your search
@@ -11,6 +11,8 @@ steps:
|
||||
command: .buildkite/prettier-check.sh
|
||||
agents:
|
||||
queue: 'baremetal'
|
||||
- label: ":git: :sleuth_or_spy:"
|
||||
command: .buildkite/verify-release/verify-release.sh
|
||||
- label: ':rice: pure-docker-test'
|
||||
command: .buildkite/vagrant-run.sh docker-test
|
||||
artifact_paths: ./*.log
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
module verify-release
|
||||
|
||||
go 1.16
|
||||
|
||||
require golang.org/x/mod v0.4.2
|
||||
@@ -0,0 +1,13 @@
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
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=
|
||||
Executable
+152
@@ -0,0 +1,152 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
|
||||
var verbose bool
|
||||
|
||||
func main() {
|
||||
flag.BoolVar(&verbose, "verbose", false, "print all paths visited")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
branch, err := getBranch()
|
||||
if err != nil {
|
||||
log.Fatalf("when getting branch %s", err)
|
||||
}
|
||||
|
||||
if !isReleaseBranch(branch) {
|
||||
fmt.Fprintf(os.Stderr, "branch %q is not a release branch\n", branch)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
paths := flag.Args()
|
||||
err = validate(paths)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func validate(paths []string) error {
|
||||
|
||||
var validationErrors []validationError
|
||||
for _, p := range paths {
|
||||
err := filepath.WalkDir(p, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("when walking over %q: %s", path, err)
|
||||
}
|
||||
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
ext := filepath.Ext(path)
|
||||
if !(ext == ".yaml" || ext == ".yml" || ext == ".sh") {
|
||||
return nil
|
||||
}
|
||||
if verbose {
|
||||
log.Println(path)
|
||||
}
|
||||
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("when reading %q: %w", path, err)
|
||||
}
|
||||
|
||||
contents := string(b)
|
||||
|
||||
for _, tag := range []string{"insiders", "latest"} {
|
||||
if strings.Contains(contents, fmt.Sprintf(":%s", tag)) {
|
||||
validationErrors = append(validationErrors, validationError{path, tag})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(validationErrors) > 0 {
|
||||
message := "FILES WITH INVALID TAGS:"
|
||||
|
||||
for _, e := range validationErrors {
|
||||
message = fmt.Sprintf("%s\n%s", message, e.Error())
|
||||
}
|
||||
|
||||
return fmt.Errorf(message)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type validationError struct {
|
||||
path string
|
||||
tag string
|
||||
}
|
||||
|
||||
func (e *validationError) Error() string {
|
||||
return fmt.Sprintf("%s: %q", e.path, e.tag)
|
||||
}
|
||||
|
||||
func isReleaseBranch(branch string) bool {
|
||||
if verbose {
|
||||
log.Printf("branch = %q", branch)
|
||||
}
|
||||
|
||||
version := strings.TrimPrefix(branch, "publish-")
|
||||
|
||||
if !strings.HasPrefix(version, "v") {
|
||||
version = fmt.Sprintf("v%s", version)
|
||||
}
|
||||
|
||||
return semver.IsValid(version)
|
||||
}
|
||||
|
||||
func getBranch() (string, error) {
|
||||
// tag, branch, git else fail
|
||||
tag := os.Getenv("BUILDKITE_TAG")
|
||||
if tag != "" {
|
||||
return tag, nil
|
||||
}
|
||||
|
||||
branch := os.Getenv("BUILDKITE_BRANCH")
|
||||
if branch != "" {
|
||||
return branch, nil
|
||||
}
|
||||
|
||||
branch, err := branchFromGit()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("when running git: %w", err)
|
||||
}
|
||||
|
||||
if branch != "" {
|
||||
return branch, nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("unable to determine branch")
|
||||
|
||||
}
|
||||
|
||||
func branchFromGit() (string, error) {
|
||||
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
branch := string(out)
|
||||
return strings.TrimSpace(branch), nil
|
||||
}
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/../.."
|
||||
set -euxo pipefail
|
||||
|
||||
ROOT="$(pwd)"
|
||||
cd .buildkite/verify-release
|
||||
|
||||
echo "--- Check to see if semver tag are set in release branch"
|
||||
go run verify-release.go -verbose=true "${ROOT}"
|
||||
@@ -1,3 +1,4 @@
|
||||
yarn 1.19.2
|
||||
shellcheck 0.7.1
|
||||
nodejs 13.12.0
|
||||
go 1.16
|
||||
Reference in new issue
Block a user