Skip to content

Commit 94fa0f7

Browse files
Merge pull request #64 from datawire/rlane/update-go-version
Update to Go 1.22
2 parents ec921e4 + 0641302 commit 94fa0f7

File tree

13 files changed

+80
-1250
lines changed

13 files changed

+80
-1250
lines changed

.dockerignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ DEPENDENCY_LICENSES.md
77
.git
88
.github
99
actions
10-
tools

.github/workflows/qa.yml

+12-11
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,38 @@ jobs:
1111
- macos-latest
1212
#- windows-latest
1313
go_version:
14-
- '1.18.0'
15-
- '1.19.0'
16-
- '1.20.0'
1714
- '1.21.0'
15+
- '1.22.0'
1816
steps:
19-
- uses: actions/checkout@v3
20-
- uses: actions/setup-go@v3
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-go@v5
2119
with:
2220
go-version: '~${{ matrix.go_version }}'
2321
cache: true
2422
- run: |
2523
if [[ "${{runner.debug}}" == "1" ]]; then
2624
DEBUG_FLAGS="-v"
2725
fi
28-
26+
2927
go test -race ${DEBUG_FLAGS} ./...
3028
lint:
3129
runs-on: ubuntu-latest
3230
steps:
33-
- uses: actions/checkout@v3
34-
- uses: actions/setup-go@v3
31+
- uses: actions/checkout@v4
32+
- uses: actions/setup-go@v5
3533
with:
3634
# Specify the most recent (1.Y.Z) Y release
3735
go-version-file: go.mod
3836
cache: true
39-
- run: make lint
37+
- uses: golangci/golangci-lint-action@v5
38+
with:
39+
version: latest
40+
args: --timeout=10m
4041
generate:
4142
runs-on: ubuntu-latest
4243
steps:
43-
- uses: actions/checkout@v3
44-
- uses: actions/setup-go@v3
44+
- uses: actions/checkout@v4
45+
- uses: actions/setup-go@v5
4546
with:
4647
go-version-file: go.mod
4748
cache: true

.github/workflows/test-action.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ jobs:
1212
name: "Generate dependency information"
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 0
1818

1919
- name: Setup Go environment
20-
uses: actions/setup-go@v3
20+
uses: actions/setup-go@v5
2121
with:
2222
go-version-file: go.mod
2323
cache: true
@@ -37,14 +37,14 @@ jobs:
3737
: > DEPENDENCY_LICENSES.md
3838
: > DEPENDENCIES.md
3939
git add DEPENDENCY_LICENSES.md DEPENDENCIES.md
40-
40+
4141
# Generate license information
4242
export GO_IMAGE=$(grep -e 'FROM golang:' "build-aux/docker/go_builder.dockerfile" | cut -d ' ' -f2 )
4343
4444
#Copy test data to another folder since it can't be used from there
4545
cp -a ./test-data ./ui
4646
export NPM_PACKAGES=$( echo -e "./ui/package.json\n./ui/package-lock.json" )
47-
47+
4848
mkdir -p "${BUILD_TMP}"
4949
build-aux/generate.sh --unparsable-packages ./unparsable-packages.yaml
5050
@@ -58,7 +58,7 @@ jobs:
5858
- name: "Check that action didn't do any changes"
5959
run: |
6060
if [[ "${{ steps.changed-by-dependabot.outputs.is_dirty }}" == 'true' ]]; then
61-
echo "::error:: Action indicates that the repo was dirty"
61+
echo "::error:: Action indicates that the repo was dirty"
6262
exit 1
6363
fi
6464
@@ -74,18 +74,18 @@ jobs:
7474
if: github.ref_type == 'branch'
7575
run: |
7676
if [[ "${{ steps.changed-by-dependabot2.outputs.license_information_committed }}" != 'true' ]]; then
77-
echo "::error:: Action indicates that the repo was not dirty"
77+
echo "::error:: Action indicates that the repo was not dirty"
7878
exit 1
7979
fi
8080
8181
DESTINATION_BRANCH="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}"
8282
DIFF=$(git diff --stat --cached origin/${DESTINATION_BRANCH})
8383
if [[ -z "${DIFF}" ]]; then
84-
echo "::error:: There weren't any files committed."
84+
echo "::error:: There weren't any files committed."
8585
exit 1
8686
fi
8787
8888
if ! grep -e '^\s*DEPENDENCY_LICENSES.md' <(echo "${DIFF}") > /dev/null; then
89-
echo "::error:: File DEPENDENCY_LICENSES.md was not modified, but it should have been."
89+
echo "::error:: File DEPENDENCY_LICENSES.md was not modified, but it should have been."
9090
exit 1
9191
fi

Makefile

-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ generate:
1313
go generate ./...
1414
.PHONY: generate
1515

