From 6a601f5ed36e6ca6204472955b32b1ca6ff525dc Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 12:44:33 -0600 Subject: [PATCH 01/12] Add support for pre-release builds from main --- .github/workflows/test.yaml | 27 ++++++++++++++++++++++++++- .gitignore | 1 + Makefile | 16 +++++++++++++--- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9324352..621015d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,10 +2,15 @@ on: pull_request: workflow_dispatch: workflow_call: + push: + branches: + - main + release: + types: [created] jobs: test: - name: Test lint and build + name: Lint and Test Build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -25,3 +30,23 @@ jobs: fi - name: Build run: make all + + build: + name: Build and Upload + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' || github.event_name == 'release' + needs: test + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ secrets.GCP_CREDENTIALS }} + uses: google-github-actions/setup-gcloud@v2 + - name: Build + run: make all + - name: Upload to GCS + run: | + gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-* preinstall.sh install.sh uninstall.sh gs://packages.viam.com/temp/ diff --git a/.gitignore b/.gitignore index e660fd9..2a8ac54 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bin/ +.vscode/ diff --git a/Makefile b/Makefile index e85a8b1..e5fc3f8 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,17 @@ LINUX_ARCH = aarch64 endif ifeq ($(shell git status -s),) - TAG_VERSION ?= $(shell git tag --points-at | sort -Vr | head -n1 | cut -c2-) + ifeq ($(shell git branch --show-current),"main") + LAST_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null) + COMMITS_SINCE_TAG := $(shell git rev-list $(LAST_TAG)..HEAD --count 2>/dev/null) + BASE_VERSION := $(shell echo $(LAST_TAG) | cut -c2-) + NEXT_VERSION := $(shell echo $(BASE_VERSION) | awk -F. '{$$2+=1; $$3=0;}1' OFS=.) + ifeq ($(COMMITS_SINCE_TAG),0) + TAG_VERSION ?= $(BASE_VERSION) + else + TAG_VERSION ?= $(NEXT_VERSION)-pre.$(COMMITS_SINCE_TAG) + endif + endif GIT_REVISION = $(shell git rev-parse HEAD | tr -d '\n') endif ifeq ($(TAG_VERSION),) @@ -35,7 +45,7 @@ amd64: bin/viam-agent-$(PATH_VERSION)-$(LINUX_ARCH): go.* *.go */*.go */*/*.go *.service Makefile go build -o $@ -trimpath -tags $(TAGS) -ldflags $(LDFLAGS) ./cmd/viam-agent/main.go - test "$(PATH_VERSION)" != "custom" && cp $@ bin/viam-agent-stable-$(LINUX_ARCH) || true + echo $(PATH_VERSION) | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$$' && cp $@ bin/viam-agent-stable-$(LINUX_ARCH) || true .PHONY: clean clean: @@ -51,7 +61,7 @@ lint: bin/golangci-lint .PHONY: upload-stable upload-stable: bin/viam-agent-$(PATH_VERSION)-x86_64 bin/viam-agent-$(PATH_VERSION)-aarch64 bin/viam-agent-stable-x86_64 bin/viam-agent-stable-aarch64 - test "$(PATH_VERSION)" != "custom" + echo $(PATH_VERSION) | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$$' || exit 1 gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-$(PATH_VERSION)-x86_64 bin/viam-agent-$(PATH_VERSION)-aarch64 bin/viam-agent-stable-x86_64 bin/viam-agent-stable-aarch64 gs://packages.viam.com/apps/viam-agent/ .PHONY: upload-installer From a48b161468212042e91b53593318141a9bc92337 Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 13:38:07 -0600 Subject: [PATCH 02/12] Fix and run tests --- .github/workflows/test.yaml | 2 ++ Makefile | 7 ++++++- utils/config_test.go | 23 ++++++++++++++--------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 621015d..cdd3f94 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -28,6 +28,8 @@ jobs: git status exit 1 fi + - name: Test + run: make test - name: Build run: make all diff --git a/Makefile b/Makefile index e5fc3f8..417f2d5 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ LINUX_ARCH = aarch64 endif ifeq ($(shell git status -s),) - ifeq ($(shell git branch --show-current),"main") + ifeq ($(shell git branch --show-current),main) LAST_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null) COMMITS_SINCE_TAG := $(shell git rev-list $(LAST_TAG)..HEAD --count 2>/dev/null) BASE_VERSION := $(shell echo $(LAST_TAG) | cut -c2-) @@ -59,6 +59,10 @@ lint: bin/golangci-lint go mod tidy bin/golangci-lint run -v --fix +.PHONY: test +test: + go test -race ./... + .PHONY: upload-stable upload-stable: bin/viam-agent-$(PATH_VERSION)-x86_64 bin/viam-agent-$(PATH_VERSION)-aarch64 bin/viam-agent-stable-x86_64 bin/viam-agent-stable-aarch64 echo $(PATH_VERSION) | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$$' || exit 1 @@ -66,4 +70,5 @@ upload-stable: bin/viam-agent-$(PATH_VERSION)-x86_64 bin/viam-agent-$(PATH_VERSI .PHONY: upload-installer upload-installer: + echo $(PATH_VERSION) | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$$' || exit 1 gsutil -h "Cache-Control:no-cache" cp preinstall.sh install.sh uninstall.sh gs://packages.viam.com/apps/viam-agent/ diff --git a/utils/config_test.go b/utils/config_test.go index 7d76144..b158292 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -65,16 +65,21 @@ func TestConvertJson(t *testing.T) { err := json.Unmarshal([]byte(jsonBytes), newConfig) testConfig := DefaultConfig() - testConfig.AdditionalNetworks["network1"] = NetworkDefinition{ - Type: "wifi", - Interface: "wlan0", - SSID: "foo", - PSK: "bar", - IPv4Address: "192.168.0.1/24", - IPv4Gateway: "192.168.0.255", - IPv4DNS: []string{"192.168.0.255"}, + testConfig.AdditionalNetworks = map[string]NetworkDefinition{ + "network1": { + Type: "wifi", + Interface: "wlan0", + SSID: "foo", + PSK: "bar", + IPv4Address: "192.168.0.1/24", + IPv4Gateway: "192.168.0.255", + IPv4DNS: []string{"192.168.0.255"}, + }, + "network2": { + SSID: "moo", + PSK: "cow", + }, } - testConfig.AdditionalNetworks["network2"] = NetworkDefinition{SSID: "moo", PSK: "cow"} test.That(t, err, test.ShouldBeNil) test.That(t, *newConfig, test.ShouldResemble, testConfig) From 0243521bea9af42907c4cbccbd0c10a22d4a3fad Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 16:22:06 -0600 Subject: [PATCH 03/12] Test url --- .github/workflows/test.yaml | 2 +- .gitignore | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index cdd3f94..bee5b56 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -51,4 +51,4 @@ jobs: run: make all - name: Upload to GCS run: | - gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-* preinstall.sh install.sh uninstall.sh gs://packages.viam.com/temp/ + gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-* preinstall.sh install.sh uninstall.sh gs://packages.viam.com/temp/prerelease/ #SMURF use real before merge diff --git a/.gitignore b/.gitignore index 2a8ac54..e660fd9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ bin/ -.vscode/ From cf4a4f389366820b04c6fc9959c79d90b4927c42 Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 16:26:28 -0600 Subject: [PATCH 04/12] typos --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index bee5b56..0be4356 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,7 +4,7 @@ on: workflow_call: push: branches: - - main + - prereleases release: types: [created] @@ -36,7 +36,7 @@ jobs: build: name: Build and Upload runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' || github.event_name == 'release' + if: github.ref == 'refs/heads/prereleaases' || github.event_name == 'release' needs: test steps: - uses: actions/checkout@v4 @@ -50,5 +50,5 @@ jobs: - name: Build run: make all - name: Upload to GCS - run: | - gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-* preinstall.sh install.sh uninstall.sh gs://packages.viam.com/temp/prerelease/ #SMURF use real before merge + run: | + gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-* preinstall.sh install.sh uninstall.sh gs://packages.viam.com/temp/prerelease/ #SMURF use real before merge From 49a1199569e0442921f17a23476efb38f18aae21 Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 16:27:42 -0600 Subject: [PATCH 05/12] typo --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0be4356..69555dc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -43,10 +43,10 @@ jobs: - uses: actions/setup-go@v5 with: go-version-file: go.mod - uses: google-github-actions/auth@v2 + - uses: google-github-actions/auth@v2 with: credentials_json: ${{ secrets.GCP_CREDENTIALS }} - uses: google-github-actions/setup-gcloud@v2 + - uses: google-github-actions/setup-gcloud@v2 - name: Build run: make all - name: Upload to GCS From d3e9a32580466c488e978bba14f34a5fb127ff04 Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 16:33:30 -0600 Subject: [PATCH 06/12] typo --- .github/workflows/test.yaml | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 69555dc..e2b4282 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -36,7 +36,7 @@ jobs: build: name: Build and Upload runs-on: ubuntu-latest - if: github.ref == 'refs/heads/prereleaases' || github.event_name == 'release' + if: github.ref == 'refs/heads/prereleases' || github.event_name == 'release' needs: test steps: - uses: actions/checkout@v4 diff --git a/Makefile b/Makefile index 417f2d5..7b0b6e9 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ ifeq ($(shell git status -s),) ifeq ($(COMMITS_SINCE_TAG),0) TAG_VERSION ?= $(BASE_VERSION) else - TAG_VERSION ?= $(NEXT_VERSION)-pre.$(COMMITS_SINCE_TAG) + TAG_VERSION ?= $(NEXT_VERSION)-dev.$(COMMITS_SINCE_TAG) endif endif GIT_REVISION = $(shell git rev-parse HEAD | tr -d '\n') From 7271300a4410ca1107583d958dbc55c339621480 Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 16:36:37 -0600 Subject: [PATCH 07/12] typo --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7b0b6e9..0baf1df 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ LINUX_ARCH = aarch64 endif ifeq ($(shell git status -s),) - ifeq ($(shell git branch --show-current),main) + ifeq ($(shell git branch --show-current),prereleases) #SMURF use main before merge LAST_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null) COMMITS_SINCE_TAG := $(shell git rev-list $(LAST_TAG)..HEAD --count 2>/dev/null) BASE_VERSION := $(shell echo $(LAST_TAG) | cut -c2-) From ef98e3879b1cc39215cba1130f7591f672505d8e Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 16:39:35 -0600 Subject: [PATCH 08/12] smurf --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e2b4282..506af61 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,7 +4,7 @@ on: workflow_call: push: branches: - - prereleases + - prereleases #SMURF use main before merge release: types: [created] From 560ed693658da322a1d9caca0c5a71e0e23f9ba8 Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 16:41:40 -0600 Subject: [PATCH 09/12] testing --- .github/workflows/test.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 506af61..1e4633d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -40,6 +40,8 @@ jobs: needs: test steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: actions/setup-go@v5 with: go-version-file: go.mod From 24cf03fec47f9493703cdc8c045c6751cf814925 Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 16:49:42 -0600 Subject: [PATCH 10/12] testing --- .github/workflows/test.yaml | 2 +- Makefile | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1e4633d..80333e1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -41,7 +41,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 0 #required to be able to generate prerelease tags - uses: actions/setup-go@v5 with: go-version-file: go.mod diff --git a/Makefile b/Makefile index 0baf1df..17d3073 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,12 @@ else ifeq ($(GOARCH),arm64) LINUX_ARCH = aarch64 endif -ifeq ($(shell git status -s),) +#ifeq ($(shell git status -s),) ifeq ($(shell git branch --show-current),prereleases) #SMURF use main before merge LAST_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null) COMMITS_SINCE_TAG := $(shell git rev-list $(LAST_TAG)..HEAD --count 2>/dev/null) BASE_VERSION := $(shell echo $(LAST_TAG) | cut -c2-) - NEXT_VERSION := $(shell echo $(BASE_VERSION) | awk -F. '{$$2+=1; $$3=0;}1' OFS=.) + NEXT_VERSION := $(shell echo $(BASE_VERSION) | awk -F. '{$$3+=1}1' OFS=.) ifeq ($(COMMITS_SINCE_TAG),0) TAG_VERSION ?= $(BASE_VERSION) else @@ -19,7 +19,7 @@ ifeq ($(shell git status -s),) endif endif GIT_REVISION = $(shell git rev-parse HEAD | tr -d '\n') -endif +#endif ifeq ($(TAG_VERSION),) PATH_VERSION = custom else @@ -46,6 +46,9 @@ amd64: bin/viam-agent-$(PATH_VERSION)-$(LINUX_ARCH): go.* *.go */*.go */*/*.go *.service Makefile go build -o $@ -trimpath -tags $(TAGS) -ldflags $(LDFLAGS) ./cmd/viam-agent/main.go echo $(PATH_VERSION) | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$$' && cp $@ bin/viam-agent-stable-$(LINUX_ARCH) || true + git branch --show-current + + .PHONY: clean clean: From 57745867e4160bb2699a0ed357e1740c350b6b29 Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 16:52:55 -0600 Subject: [PATCH 11/12] testing --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index 17d3073..55d8f56 100644 --- a/Makefile +++ b/Makefile @@ -46,9 +46,6 @@ amd64: bin/viam-agent-$(PATH_VERSION)-$(LINUX_ARCH): go.* *.go */*.go */*/*.go *.service Makefile go build -o $@ -trimpath -tags $(TAGS) -ldflags $(LDFLAGS) ./cmd/viam-agent/main.go echo $(PATH_VERSION) | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$$' && cp $@ bin/viam-agent-stable-$(LINUX_ARCH) || true - git branch --show-current - - .PHONY: clean clean: From ce977bc8a5fa0ee973498f342b330c5b023740c6 Mon Sep 17 00:00:00 2001 From: James Otting Date: Fri, 21 Feb 2025 17:04:41 -0600 Subject: [PATCH 12/12] Hopefully final-ish --- .github/workflows/test.yaml | 14 ++++++++------ Makefile | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 80333e1..138c2a3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,13 +4,13 @@ on: workflow_call: push: branches: - - prereleases #SMURF use main before merge + - main release: types: [created] jobs: test: - name: Lint and Test Build + name: Lint, Test, Build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -36,7 +36,7 @@ jobs: build: name: Build and Upload runs-on: ubuntu-latest - if: github.ref == 'refs/heads/prereleases' || github.event_name == 'release' + if: github.ref == 'refs/heads/main' || github.event_name == 'release' needs: test steps: - uses: actions/checkout@v4 @@ -51,6 +51,8 @@ jobs: - uses: google-github-actions/setup-gcloud@v2 - name: Build run: make all - - name: Upload to GCS - run: | - gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-* preinstall.sh install.sh uninstall.sh gs://packages.viam.com/temp/prerelease/ #SMURF use real before merge + - name: Upload binaries to GCS + run: gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-* gs://packages.viam.com/temp/prerelease/ #TODO use real target after live testing + - name: "Upload install scripts to GCS" + if: github.event_name == 'release' + run: gsutil -h "Cache-Control:no-cache" cp preinstall.sh install.sh uninstall.sh gs://packages.viam.com/temp/prerelease/ #TODO use real target after live testing diff --git a/Makefile b/Makefile index 55d8f56..34fca6c 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ else ifeq ($(GOARCH),arm64) LINUX_ARCH = aarch64 endif -#ifeq ($(shell git status -s),) - ifeq ($(shell git branch --show-current),prereleases) #SMURF use main before merge +ifeq ($(shell git status -s),) + ifeq ($(shell git branch --show-current),main) LAST_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null) COMMITS_SINCE_TAG := $(shell git rev-list $(LAST_TAG)..HEAD --count 2>/dev/null) BASE_VERSION := $(shell echo $(LAST_TAG) | cut -c2-) @@ -19,7 +19,7 @@ endif endif endif GIT_REVISION = $(shell git rev-parse HEAD | tr -d '\n') -#endif +endif ifeq ($(TAG_VERSION),) PATH_VERSION = custom else