This repository has been archived by the owner on Feb 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ci_dump_revision.go
67 lines (50 loc) · 1.57 KB
/
ci_dump_revision.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright © 2016-present Thomas Rabaix <[email protected]>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package commands
import (
"flag"
"os"
"strings"
"github.com/mitchellh/cli"
helper "github.com/rande/gitlab-ci-helper"
)
type CiDumpRevisionCommand struct {
Ui cli.Ui
Verbose bool
RevisionFile string
Reference string
}
func (c *CiDumpRevisionCommand) Run(args []string) int {
cmdFlags := flag.NewFlagSet("ci:revision", flag.ContinueOnError)
cmdFlags.Usage = func() {
c.Ui.Output(c.Help())
}
cmdFlags.BoolVar(&c.Verbose, "verbose", false, "")
cmdFlags.StringVar(&c.RevisionFile, "file", "REVISION", "The revision file")
cmdFlags.StringVar(&c.Reference, "ref", helper.GetEnv("CI_COMMIT_SHA", os.Getenv("CI_BUILD_REF")), "The sha1 (default: env var CI_BUILD_REF)")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
fp, _ := os.Create(c.RevisionFile)
defer fp.Close()
fp.Write([]byte(c.Reference))
return 0
}
func (c *CiDumpRevisionCommand) Synopsis() string {
return "Dump a REVISION with the current sha1."
}
func (c *CiDumpRevisionCommand) Help() string {
helpText := `
Usage: gitlab-ci-helper ci:revision [options]
Dump a REVISION file with the current sha1
Options:
-file Target file (default: REVISION)
-ref The sha1 (default: env var CI_BUILD_REF)
-verbose Add verbose information to the output
Env Variables:
CI_BUILD_REF Get the revision from this variable
`
return strings.TrimSpace(helpText)
}