mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 06:45:43 +03:00
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.
This commit is contained in:
parent
82c6f7bf4a
commit
49efd1fb96
6 changed files with 827 additions and 7 deletions
|
@ -90,7 +90,10 @@ steps:
|
||||||
- name: checks-backend
|
- name: checks-backend
|
||||||
image: golang:1.19
|
image: golang:1.19
|
||||||
commands:
|
commands:
|
||||||
|
- curl -sL https://deb.nodesource.com/setup_18.x | bash - && apt-get -qqy install nodejs
|
||||||
- make checks-backend
|
- make checks-backend
|
||||||
|
environment:
|
||||||
|
DEBIAN_FRONTEND: noninteractive
|
||||||
depends_on: [deps-backend]
|
depends_on: [deps-backend]
|
||||||
volumes:
|
volumes:
|
||||||
- name: deps
|
- name: deps
|
||||||
|
@ -722,12 +725,13 @@ steps:
|
||||||
pull: always
|
pull: always
|
||||||
commands:
|
commands:
|
||||||
# Upgrade to node 18 once https://github.com/techknowlogick/xgo/issues/163 is resolved
|
# Upgrade to node 18 once https://github.com/techknowlogick/xgo/issues/163 is resolved
|
||||||
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs
|
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get -qqy install nodejs
|
||||||
- export PATH=$PATH:$GOPATH/bin
|
- export PATH=$PATH:$GOPATH/bin
|
||||||
- make release
|
- make release
|
||||||
environment:
|
environment:
|
||||||
GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not
|
GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not
|
||||||
TAGS: bindata sqlite sqlite_unlock_notify
|
TAGS: bindata sqlite sqlite_unlock_notify
|
||||||
|
DEBIAN_FRONTEND: noninteractive
|
||||||
volumes:
|
volumes:
|
||||||
- name: deps
|
- name: deps
|
||||||
path: /go
|
path: /go
|
||||||
|
@ -842,12 +846,13 @@ steps:
|
||||||
pull: always
|
pull: always
|
||||||
commands:
|
commands:
|
||||||
# Upgrade to node 18 once https://github.com/techknowlogick/xgo/issues/163 is resolved
|
# Upgrade to node 18 once https://github.com/techknowlogick/xgo/issues/163 is resolved
|
||||||
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs
|
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get -qqy install nodejs
|
||||||
- export PATH=$PATH:$GOPATH/bin
|
- export PATH=$PATH:$GOPATH/bin
|
||||||
- make release
|
- make release
|
||||||
environment:
|
environment:
|
||||||
GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not
|
GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not
|
||||||
TAGS: bindata sqlite sqlite_unlock_notify
|
TAGS: bindata sqlite sqlite_unlock_notify
|
||||||
|
DEBIAN_FRONTEND: noninteractive
|
||||||
depends_on: [fetch-tags]
|
depends_on: [fetch-tags]
|
||||||
volumes:
|
volumes:
|
||||||
- name: deps
|
- name: deps
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -95,6 +95,7 @@ cpu.out
|
||||||
!/web_src/fomantic/build/themes/default/assets/fonts/outline-icons.woff2
|
!/web_src/fomantic/build/themes/default/assets/fonts/outline-icons.woff2
|
||||||
/VERSION
|
/VERSION
|
||||||
/.air
|
/.air
|
||||||
|
/.go-licenses
|
||||||
|
|
||||||
# Snapcraft
|
# Snapcraft
|
||||||
snap/.snapcraft/
|
snap/.snapcraft/
|
||||||
|
|
19
Makefile
19
Makefile
|
@ -34,6 +34,7 @@ GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10
|
||||||
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/misspell@v0.3.4
|
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/misspell@v0.3.4
|
||||||
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.30.0
|
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.30.0
|
||||||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
||||||
|
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.3.0
|
||||||
|
|
||||||
DOCKER_IMAGE ?= gitea/gitea
|
DOCKER_IMAGE ?= gitea/gitea
|
||||||
DOCKER_TAG ?= latest
|
DOCKER_TAG ?= latest
|
||||||
|
@ -114,13 +115,16 @@ SVG_DEST_DIR := public/img/svg
|
||||||
|
|
||||||
AIR_TMP_DIR := .air
|
AIR_TMP_DIR := .air
|
||||||
|
|
||||||
|
GO_LICENSE_TMP_DIR := .go-licenses
|
||||||
|
GO_LICENSE_FILE := assets/go-licenses.json
|
||||||
|
|
||||||
TAGS ?=
|
TAGS ?=
|
||||||
TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
|
TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
|
||||||
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
|
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
|
||||||
|
|
||||||
TEST_TAGS ?= sqlite sqlite_unlock_notify
|
TEST_TAGS ?= sqlite sqlite_unlock_notify
|
||||||
|
|
||||||
TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMANTIC_WORK_DIR)/node_modules $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR)
|
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)
|
||||||
|
|
||||||
GO_DIRS := cmd tests models modules routers build services tools
|
GO_DIRS := cmd tests models modules routers build services tools
|
||||||
|
|
||||||
|
@ -199,8 +203,9 @@ help:
|
||||||
@echo " - generate-swagger generate the swagger spec from code comments"
|
@echo " - generate-swagger generate the swagger spec from code comments"
|
||||||
@echo " - swagger-validate check if the swagger spec is valid"
|
@echo " - swagger-validate check if the swagger spec is valid"
|
||||||
@echo " - golangci-lint run golangci-lint linter"
|
@echo " - golangci-lint run golangci-lint linter"
|
||||||
|
@echo " - go-licenses regenerate go licenses"
|
||||||
@echo " - vet examines Go source code and reports suspicious constructs"
|
@echo " - vet examines Go source code and reports suspicious constructs"
|
||||||
@echo " - tidy run go mod tidy"
|
@echo " - tidy run go mod tidy and regenerate go licenses"
|
||||||
@echo " - test[\#TestSpecificName] run unit test"
|
@echo " - test[\#TestSpecificName] run unit test"
|
||||||
@echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
|
@echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
|
||||||
@echo " - pr#<index> build and start gitea from a PR with integration test data loaded"
|
@echo " - pr#<index> build and start gitea from a PR with integration test data loaded"
|
||||||
|
@ -393,6 +398,7 @@ unit-test-coverage:
|
||||||
tidy:
|
tidy:
|
||||||
$(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
|
$(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
|
||||||
$(GO) mod tidy -compat=$(MIN_GO_VERSION)
|
$(GO) mod tidy -compat=$(MIN_GO_VERSION)
|
||||||
|
@$(MAKE) --no-print-directory assets/go-licenses.json
|
||||||
|
|
||||||
.PHONY: vendor
|
.PHONY: vendor
|
||||||
vendor: tidy
|
vendor: tidy
|
||||||
|
@ -407,6 +413,14 @@ tidy-check: tidy
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
.PHONY: go-licenses
|
||||||
|
go-licenses: assets/go-licenses.json
|
||||||
|
|
||||||
|
assets/go-licenses.json: go.mod go.sum build/generate-go-licenses.js
|
||||||
|
-$(GO) run $(GO_LICENSES_PACKAGE) save . --force --save_path="$(GO_LICENSE_TMP_DIR)" 2>/dev/null
|
||||||
|
node build/generate-go-licenses.js "$(GO_LICENSE_TMP_DIR)" "$(GO_LICENSE_FILE)"
|
||||||
|
@rm -rf "$(GO_LICENSE_TMP_DIR)"
|
||||||
|
|
||||||
generate-ini-sqlite:
|
generate-ini-sqlite:
|
||||||
sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
|
sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
|
||||||
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
|
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
|
||||||
|
@ -782,6 +796,7 @@ deps-backend:
|
||||||
$(GO) install $(MISSPELL_PACKAGE)
|
$(GO) install $(MISSPELL_PACKAGE)
|
||||||
$(GO) install $(SWAGGER_PACKAGE)
|
$(GO) install $(SWAGGER_PACKAGE)
|
||||||
$(GO) install $(XGO_PACKAGE)
|
$(GO) install $(XGO_PACKAGE)
|
||||||
|
$(GO) install $(GO_LICENSES_PACKAGE)
|
||||||
|
|
||||||
node_modules: package-lock.json
|
node_modules: package-lock.json
|
||||||
npm install --no-save
|
npm install --no-save
|
||||||
|
|
762
assets/go-licenses.json
Normal file
762
assets/go-licenses.json
Normal file
File diff suppressed because one or more lines are too long
30
build/generate-go-licenses.js
Normal file
30
build/generate-go-licenses.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
import fastGlob from 'fast-glob';
|
||||||
|
import {fileURLToPath} from 'url';
|
||||||
|
import {readFileSync, writeFileSync} from 'fs';
|
||||||
|
import wrapAnsi from 'wrap-ansi';
|
||||||
|
import {join, dirname} from 'path';
|
||||||
|
|
||||||
|
const base = process.argv[2];
|
||||||
|
const out = process.argv[3];
|
||||||
|
|
||||||
|
function exit(err) {
|
||||||
|
if (err) console.error(err);
|
||||||
|
process.exit(err ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const data = fastGlob.sync('**/*', {
|
||||||
|
cwd: fileURLToPath(new URL(`../${base}`, import.meta.url)),
|
||||||
|
}).filter((path) => {
|
||||||
|
return /\/((UN)?LICEN(S|C)E|COPYING|NOTICE)/i.test(path);
|
||||||
|
}).sort().map((path) => {
|
||||||
|
return {
|
||||||
|
name: dirname(path),
|
||||||
|
body: wrapAnsi(readFileSync(join(base, path), 'utf8') || '', 80)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
writeFileSync(out, JSON.stringify(data, null, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
main().then(exit).catch(exit);
|
|
@ -9,6 +9,7 @@ import EsBuildLoader from 'esbuild-loader';
|
||||||
import {parse, dirname} from 'path';
|
import {parse, dirname} from 'path';
|
||||||
import webpack from 'webpack';
|
import webpack from 'webpack';
|
||||||
import {fileURLToPath} from 'url';
|
import {fileURLToPath} from 'url';
|
||||||
|
import {readFileSync} from 'fs';
|
||||||
|
|
||||||
const {VueLoaderPlugin} = VueLoader;
|
const {VueLoaderPlugin} = VueLoader;
|
||||||
const {ESBuildMinifyPlugin} = EsBuildLoader;
|
const {ESBuildMinifyPlugin} = EsBuildLoader;
|
||||||
|
@ -205,10 +206,16 @@ export default {
|
||||||
outputFilename: 'js/licenses.txt',
|
outputFilename: 'js/licenses.txt',
|
||||||
outputWriter: ({dependencies}) => {
|
outputWriter: ({dependencies}) => {
|
||||||
const line = '-'.repeat(80);
|
const line = '-'.repeat(80);
|
||||||
return dependencies.map((module) => {
|
const goModules = JSON.parse(readFileSync('assets/go-licenses.json', 'utf8'));
|
||||||
const {name, version, licenseName, licenseText} = module;
|
const jsModules = dependencies.map(({name, version, licenseName, licenseText}) => {
|
||||||
const body = wrapAnsi(licenseText || '', 80);
|
const body = wrapAnsi(licenseText || '', 80);
|
||||||
return `${line}\n${name}@${version} - ${licenseName}\n${line}\n${body}`;
|
return {name, version, licenseName, body};
|
||||||
|
});
|
||||||
|
|
||||||
|
const modules = [...goModules, ...jsModules].sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
return modules.map(({name, version, licenseName, body}) => {
|
||||||
|
const title = licenseName ? `${name}@${version} - ${licenseName}` : name;
|
||||||
|
return `${line}\n${title}\n${line}\n${body}`;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
},
|
},
|
||||||
override: {
|
override: {
|
||||||
|
|
Loading…
Reference in a new issue