16-
lint: tools/bin/golangci-lint
17-
tools/bin/golangci-lint run ./...
18-
.PHONY: lint
19-
20-
tools/bin/%: tools/src/%/pin.go tools/src/%/go.mod
21-
cd $(<D) && GOOS= GOARCH= go build -o $(abspath $@) $$(sed -En 's,^import "(.*)".*,\1,p' pin.go)
22-
2316
.DELETE_ON_ERROR:
2417
.PHONY: FORCE
2518
FORCE:

README.md

+56-53
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
# go-mkopensource
2+
13
## Command line tool Docs
2-
* [go-mkopensource](/cmd/go-mkopensource/README.md)
3-
* [js-mkopensource](/cmd/js-mkopensource/README.md)
4+
5+
- [go-mkopensource](/cmd/go-mkopensource/README.md)
6+
- [js-mkopensource](/cmd/js-mkopensource/README.md)
47

58
## Building
69

@@ -18,87 +21,87 @@ package is good at detecting the licenses in a file
1821
## Design
1922

2023
There are many existing packages to do license detection, such as
21-
[go-license-detector][] or GitHub's [licensee][]. The reason these
24+
[go-license-detector][] or GitHub's [licensee][]. The reason these
2225
are not used is that they are meant to be _informative_, they provide
2326
"best effort" identification of the license.
2427

25-
`go-mkopensource` isn't meant to just be _informative_, it is meant to
26-
be used for _compliance_, if it has any reason at all to be even a
28+
`go-mkopensource` isn't meant to just be informative, it is meant to
29+
be used for compliance; if it has any reason at all to be even a
2730
little skeptical of a result, rather than returning its best guess, it
28-
blows up in your face, asking a human to verify the result.
31+
asks a human to verify the result.
2932

3033
[go-license-detector]: https://github.com/go-enry/go-license-detector
3134
[licensee]: https://github.com/licensee/licensee
3235

3336
## License scanning scripts
3437

35-
Folder `/build-aux` contains scripts to scan licenses for Go, Python
36-
and Node.Js. Script will generate both `DEPENDENCY_LICENSES.md` and
38+
Folder `/build-aux` contains scripts to scan licenses for Go, Python
39+
and Node.Js. Script will generate both `DEPENDENCY_LICENSES.md` and
3740
`DEPENDENCIES.md`
3841

39-
The following environment variables are used to configure the
42+
The following environment variables are used to configure the
4043
application behaviour.
4144

42-
* `APPLICATION`: Required. Name of the application being scanned.
45+
- `APPLICATION`: Required. Name of the application being scanned.
4346
It's used in the header of the license files.
4447

45-
* `APPLICATION_TYPE`: Required. Where will the application being
46-
scanned run.
47-
`internal` is used for anything running on Ambassador Labs servers,
48-
and `external` for anything that's deployed to customer machines.
48+
- `APPLICATION_TYPE`: Required. Where will the application being
49+
scanned run.
50+
`internal` is used for anything running on Ambassador Labs servers,
51+
and `external` for anything that's deployed to customer machines.
4952

50-
* `BUILD_HOME` Required. Location of the root folder of the repo to
53+
- `BUILD_HOME` Required. Location of the root folder of the repo to
5154
scan.
5255

53-
* `BUILD_TMP`: Required. Folder to use for storing temporary files.
56+
- `BUILD_TMP`: Required. Folder to use for storing temporary files.
5457

55-
* `GIT_TOKEN` Required. Git token with permissions to pull
58+
- `GIT_TOKEN` Required. Git token with permissions to pull
5659
repositories
5760

58-
* `GO_IMAGE` Required. Image to use for generating Go
61+
- `GO_IMAGE` Required. Image to use for generating Go
5962
dependencies.
6063

61-
* `PYTHON_PACKAGES`: Optional. List of requirement.txt files to scan.
62-
Paths should be relative to `BUILD_HOME`.
64+
- `PYTHON_PACKAGES`: Optional. List of requirement.txt files to scan.
65+
Paths should be relative to `BUILD_HOME`.
6366
Example:
6467

6568
`export PYTHON_PACKAGES="./python/requirements.txt ./builder/requirements.txt"`
6669

67-
* `PYTHON_IMAGE`: Required. Image to use for generating Python
70+
- `PYTHON_IMAGE`: Required. Image to use for generating Python
6871
dependencies.
6972

70-
* `NPM_PACKAGES`: Optional. List of package.json and package-lock.json
71-
files to scan. Paths should be relative to `BUILD_HOME`.
73+
- `NPM_PACKAGES`: Optional. List of package.json and package-lock.json
74+
files to scan. Paths should be relative to `BUILD_HOME`.
7275
Example:
7376

