Skip to content

Commit 8a49dd1

Browse files
authored
Merge pull request #6 from concourse/version-from-file
Emit version from file
2 parents 007fd20 + 194576c commit 8a49dd1

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,5 @@ Since the mock resource is included as a base resource type, it can be used as t
7373
* `version`: Version to create.
7474

7575
* `print_env`: Print all environment variables to stdout when set to true. Default false.
76+
77+
* `file`: Contents will be read from the file and emitted as the version

cmd/out/main.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949
logrus.Info(req.Source.Log)
5050
}
5151

52-
if req.Params.Version == "" {
52+
if req.Params.Version == "" && req.Params.File == "" {
5353
logrus.Fatal("no version specified")
5454
return
5555
}
@@ -60,8 +60,20 @@ func main() {
6060
return
6161
}
6262

63-
version := resource.Version{
64-
Version: req.Params.Version,
63+
var version resource.Version
64+
if req.Params.Version == "" {
65+
contents, err := os.ReadFile(req.Params.File)
66+
if err != nil {
67+
logrus.Fatalf("error reading version from file %s: %s", req.Params.File, err)
68+
return
69+
}
70+
version = resource.Version{
71+
Version: string(contents),
72+
}
73+
} else {
74+
version = resource.Version{
75+
Version: req.Params.Version,
76+
}
6577
}
6678

6779
if privileged {

types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ type PutParams struct {
7474

7575
// print all env vars to stdout
7676
PrintEnv bool `json:"print_env"`
77+
78+
// file whose contents will be the version
79+
File string `json:"file"`
7780
}
7881

7982
type MetadataField struct {

0 commit comments

Comments
 (0)