Skip to content

Commit 49efd1f

Browse files
authored
Add go licenses to licenses.txt (#21034)
`make go-licenses` will generate `assets/go-licenses.json` which is then included in the webpack build. This step depends on both go and node being present, so unfortunately, I could not automate the generation by hooking it up to `tidy` as that target is triggered on CI where we do not have a docker image with both go an node. It should be ran from time to time, ideally after each go mod update.
1 parent 82c6f7b commit 49efd1f

File tree

6 files changed

+827
-7
lines changed

6 files changed

+827
-7
lines changed

.drone.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ steps:
9090
- name: checks-backend
9191
image: golang:1.19
9292
commands:
93+
- curl -sL https://deb.nodesource.com/setup_18.x | bash - && apt-get -qqy install nodejs
9394
- make checks-backend
95+
environment:
96+
DEBIAN_FRONTEND: noninteractive
9497
depends_on: [deps-backend]
9598
volumes:
9699
- name: deps
@@ -722,12 +725,13 @@ steps:
722725
pull: always
723726
commands:
724727
# Upgrade to node 18 once https://github.com/techknowlogick/xgo/issues/163 is resolved
725-
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs
728+
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get -qqy install nodejs
726729
- export PATH=$PATH:$GOPATH/bin
727730
- make release
728731
environment:
729732
GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not
730733
TAGS: bindata sqlite sqlite_unlock_notify
734+
DEBIAN_FRONTEND: noninteractive
731735
volumes:
732736
- name: deps
733737
path: /go
@@ -842,12 +846,13 @@ steps:
842846
pull: always
843847
commands:
844848
# Upgrade to node 18 once https://github.com/techknowlogick/xgo/issues/163 is resolved
845-
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs
849+
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get -qqy install nodejs
846850
- export PATH=$PATH:$GOPATH/bin
847851
- make release
848852
environment:
849853
GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not
850854
TAGS: bindata sqlite sqlite_unlock_notify
855+
DEBIAN_FRONTEND: noninteractive
851856
depends_on: [fetch-tags]
852857
volumes:
853858
- name: deps

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ cpu.out
9595
!/web_src/fomantic/build/themes/default/assets/fonts/outline-icons.woff2
9696
/VERSION
9797
/.air
98+
/.go-licenses
9899

99100
# Snapcraft
100101
snap/.snapcraft/

Makefile

+17-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3434
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/[email protected]
3535
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]
3636
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
37+
GO_LICENSES_PACKAGE ?= github.com/google/[email protected]
3738

3839
DOCKER_IMAGE ?= gitea/gitea
3940
DOCKER_TAG ?= latest
@@ -114,13 +115,16 @@ SVG_DEST_DIR := public/img/svg
114115

115116
AIR_TMP_DIR := .air
116117

118+
GO_LICENSE_TMP_DIR := .go-licenses
119+
GO_LICENSE_FILE := assets/go-licenses.json
120+
117121
TAGS ?=
118122
TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
119123
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
120124

121125
TEST_TAGS ?= sqlite sqlite_unlock_notify
122126

123-
TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMANTIC_WORK_DIR)/node_modules $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR)
127+
TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMANTIC_WORK_DIR)/node_modules $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR) $(GO_LICENSE_TMP_DIR)
124128

125129
GO_DIRS := cmd tests models modules routers build services tools
126130

@@ -199,8 +203,9 @@ help:
199203
@echo " - generate-swagger generate the swagger spec from code comments"
200204
@echo " - swagger-validate check if the swagger spec is valid"
201205
@echo " - golangci-lint run golangci-lint linter"
206+
@echo " - go-licenses regenerate go licenses"
202207
@echo " - vet examines Go source code and reports suspicious constructs"
203-
@echo " - tidy run go mod tidy"
208+
@echo " - tidy run go mod tidy and regenerate go licenses"
204209
@echo " - test[\#TestSpecificName] run unit test"
205210
@echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
206211
@echo " - pr#<index> build and start gitea from a PR with integration test data loaded"
@@ -393,6 +398,7 @@ unit-test-coverage:
393398
tidy:
394399
$(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
395400
$(GO) mod tidy -compat=$(MIN_GO_VERSION)
401+
@$(MAKE) --no-print-directory assets/go-licenses.json
396402

397403
.PHONY: vendor
398404
vendor: tidy
@@ -407,6 +413,14 @@ tidy-check: tidy
407413
exit 1; \
408414
fi
409415

416+
.PHONY: go-licenses
417+
go-licenses: assets/go-licenses.json
418+
419+
assets/go-licenses.json: go.mod go.sum build/generate-go-licenses.js
420+
-$(GO) run $(GO_LICENSES_PACKAGE) save . --force --save_path="$(GO_LICENSE_TMP_DIR)" 2>/dev/null
421+
node build/generate-go-licenses.js "$(GO_LICENSE_TMP_DIR)" "$(GO_LICENSE_FILE)"
422+
@rm -rf "$(GO_LICENSE_TMP_DIR)"
423+
410424
generate-ini-sqlite:
411425
sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
412426
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
@@ -782,6 +796,7 @@ deps-backend:
782796
$(GO) install $(MISSPELL_PACKAGE)
783797
$(GO) install $(SWAGGER_PACKAGE)
784798
$(GO) install $(XGO_PACKAGE)
799+
$(GO) install $(GO_LICENSES_PACKAGE)
785800

786801
node_modules: package-lock.json
787802
npm install --no-save

0 commit comments

Comments
 (0)