Skip to content

Commit 75deec7

Browse files
authored
[RSDK-7007] Add Manifest Generation in CI (#78)
1 parent 9c29ad5 commit 75deec7

File tree

5 files changed

+121
-35
lines changed

5 files changed

+121
-35
lines changed

.github/workflows/workflow.yaml

+12-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Test
3636
run: make test
3737
- name: Build
38-
run: make debug-workflow all
38+
run: make all
3939

4040
build:
4141
name: Build and Upload
@@ -50,13 +50,18 @@ jobs:
5050
with:
5151
go-version-file: go.mod
5252
- name: Build
53-
run: make debug-workflow all
54-
- uses: google-github-actions/auth@v2 # This BREAKS the git checkout/tags/history, so must run after builds!
53+
run: make all manifest
54+
- uses: google-github-actions/auth@v2
5555
with:
5656
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
5757
- uses: google-github-actions/setup-gcloud@v2
58-
- name: Upload binaries to GCS
59-
run: gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-* gs://packages.viam.com/temp/prerelease/ #TODO use real target after live testing
60-
- name: "Upload install scripts to GCS"
58+
- name: Upload binaries to GCS (Release)
6159
if: github.event_name == 'release'
62-
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
60+
run: |
61+
gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-* install.sh uninstall.sh preinstall.sh gs://packages.viam.com/apps/viam-agent/
62+
gsutil cp etc/viam-agent-*.json gs://packages.viam.com/apps/viam-subsystems/
63+
- name: Upload binaries to GCS (Prerelease)
64+
if: github.event_name != 'release'
65+
run: |
66+
gsutil -h "Cache-Control:no-cache" cp bin/viam-agent-* gs://packages.viam.com/apps/viam-agent/prerelease/
67+
gsutil cp etc/viam-agent-*.json gs://packages.viam.com/apps/viam-subsystems/

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
bin/
2+
etc/
3+
4+
# GCP's auth action adds this in CI, dirtying the tree
5+
gha-creds-*.json

Makefile

+10-28
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,8 @@ else ifeq ($(GOARCH),arm64)
66
LINUX_ARCH = aarch64
77
endif
88

9-
GITHUB_REF_NAME ?= $(shell git branch --show-current)
10-
SHOULD_PUBLISH = $(shell echo $(GITHUB_REF_NAME) | grep -qE '^(main|v[0-9]+\.[0-9]+\.[0-9]+)$$' && echo true)
11-
12-
ifeq ($(shell git status -s),)
13-
ifeq ($(SHOULD_PUBLISH),true)
14-
LAST_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null)
15-
COMMITS_SINCE_TAG := $(shell git rev-list $(LAST_TAG)..HEAD --count 2>/dev/null)
16-
BASE_VERSION := $(shell echo $(LAST_TAG) | cut -c2-)
17-
NEXT_VERSION := $(shell echo $(BASE_VERSION) | awk -F. '{$$3+=1}1' OFS=.)
18-
ifeq ($(COMMITS_SINCE_TAG),0)
19-
TAG_VERSION ?= $(BASE_VERSION)
20-
else
21-
TAG_VERSION ?= $(NEXT_VERSION)-dev.$(COMMITS_SINCE_TAG)
22-
endif
23-
endif
24-
GIT_REVISION = $(shell git rev-parse HEAD | tr -d '\n')
25-
endif
9+
GIT_REVISION = $(shell git rev-parse HEAD)
10+
TAG_VERSION ?= $(shell ./dev-version.sh | sed 's/^v//')
2611
ifeq ($(TAG_VERSION),)
2712
PATH_VERSION = custom
2813
else
@@ -35,16 +20,6 @@ TAGS = osusergo,netgo
3520

3621
.DEFAULT_GOAL := bin/viam-agent-$(PATH_VERSION)-$(LINUX_ARCH)
3722

38-
.PHONY: debug-workflow
39-
debug-workflow:
40-
echo GITHUB_REF_NAME $(GITHUB_REF_NAME)
41-
echo SHOULD_PUBLISH $(SHOULD_PUBLISH)
42-
echo TAG_VERSION $(TAG_VERSION)
43-
echo PATH_VERSION $(PATH_VERSION)
44-
echo GIT_REVISION $(GIT_REVISION)
45-
echo LAST_TAG $(LAST_TAG)
46-
echo COMMITS_SINCE_TAG $(COMMITS_SINCE_TAG)
47-
4823
.PHONY: all
4924
all: amd64 arm64
5025

@@ -76,10 +51,17 @@ lint: bin/golangci-lint
7651
test:
7752
go test -race ./...
7853

