Skip to content

Commit cc630ab

Browse files
authored
Merge pull request #251 from opendevstack/fix/vulnerability
update to go 1.21 to fix CVE-2023-44487
2 parents cab064e + fccb07f commit cc630ab

File tree

18 files changed

+147
-62
lines changed

18 files changed

+147
-62
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,32 @@ jobs:
77
steps:
88
-
99
name: Checkout repository
10-
uses: actions/checkout@v2
10+
uses: actions/checkout@v4
1111
with:
1212
fetch-depth: 0
1313
-
1414
name: Setup Go
15-
uses: actions/setup-go@v2
15+
uses: actions/setup-go@v4
1616
with:
17-
version: 1.14
17+
go-version: 1.21
1818
-
1919
name: Download Go tools
2020
run: |
21-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.25.0
22-
go get golang.org/x/tools/cmd/goimports
21+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.2
22+
go install golang.org/x/tools/cmd/goimports@latest
23+
echo "PATH=$PATH:$(go env GOPATH)/bin" >> $GITHUB_ENV
2324
-
2425
name: Run lint
2526
run: |
26-
export PATH=$PATH:$(go env GOPATH)/bin
2727
make lint
2828
-
29-
name: Setup OpenShift
30-
uses: manusa/actions-setup-openshift@v1.1.2
31-
with:
32-
oc version: 'v3.11.0'
33-
enable: 'centos-imagestreams,persistent-volumes,registry,router'
34-
github token: ${{ secrets.GITHUB_TOKEN }}
35-
-
36-
name: Run tests
29+
name: Download OpenShift client
3730
run: |
38-
export PATH=$PATH:$(go env GOPATH)/bin
39-
sudo chown -R runner:docker openshift.local.clusterup/
40-
make test
31+
mkdir -p ~/oc
32+
cd ~/oc
33+
curl -L https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux.tar.gz -o oc.tar.gz
34+
tar -xzf oc.tar.gz
35+
echo "$HOME/oc" >> $GITHUB_PATH
36+
-
37+
name: Run Unit tests (cannot run openshift tests due to requiring Github runner with ubuntu 20.04)
38+
run: make test-unit

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout repository
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
1717
with:
1818
# We must fetch at least the immediate parents so that if this is
1919
# a pull request then we can checkout the head.
@@ -26,15 +26,15 @@ jobs:
2626

2727
# Initializes the CodeQL tools for scanning.
2828
- name: Initialize CodeQL
29-
uses: github/codeql-action/init@v1
29+
uses: github/codeql-action/init@v4
3030
# Override language selection by uncommenting this and choosing your languages
3131
# with:
3232
# languages: go, javascript, csharp, python, cpp, java
3333

3434
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
3535
# If this step fails, then you should remove it and run the build manually (see below)
3636
- name: Autobuild
37-
uses: github/codeql-action/autobuild@v1
37+
uses: github/codeql-action/autobuild@v4
3838

3939
# ℹ️ Command-line programs to run using the OS shell.
4040
# 📚 https://git.io/JvXDl
@@ -48,4 +48,4 @@ jobs:
4848
# make release
4949

5050
- name: Perform CodeQL Analysis
51-
uses: github/codeql-action/analyze@v1
51+
uses: github/codeql-action/analyze@v4