7477
`export NPM_PACKAGES="./tools/sandbox/grpc_web/package.json ./tools/sandbox/grpc_web/package-lock.json"`
7578

76-
* `EXCLUDED_PKG`: Optional. Semicolon separated list of npm packages names that we want to exclude for the validation.
77-
*Important*: it will restrict the output to the packages (package@version) from being reported in DEPENDENCIES.md and DEPENDENCY_LICENSES.md,
79+
- `EXCLUDED_PKG`: Optional. Semicolon separated list of npm packages names that we want to exclude for the validation.
80+
_Important_: it will restrict the output to the packages (package@version) from being reported in DEPENDENCIES.md and DEPENDENCY_LICENSES.md,
7881
before to use it, confirm if it is absolutely necessary.
79-
82+
8083
Example:
8184

8285
`export EXCLUDED_PKG="[email protected];internal-2"`
8386

84-
* `NODE_IMAGE`: Required when `NPM_PACKAGES` is defined. Version
87+
- `NODE_IMAGE`: Required when `NPM_PACKAGES` is defined. Version
8588
of Node.JS to use when running npm dependency scan. Only valid
86-
version numbers (X.Y.Z) are allowed.
89+
version numbers (X.Y.Z) are allowed.
8790
Example:
8891

8992
`NODE_IMAGE=node:14.13.1-alpine`
9093

91-
* `SCRIPTS_HOME`: Required. Location where `go-mkopensource` repo is
92-
checked out, relative to `BUILD_HOME`
94+
- `SCRIPTS_HOME`: Required. Location where `go-mkopensource` repo is
95+
checked out, relative to `BUILD_HOME`
9396

94-
To update license information files, set the environment variables
97+
To update license information files, set the environment variables
9598
described above and run `build-aux/generate.sh`
9699

97100
Tips:
98101

