consolidate go version computation (#33679)

* consolidate go version computation

* use Go from mattermost-build-server

* work around "error obtaining VCS status: exit status 128" in a container"

* no longer require sudo

* fix config-reset for GOFLAGS

* only test-postgres-binary on master/release

* add check-prereqs-enterprise to test-mmctl* to ensure go.work setup
This commit is contained in:
Jesse Hallam
2025-08-29 12:01:12 -03:00
committed by GitHub
parent 0a098df9a7
commit f56d02406c
4 changed files with 71 additions and 126 deletions
+4 -14
View File
@@ -14,6 +14,9 @@ on:
logsartifact:
required: true
type: string
go-version:
required: true
type: string
jobs:
test:
@@ -24,23 +27,10 @@ jobs:
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
working-directory: ./server
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Store required variables for publishing results
run: |
echo "${{ inputs.name }}" > server/test-name
echo "${{ github.event.pull_request.number }}" > server/pr-number
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: server/go.sum
- name: Run setup-go-work
run: |
cd server
make setup-go-work
- name: Setup needed prepackaged plugins
run: |
cd server
@@ -56,7 +46,7 @@ jobs:
docker compose --ansi never ps
- name: Run mmctl Tests
env:
BUILD_IMAGE: mattermostdevelopment/mattermost-build-server:${{ steps.go.outputs.GO_VERSION }}
BUILD_IMAGE: mattermostdevelopment/mattermost-build-server:${{ inputs.go-version }}
run: |
if [[ ${{ github.ref_name }} == 'master' ]]; then
export TESTFLAGS="-timeout 90m -race"
+58 -97
View File
@@ -17,25 +17,29 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
go:
name: Compute Go Version
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.calculate.outputs.GO_VERSION }}
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate version
id: calculate
working-directory: server/
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
check-mocks:
name: Check mocks
needs: go
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: |
server/go.sum
server/public/go.sum
- name: Run setup-go-work
run: make setup-go-work
- name: Generate mocks
@@ -44,23 +48,15 @@ jobs:
run: if [[ -n $(git status --porcelain) ]]; then echo "Please update the mocks using `make mocks`"; exit 1; fi
check-go-mod-tidy:
name: Check go mod tidy
needs: go
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: |
server/go.sum
server/public/go.sum
- name: Run setup-go-work
run: make setup-go-work
- name: Run go mod tidy
@@ -69,46 +65,32 @@ jobs:
run: if [[ -n $(git status --porcelain) ]]; then echo "Please tidy up the Go modules using make modules-tidy"; git diff; exit 1; fi
golangci:
name: golangci-lint
needs: go
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
env:
GOFLAGS: -buildvcs=false # TODO: work around "error obtaining VCS status: exit status 128" in a container
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: |
server/go.sum
server/public/go.sum
- name: Run setup-go-work
run: make setup-go-work
- name: Run golangci
run: make golangci-lint
check-gen-serialized:
name: Check serialization methods for hot structs
needs: go
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: |
server/go.sum
server/public/go.sum
- name: Run setup-go-work
run: make setup-go-work
- name: Run make-gen-serialized
@@ -117,23 +99,15 @@ jobs:
run: if [[ -n $(git status --porcelain) ]]; then echo "Please update the serialized files using 'make gen-serialized'"; exit 1; fi
check-mattermost-vet:
name: Check style
needs: go
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: |
server/go.sum
server/public/go.sum
- name: Run setup-go-work
run: make setup-go-work
- name: Reset config
@@ -144,30 +118,24 @@ jobs:
run: make vet BUILD_NUMBER='${GITHUB_HEAD_REF}'
check-mattermost-vet-api:
name: Vet API
needs: go
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: |
server/go.sum
server/public/go.sum
- name: Run setup-go-work
run: make setup-go-work
- name: Run mattermost-vet-api
run: make vet-api
check-migrations:
name: Check migration files
needs: go
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
@@ -180,7 +148,9 @@ jobs:
run: if [[ -n $(git status --porcelain) ]]; then echo "Please update the migrations using make migrations-extract"; exit 1; fi
check-email-templates:
name: Generate email templates
needs: go
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
@@ -189,29 +159,21 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Generate email templates
run: |
sudo npm install -g mjml@4.9.0
npm install -g mjml@4.9.0
make build-templates
- name: Check generated email templates
run: if [[ -n $(git status --porcelain) ]]; then echo "Please update the email templates using `make build-templates`"; exit 1; fi
check-store-layers:
name: Check store layers
needs: go
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: |
server/go.sum
server/public/go.sum
- name: Run setup-go-work
run: make setup-go-work
- name: Generate store layers
@@ -220,23 +182,15 @@ jobs:
run: if [[ -n $(git status --porcelain) ]]; then echo "Please update the store layers using make store-layers"; exit 1; fi
check-mmctl-docs:
name: Check mmctl docs
needs: go
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
steps:
- name: Checkout mattermost-server
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: |
server/go.sum
server/public/go.sum
- name: Run setup-go-work
run: make setup-go-work
- name: Check docs
@@ -245,9 +199,11 @@ jobs:
make mmctl-docs
if [[ -n $(git status --porcelain) ]]; then echo "Please update the mmctl docs using make mmctl-docs"; exit 1; fi
test-postgres-binary:
if: github.ref_name != 'master' # Do not run postgres binary tests on master
if: github.event_name == 'push' # Only run postgres binary tests on master/release pushes: odds are low this regresses, so save the cycles for pull requests.
name: Postgres with binary parameters
needs: check-mattermost-vet
needs:
- go
- check-mattermost-vet
uses: ./.github/workflows/server-test-template.yml
secrets: inherit
with:
@@ -255,9 +211,12 @@ jobs:
datasource: postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10&binary_parameters=yes
drivername: postgres
logsartifact: postgres-binary-server-test-logs
go-version: ${{ needs.go.outputs.version }}
test-postgres-normal:
name: Postgres
needs: check-mattermost-vet
needs:
- go
- check-mattermost-vet
uses: ./.github/workflows/server-test-template.yml
secrets: inherit
with:
@@ -265,11 +224,14 @@ jobs:
datasource: postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10
drivername: postgres
logsartifact: postgres-server-test-logs
go-version: ${{ needs.go.outputs.version }}
test-coverage:
# Skip coverage generation for cherry-pick PRs into release branches.
if: ${{ github.event_name != 'pull_request' || !startsWith(github.event.pull_request.base.ref, 'release-') }}
name: Generate Test Coverage
needs: check-mattermost-vet
needs:
- go
- check-mattermost-vet
uses: ./.github/workflows/server-test-template.yml
secrets: inherit
with:
@@ -279,9 +241,12 @@ jobs:
logsartifact: coverage-server-test-logs
fullyparallel: true
enablecoverage: true
go-version: ${{ needs.go.outputs.version }}
test-mmctl:
name: Run mmctl tests
needs: check-mattermost-vet
needs:
- check-mattermost-vet
- go
uses: ./.github/workflows/mmctl-test-template.yml
secrets: inherit
with:
@@ -289,26 +254,22 @@ jobs:
datasource: postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10
drivername: postgres
logsartifact: mmctl-test-logs
go-version: ${{ needs.go.outputs.version }}
build-mattermost-server:
name: Build mattermost server app
needs:
- go
- check-mattermost-vet
runs-on: ubuntu-22.04
container: mattermostdevelopment/mattermost-build-server:${{ needs.go.outputs.version }}
defaults:
run:
working-directory: server
needs: check-mattermost-vet
env:
GOFLAGS: -buildvcs=false # TODO: work around "error obtaining VCS status: exit status 128" in a container
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: |
server/go.sum
server/public/go.sum
- name: ci/setup-node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
id: setup_node
+4 -10
View File
@@ -22,6 +22,9 @@ on:
required: false
type: boolean
default: false
go-version:
required: true
type: string
jobs:
test:
@@ -33,15 +36,6 @@ jobs:
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Calculate Golang Version
id: go
working-directory: ./server
run: echo GO_VERSION=$(cat .go-version) >> "${GITHUB_OUTPUT}"
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go.outputs.GO_VERSION }}
cache-dependency-path: server/go.sum
- name: Store required variables for publishing results
run: |
echo "${{ inputs.name }}" > server/test-name
@@ -57,7 +51,7 @@ jobs:
docker compose --ansi never ps
- name: Run Tests
env:
BUILD_IMAGE: mattermostdevelopment/mattermost-build-server:${{ steps.go.outputs.GO_VERSION }}
BUILD_IMAGE: mattermostdevelopment/mattermost-build-server:${{ inputs.go-version }}
run: |
if [[ ${{ github.ref_name }} == 'master' && ${{ inputs.fullyparallel }} != true ]]; then
export RACE_MODE="-race"
+5 -5
View File
@@ -521,28 +521,28 @@ inject-test-data: # add test data to the local instance.
test-mmctl-unit: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT)
test-mmctl-unit: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE)
test-mmctl-unit: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE)
test-mmctl-unit: gotestsum
test-mmctl-unit: check-prereqs-enterprise gotestsum
@echo Running mmctl unit tests
$(GOBIN)/gotestsum --packages="$(MMCTL_PACKAGES)" -- -tags 'unit $(MMCTL_BUILD_TAGS)' $(MMCTL_TESTFLAGS)
test-mmctl-e2e: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT)
test-mmctl-e2e: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE)
test-mmctl-e2e: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE)
test-mmctl-e2e: gotestsum start-docker
test-mmctl-e2e: check-prereqs-enterprise gotestsum start-docker
@echo Running mmctl e2e tests
$(GOBIN)/gotestsum --packages="$(MMCTL_PACKAGES)" -- -tags 'e2e $(MMCTL_BUILD_TAGS)' $(MMCTL_TESTFLAGS)
test-mmctl: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT)
test-mmctl: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE)
test-mmctl: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE)
test-mmctl: gotestsum start-docker
test-mmctl: check-prereqs-enterprise gotestsum start-docker
@echo Running all mmctl tests
$(GOBIN)/gotestsum --packages="$(MMCTL_PACKAGES)" -- -tags 'unit e2e $(MMCTL_BUILD_TAGS)' $(MMCTL_TESTFLAGS)
test-mmctl-coverage: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT)
test-mmctl-coverage: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE)
test-mmctl-coverage: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE)
test-mmctl-coverage: gotestsum start-docker
test-mmctl-coverage: check-prereqs-enterprise gotestsum start-docker
@echo Running all mmctl tests with coverage
$(GOBIN)/gotestsum --packages="$(MMCTL_PACKAGES)" -- -tags 'unit e2e $(MMCTL_BUILD_TAGS)' -coverprofile=mmctlcover.out $(MMCTL_TESTFLAGS)
$(GO) tool cover -html=mmctlcover.out
@@ -705,7 +705,7 @@ config-openid: ## Configures OpenID.
config-reset: ## Resets the config/config.json file to the default production values.
@echo Resetting configuration to production default
rm -f config/config.json
OUTPUT_CONFIG=$(PWD)/config/config.json $(GO) $(GOFLAGS) run -tags production ./scripts/config_generator
OUTPUT_CONFIG=$(PWD)/config/config.json $(GO) run $(GOFLAGS) -tags production ./scripts/config_generator
diff-config: ## Compares default configuration between two mattermost versions
@./scripts/diff-config.sh