diff --git a/.github/workflows/tarball.yml b/.github/workflows/tarball.yml new file mode 100644 index 0000000..fcf61e1 --- /dev/null +++ b/.github/workflows/tarball.yml @@ -0,0 +1,105 @@ +name: tarball + +on: + push: + branches: [ master ] + paths: + - '.github/workflows/build.yml' + - '**.go' + - 'go.*' + - 'Makefile' + pull_request: + branches: [ master ] + paths: + - '.github/workflows/build.yml' + - '**.go' + - 'go.*' + - 'Makefile' + +jobs: + create: + strategy: + matrix: + go-version: + - "1.17" + - "1.18" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + + - id: go-cache-paths + run: | + echo "::set-output name=go-build::$(go env GOCACHE)" + echo "::set-output name=go-mod::$(go env GOMODCACHE)" + echo "::set-output name=go-version::$(go version | cut -d ' ' -f 3)" + + - name: Go build cache + uses: actions/cache@v3 + with: + path: ${{ steps.go-cache-paths.outputs.go-build }} + key: ${{ runner.os }}-${{ steps.go-cache-paths.outputs.go-version }}-build-${{ hashFiles('**/go.mod', '**/go.sum') }} + + - name: Go mod cache + uses: actions/cache@v3 + with: + path: ${{ steps.go-cache-paths.outputs.go-mod }} + key: ${{ runner.os }}-${{ steps.go-cache-paths.outputs.go-version }}-mod-${{ hashFiles('**/go.mod', '**/go.sum') }} + + - name: Install dependencies + run: | + sudo apt -y update && sudo apt -y install protobuf-compiler + + - name: Create tarball + run: | + echo "Building with $(nproc) threads" + make tarball + + - name: Upload tarball + uses: actions/upload-artifact@v2 + with: + name: tarball-${{ matrix.go-version }} + path: nextcloud-spreed-signaling*.tar.gz + + test: + strategy: + matrix: + go-version: + - "1.17" + - "1.18" + runs-on: ubuntu-latest + needs: [create] + steps: + - uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + + - name: Install dependencies + run: | + sudo apt -y update && sudo apt -y install protobuf-compiler + + - name: Download tarball + uses: actions/download-artifact@v2 + with: + name: tarball-${{ matrix.go-version }} + + - name: Extract tarball + run: | + mkdir -p tmp + tar xf nextcloud-spreed-signaling*.tar.gz --strip-components=1 -C tmp + [ -d "tmp/vendor" ] || exit 1 + + - name: Build + env: + GOPROXY: off + run: | + echo "Building with $(nproc) threads" + make -C tmp build -j$(nproc) + + - name: Run tests + env: + GOPROXY: off + run: | + make -C tmp test diff --git a/Makefile b/Makefile index b9cc4f6..9065f6f 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,14 @@ GOOS ?= linux GOARCH ?= amd64 GOVERSION := $(shell "$(GO)" env GOVERSION | sed "s|go||" ) BINDIR := "$(CURDIR)/bin" +VENDORDIR := "$(CURDIR)/vendor" VERSION := $(shell "$(CURDIR)/scripts/get-version.sh") TARVERSION := $(shell "$(CURDIR)/scripts/get-version.sh" --tar) PACKAGENAME := github.com/strukturag/nextcloud-spreed-signaling ALL_PACKAGES := $(PACKAGENAME) $(PACKAGENAME)/client $(PACKAGENAME)/proxy $(PACKAGENAME)/server +PROTOC_GEN_GRPC_VERSION := v1.2.0 + ifneq ($(VERSION),) INTERNALLDFLAGS := -X main.version=$(VERSION) else @@ -53,15 +56,14 @@ hook: [ ! -d "$(CURDIR)/.git/hooks" ] || ln -sf "$(CURDIR)/scripts/pre-commit.hook" "$(CURDIR)/.git/hooks/pre-commit" $(GOPATHBIN)/easyjson: - $(GO) get -u -d github.com/mailru/easyjson/... + [ "$(GOPROXY)" = "off" ] || $(GO) get -u -d github.com/mailru/easyjson/... $(GO) install github.com/mailru/easyjson/... $(GOPATHBIN)/protoc-gen-go: - $(GO) get -u -d google.golang.org/protobuf/cmd/protoc-gen-go $(GO) install google.golang.org/protobuf/cmd/protoc-gen-go $(GOPATHBIN)/protoc-gen-go-grpc: - $(GO) get -u -d google.golang.org/grpc/cmd/protoc-gen-go-grpc + [ "$(GOPROXY)" = "off" ] || $(GO) get -u -d google.golang.org/grpc/cmd/protoc-gen-go-grpc $(GO) install google.golang.org/grpc/cmd/protoc-gen-go-grpc continentmap.go: @@ -143,13 +145,34 @@ clean: build: server proxy -tarball: +vendor: go.mod go.sum common + set -e ;\ + rm -rf $(VENDORDIR) + EASYJSON_DIR=$$($(GO) list -m -f '{{.Dir}}' github.com/mailru/easyjson); \ + PROTOBUF_DIR=$$($(GO) list -m -f '{{.Dir}}' google.golang.org/protobuf); \ + $(GO) mod tidy; \ + $(GO) mod vendor; \ + mkdir -p $(VENDORDIR)/github.com/mailru/easyjson/; \ + cp -rf --no-preserve=mode $$EASYJSON_DIR/easyjson/ $(VENDORDIR)/github.com/mailru/easyjson/; \ + mkdir -p $(VENDORDIR)/google.golang.org/grpc/cmd/protoc-gen-go-grpc/; \ + cp -rf --no-preserve=mode $(GOPATH)/pkg/mod/google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GRPC_VERSION)/* $(VENDORDIR)/google.golang.org/grpc/cmd/protoc-gen-go-grpc/; \ + cp -rf --no-preserve=mode $$PROTOBUF_DIR/cmd/ $(VENDORDIR)/google.golang.org/protobuf/; \ + cp -rf --no-preserve=mode $$PROTOBUF_DIR/compiler/ $(VENDORDIR)/google.golang.org/protobuf/; \ + cp -rf --no-preserve=mode $$PROTOBUF_DIR/types/ $(VENDORDIR)/google.golang.org/protobuf/; \ + +tarball: vendor git archive \ --prefix=nextcloud-spreed-signaling-$(TARVERSION)/ \ - -o nextcloud-spreed-signaling-$(TARVERSION).tar.gz \ + -o nextcloud-spreed-signaling-$(TARVERSION).tar \ HEAD + tar rf nextcloud-spreed-signaling-$(TARVERSION).tar \ + -C $(CURDIR) \ + --mtime="$(shell git log -1 --date=iso8601-strict --format=%cd HEAD)" \ + --transform "s//nextcloud-spreed-signaling-$(TARVERSION)\//" \ + vendor + gzip --force nextcloud-spreed-signaling-$(TARVERSION).tar dist: tarball .NOTPARALLEL: %_easyjson.go -.PHONY: continentmap.go +.PHONY: continentmap.go vendor diff --git a/go.mod b/go.mod index 6f6ab6e..3a3232e 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,7 @@ require ( go.etcd.io/etcd/client/v3 v3.5.4 go.etcd.io/etcd/server/v3 v3.5.4 google.golang.org/grpc v1.48.0 + google.golang.org/protobuf v1.28.0 ) require ( @@ -79,7 +80,6 @@ require ( golang.org/x/text v0.3.6 // indirect golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect - google.golang.org/protobuf v1.28.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect diff --git a/vendor_helper_test.go b/vendor_helper_test.go new file mode 100644 index 0000000..0166898 --- /dev/null +++ b/vendor_helper_test.go @@ -0,0 +1,29 @@ +/** + * Standalone signaling server for the Nextcloud Spreed app. + * Copyright (C) 2022 struktur AG + * + * @author Joachim Bauch + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package signaling + +// Import modules that would otherwise not be detected by "go mod vendor". +import ( + _ "github.com/mailru/easyjson/bootstrap" + _ "github.com/mailru/easyjson/gen" + _ "github.com/mailru/easyjson/parser" +)