.github/workflows/release.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
build:
12+
name: Build and Upload Artifacts
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup Go
21+
uses: actions/setup-go@v4
22+
with:
23+
go-version: 1.21
24+
25+
- name: Download Go tools
26+
run: |
27+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.2
28+
go install golang.org/x/tools/cmd/goimports@latest
29+
echo "PATH=$PATH:$(go env GOPATH)/bin" >> $GITHUB_ENV
30+
31+
- name: Run lint
32+
run: make lint
33+
34+
-
35+
name: Download OpenShift client
36+
run: |
37+
mkdir -p ~/oc
38+
cd ~/oc
39+
curl -L https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux.tar.gz -o oc.tar.gz
40+
tar -xzf oc.tar.gz
41+
echo "$HOME/oc" >> $GITHUB_PATH
42+
43+
- name: Run unit tests
44+
run: make test-unit
45+
46+
- name: Extract version from tag
47+
id: version
48+
run: |
49+
TAG=${{ github.event.release.tag_name }}
50+
VERSION=${TAG#v}
51+
echo "version=$VERSION" >> $GITHUB_OUTPUT
52+
53+
- name: Build binaries
54+
run: make build VERSION=${{ steps.version.outputs.version }}
55+
56+
- name: Upload Linux binary
57+
uses: actions/upload-release-asset@v1
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
with:
61+
upload_url: ${{ github.event.release.upload_url }}
62+
asset_path: ./cmd/tailor/tailor-linux-amd64
63+
asset_name: tailor-linux-amd64
64+
asset_content_type: application/octet-stream
65+
66+
- name: Upload macOS binary
67+
uses: actions/upload-release-asset@v1
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
with:
71+
upload_url: ${{ github.event.release.upload_url }}
72+
asset_path: ./cmd/tailor/tailor-darwin-amd64
73+
asset_name: tailor-darwin-amd64
74+
asset_content_type: application/octet-stream
75+
76+
- name: Upload Windows binary
77+
uses: actions/upload-release-asset@v1
78+
env:
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
with:
81+
upload_url: ${{ github.event.release.upload_url }}
82+
asset_path: ./cmd/tailor/tailor-windows-amd64.exe
83+
asset_name: tailor-windows-amd64.exe
84+
asset_content_type: application/octet-stream

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ build: imports build-linux build-darwin build-windows
4444

4545
## Build Linux binary.
4646
build-linux: imports
47-
cd cmd/tailor && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -o tailor-linux-amd64
47+
cd cmd/tailor && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -ldflags "-X main.Version=$(VERSION)" -o tailor-linux-amd64
4848
.PHONY: build-linux
4949

5050
## Build macOS binary.
5151
build-darwin: imports
52-
cd cmd/tailor && GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -o tailor-darwin-amd64
52+
cd cmd/tailor && GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -ldflags "-X main.Version=$(VERSION)" -o tailor-darwin-amd64
5353
.PHONY: build-darwin
5454

5555
## Build Windows binary.
5656
build-windows: imports
57-
cd cmd/tailor && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -o tailor-windows-amd64.exe
57+
cd cmd/tailor && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -ldflags "-X main.Version=$(VERSION)" -o tailor-windows-amd64.exe
5858
.PHONY: build-windows
5959

6060
internal/test/e2e/tailor-test: cmd/tailor/main.go go.mod go.sum pkg/cli/* pkg/commands/* pkg/openshift/* pkg/utils/*

cmd/tailor/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import (
1111
"github.com/opendevstack/tailor/pkg/commands"
1212
)
1313

14+
// Version will be set during build time using ldflags to the current version from git tags (already prepared in the Makefile).
15+
// For example: make build VERSION=1.0.0
16+
// If the version cannot be determined (e.g. when building from source manually and no version is specified), it will default to "dev".
17+
var Version = "dev"
18+
1419
var (
1520
app = kingpin.New(
1621
"tailor",
@@ -253,7 +258,7 @@ func main() {
253258
command := kingpin.MustParse(app.Parse(os.Args[1:]))
254259

255260
if command == versionCommand.FullCommand() {
256-
fmt.Println("1.3.4+master")
261+
fmt.Println(Version)
257262
return
258263
}
259264

go.mod

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ module github.com/opendevstack/tailor
22

33
require (
44
github.com/alecthomas/kingpin v2.2.6+incompatible
5-
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
6-
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
75
github.com/fatih/color v1.7.0
86
github.com/ghodss/yaml v1.0.0
97
github.com/google/go-cmp v0.3.1
10-
github.com/mattn/go-colorable v0.0.9 // indirect
11-
github.com/mattn/go-isatty v0.0.3 // indirect
128
github.com/pmezard/go-difflib v1.0.0
13-
github.com/stretchr/testify v1.3.0 // indirect
149
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f
1510
golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac
1611
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
12+
)
13+
14+
require (
15+
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
16+
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
17+
github.com/mattn/go-colorable v0.0.9 // indirect
18+
github.com/mattn/go-isatty v0.0.3 // indirect
19+
github.com/stretchr/testify v1.3.0 // indirect
1720
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 // indirect
1821
gopkg.in/yaml.v2 v2.2.1 // indirect
1922
)
2023

21-
go 1.14
24+
go 1.21

internal/test/e2e/e2e_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
87
"os"
98
"os/exec"
109
"strings"
@@ -79,11 +78,11 @@ func exportInitialState(t *testing.T, testProjectName string, tailorBinary strin
7978
if exportErr != nil {
8079
t.Fatalf("Could not export initial state: %s\n%s", exportErr, exportStderr)
8180
}
82-
tempDir, tempDirErr := ioutil.TempDir("..", "initial-export-")
81+
tempDir, tempDirErr := os.MkdirTemp("..", "initial-export-")
8382
if tempDirErr != nil {
8483
t.Fatalf("Could not create temp dir: %s", tempDirErr)
8584
}
86-
writeErr := ioutil.WriteFile(tempDir+"/template.yml", exportStdout, 0644)
85+
writeErr := os.WriteFile(tempDir+"/template.yml", exportStdout, 0644)
8786
if writeErr != nil {
8887
t.Logf("Failed to write file template.yml into %s", tempDir)
8988
os.RemoveAll(tempDir)
@@ -93,7 +92,7 @@ func exportInitialState(t *testing.T, testProjectName string, tailorBinary strin
9392
}
9493

9594
func walkSubdirs(t *testing.T, dir string, fun func(subdir string)) {
96-
files, err := ioutil.ReadDir(dir)
95+
files, err := os.ReadDir(dir)
9796
if err != nil {
9897
t.Fatal(err)
9998
}
@@ -262,7 +261,7 @@ func runCmd(executable string, args []string) (outBytes, errBytes []byte, err er
262261
}
263262

264263
func readTestCaseSteps(folder string) (testCaseSteps, error) {
265-
content, err := ioutil.ReadFile(folder + "/steps.json")
264+
content, err := os.ReadFile(folder + "/steps.json")
266265
if err != nil {
267266
return nil, fmt.Errorf("Cannot read file: %w", err)
268267
}

internal/test/helper/file.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package helper
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"path"
87
"runtime"
@@ -48,5 +47,5 @@ func readFile(name string) ([]byte, error) {
4847
return []byte{}, fmt.Errorf("Could not get filename when looking for %s", name)
4948
}
5049
filepath := path.Join(path.Dir(filename), name)
51-
return ioutil.ReadFile(filepath)
50+
return os.ReadFile(filepath)
5251
}

pkg/cli/cli.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"log"
109
"os"
1110
"os/exec"
@@ -136,7 +135,7 @@ func AskForAction(question string, options []string, reader *bufio.Reader) strin
136135

137136
// EditEnvFile opens content in EDITOR, and returns saved content.
138137
func EditEnvFile(content string) (string, error) {
139-
err := ioutil.WriteFile(".ENV.DEC", []byte(content), 0644)
138+
err := os.WriteFile(".ENV.DEC", []byte(content), 0644)
140139
if err != nil {
141140
return "", err
142141
}
@@ -160,7 +159,7 @@ func EditEnvFile(content string) (string, error) {
160159
if err != nil {
161160
return "", err
162161
}
163-
data, err := ioutil.ReadFile(".ENV.DEC")
162+
data, err := os.ReadFile(".ENV.DEC")
164163
if err != nil {
165164
return "", err
166165
}

pkg/cli/options.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cli
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"os/exec"
98
"strings"
@@ -619,7 +618,7 @@ func getFileFlags(filename string, verbose bool) (map[string]string, error) {
619618
return fileFlags, err
620619
}
621620

622-
b, err := ioutil.ReadFile(filename)
621+
b, err := os.ReadFile(filename)
623622
if err != nil {
624623
return fileFlags, err
625624
}

0 commit comments

Comments
 (0)