54+
.PHONY: manifest
55+
manifest: bin/viam-agent-$(PATH_VERSION)-x86_64 bin/viam-agent-$(PATH_VERSION)-aarch64
56+
echo $(PATH_VERSION) | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+' || exit 1
57+
./manifest.sh bin/viam-agent-$(PATH_VERSION)-x86_64
58+
./manifest.sh bin/viam-agent-$(PATH_VERSION)-aarch64
59+
7960
.PHONY: upload-stable
80-
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
61+
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 manifest
8162
echo $(PATH_VERSION) | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$$' || exit 1
8263
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/
64+
gsutil cp etc/viam-agent-$(PATH_VERSION)-x86_64.json etc/viam-agent-$(PATH_VERSION)-aarch64.json gs://packages.viam.com/apps/viam-subsystems/
8365

8466
.PHONY: upload-installer
8567
upload-installer:

dev-version.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
# Exit with a blank if tree is dirty
4+
if [ -n "$(git status -s)" ]; then
5+
exit 0
6+
fi
7+
8+
# See if we have a direct tag
9+
DIRECT_TAG=$(git tag --points-at | sort -Vr | head -n1)
10+
if [ -n "$DIRECT_TAG" ]; then
11+
echo ${DIRECT_TAG}
12+
exit 0
13+
fi
14+
15+
if [ -z "$GITHUB_REF_NAME" ]; then
16+
GITHUB_REF_NAME=$(git rev-parse --abbrev-ref HEAD)
17+
fi
18+
19+
# If we're not on main, we have no (automated) version to create
20+
if [ "$GITHUB_REF_NAME" != "main" ]; then
21+
exit 0
22+
fi
23+
24+
# If we don't have a direct tag, use the most recent non-RC tag
25+
DESC=$(git describe --tags --match="v*" --exclude="*-rc*" --long | sed 's/^v//')
26+
27+
BASE_VERSION=$(echo "$DESC" | cut -d'-' -f1)
28+
COMMITS_SINCE_TAG=$(echo "$DESC" | cut -d'-' -f2)
29+
30+
# Calculate next version by incrementing patch number
31+
NEXT_VERSION=$(echo "$BASE_VERSION" | awk -F. '{$3+=1}1' OFS=.)
32+
33+
# Set TAG_VERSION based on commits since last tag
34+
if [ "$COMMITS_SINCE_TAG" -eq 0 ]; then
35+
TAG_VERSION="$BASE_VERSION"
36+
else
37+
TAG_VERSION="${NEXT_VERSION}-dev.${COMMITS_SINCE_TAG}"
38+
fi
39+
40+
# Set PATH_VERSION based on TAG_VERSION
41+
PATH_VERSION="v${TAG_VERSION}"
42+
43+
echo ${PATH_VERSION}

manifest.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# Check if binary path is provided
4+
if [ $# -ne 1 ]; then
5+
echo "Usage: $0 <path-to-binary>"
6+
exit 1
7+
fi
8+
9+
BINARY_PATH="$1"
10+
BINARY_NAME=$(basename "$BINARY_PATH")
11+
12+
# Extract version from binary name
13+
VERSION=$(echo "$BINARY_NAME" | sed -E 's/viam-agent-v([0-9]+\.[0-9]+\.[0-9]+(-dev\.[0-9]+)?).*/\1/')
14+
15+
# Determine if this is a prerelease
16+
if [[ "$VERSION" == *"-dev"* ]]; then
17+
PRERELEASE="prerelease/"
18+
fi
19+
20+
# Set platform based on architecture in binary name
21+
if [[ "$BINARY_NAME" == *"x86_64"* ]]; then
22+
ARCH="amd64"
23+
elif [[ "$BINARY_NAME" == *"aarch64"* ]]; then
24+
ARCH="arm64"
25+
else
26+
echo "Unknown architecture in binary name"
27+
exit 1
28+
fi
29+
30+
# Set OS based on binary name
31+
OS="linux"
32+
if [[ "$BINARY_NAME" == *"windows"* ]]; then
33+
OS="windows"
34+
fi
35+
36+
# Set platform
37+
PLATFORM="${OS}/${ARCH}"
38+
39+
# Calculate SHA256
40+
SHA256=$(sha256sum "$BINARY_PATH" | cut -d' ' -f1)
41+
42+
# Generate json manifest with binary-specific name
43+
mkdir -p etc
44+
cat > "etc/${BINARY_NAME}.json" << EOF
45+
{
46+
"subsystem": "viam-agent",
47+
"version": "$VERSION",
48+
"platform": "$PLATFORM",
49+
"upload-path": "packages.viam.com/apps/viam-agent/${PRERELEASE}${BINARY_NAME}",
50+
"sha256": "$SHA256"
51+
}
52+
EOF

0 commit comments

Comments
 (0)