99-
* Add a .dockerignore at the root of your repository and exclude any files that are not necessary for generating depdency
100-
information, including DEPENDENCIES.md, DEPENDENCY_INFORMATION.md and temporary folders. See the
101-
[saas_app .dockerignore](https://github.com/datawire/saas_app/blob/master/.dockerignore) for a list of suggested exclussions.
102+
- Add a .dockerignore at the root of your repository and exclude any files that are not necessary for generating depdency
103+
information, including DEPENDENCIES.md, DEPENDENCY_INFORMATION.md and temporary folders. See the
104+
[saas_app .dockerignore](https://github.com/datawire/saas_app/blob/master/.dockerignore) for a list of suggested exclussions.
102105

103106
## When scanning fails
104107

@@ -124,7 +127,7 @@ fatal: 2 license-detection errors:
124127
```
125128

126129
A quick look at the package reveals that it uses an Apache License, but adds extra text at the top of the actual LICENSE
127-
file indicating that it also uses files from golang/encoding/json. We know that golang uses a 3-clause BSD license. So we consult the [SPDX License List](https://spdx.org/licenses/) to get the canonical
130+
file indicating that it also uses files from golang/encoding/json. We know that golang uses a 3-clause BSD license. So we consult the [SPDX License List](https://spdx.org/licenses/) to get the canonical
128131
identifiers for the licenses, and add them to an `unparsable-packages.yaml` file to our build system
129132
with the following contents:
130133

@@ -146,28 +149,29 @@ the list of all the packages in the file "vendor/modules.txt" using the command
146149
#26 18.24 go: downloading github.com/containerd/cgroups v0.0.0-20200531161412-0dbf7f05ba59
147150
#26 18.28 go: downloading github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
148151
#26 36.85 github.com/datawire/saas_app/internal/pkg/kubernetes imports
149-
#26 36.85 k8s.io/client-go/rest imports
150-
#26 36.85 k8s.io/apimachinery/pkg/util/clock: no required module provides package k8s.io/apimachinery/pkg/util/clock; to add it:
151-
#26 36.85 go get k8s.io/apimachinery/pkg/util/clock
152+
#26 36.85 k8s.io/client-go/rest imports
153+
#26 36.85 k8s.io/apimachinery/pkg/util/clock: no required module provides package k8s.io/apimachinery/pkg/util/clock; to add it:
154+
#26 36.85 go get k8s.io/apimachinery/pkg/util/clock
152155
#26 36.85 /scripts/go-mkopensource: fatal: ["go" "mod" "vendor"]: exit status 1
153156
#26 ERROR: executor failed running [/bin/sh -c /scripts/scan-go.sh]: exit code: 1
154157
```
155158

156-
Now the scanner is smart enough to follow the indications of the "go mod vendor" install the dependencies, and then
159+
Now the scanner will follow the indications of the "go mod vendor", install the dependencies, and then
157160
get the list of packages from the file ''vendor/modules.txt"
158161

159-
Sometimes it isn't possible to install the dependecies sugested by the "go mod vendor" command.
162+
Sometimes it isn't possible to install the dependencies suggested by the "go mod vendor" command.
160163
The scanner will complain with the message "Error installing dependency". In this case the project will require human intervention to solve the problem.
161164

162-
Another reason that may cause a failure is the use of our proprietary packages, like `github.com/datawire/telepresence-pro/rpc/proconnector`.
163-
The error will message will be similar to this one:
165+
Another reason that may cause a failure is the use of our proprietary packages, like `github.com/datawire/telepresence-pro/rpc/proconnector`.
166+
The error will message will be similar to this one:
164167

165168
```bash
166169
/scripts/go-mkopensource: fatal: 1 license-detection errors:
167170
1. Package "github.com/datawire/telepresence-pro/rpc/proconnector": could not identify a license for all sources (had no global LICENSE file)
168171
```
169172

170-
Fo exclude these packages, add a yaml file like this
173+
To exclude these packages, add a yaml file like this:
174+
171175
```yaml
172176
- github.com/datawire/telepresence-pro/rpc/userdaemon
173177
- github.com/datawire/telepresence-pro/rpc/proconnector
@@ -180,19 +184,17 @@ And pass it to the generate.sh script using the argument `--proprietary-packages
180184
./generate.sh" --proprietary-packages proprietary-packages.yaml;
181185
```
182186

183-
### Remember to always create a ticket!
184-
When a problem arise, remember to always create a ticket so that the problem can be fixed. This will help all users
185-
of the `go-mkopensource` tool and in many cases also make the owner of the failing component aware of the problem.
186-
187187
## Dependabot PRs
188188

189189
When dependabot creates a PR, it's possible that license scanning will fail due so several factors:
190+
190191
1. A Go package is unavailable in the new version of a module
191192
2. Dependency information is out of date.
192193

193194
To reduce friction merging dependabot PRs, there is an action (`save-dependabot-changes`) that will update a PR created by dependabot.
194195

195196
Use the action in a workflow as follows:
197+
196198
```yaml
197199
name: "Verify licenses"
198200
on: push
@@ -207,7 +209,7 @@ jobs:
207209
id: changed-by-dependabot
208210
uses: datawire/go-mkopensource/actions/[email protected]
209211
with:
210-
branches_to_skip: 'master'
212+
branches_to_skip: "master"
211213
- name: Abort if dependencies changed
212214
if: steps.changed-by-dependabot.outputs.license_information_committed == 'true'
213215
run: |
@@ -216,10 +218,11 @@ jobs:
216218
# Continue with other steps
217219
```
218220

219-
*Notes*:
220-
- The GitHub token GITHUB_TOKEN should have at least `contents:write` and `actions: write`
221+
**Notes**:
222+
223+
- The GitHub token GITHUB_TOKEN should have at least `contents:write` and `actions: write`
221224
[privileges](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token).
222-
- The workflow that invokes the action should have a `workflow_dispatch`
225+
- The workflow that invokes the action should have a `workflow_dispatch`
223226
[trigger](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch).
224227

225228
### Testing changes to the `save-dependabot-changes` action
@@ -231,5 +234,5 @@ to point to the new version of the action.
231234
uses: datawire/go-mkopensource/actions/save-dependabot-changes@<VERSION>
232235
```
233236

234-
Note: If you want to test your changes before they are complete, you could use a branch in the action reference, and
235-
update it to a tag once you're ready to release.
237+
Note: If you want to test your changes before they are complete, you could use a branch in the action reference, and
238+
update it to a tag once you're ready to release.

build-aux/docker/go_builder.dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Go dependency scanner
33
########################################
44
ARG GO_IMAGE="base-image-unknown"
5-
FROM golang:1.20.12-alpine3.19 as builder
5+
FROM golang:1.22.4-alpine3.20 as builder
66

77
ENV GOCACHE=/root/.cache/go-build
88
RUN mkdir -p "${GOCACHE}"

build-aux/docker/js_builder.dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# builder for Js scanning
33
######################################################################
44
ARG NODE_IMAGE="need-a-base-image"
5-
FROM golang:1.19-alpine3.15 as builder
5+
FROM golang:1.22.4-alpine3.20 as builder
66

77
ENV GOCACHE=/root/.cache/go-build
88
RUN mkdir -p "${GOCACHE}"

build-aux/docker/py_builder.dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Python dependency scanner
33
########################################
44
ARG PYTHON_IMAGE="need-a-base-image"
5-
FROM golang:1.19-alpine3.15 as builder
5+
FROM golang:1.22.4-alpine3.20 as builder
66

77
WORKDIR /src
88
COPY . ./

0 commit comments

Comments
 (0)