Skip to content

Commit 7652719

Browse files
authored
Merge pull request #147 from Clever/INFRANG-6696
[INFRANG-6696] Pre-build and release binaries for goci
2 parents a481ed8 + 57f3121 commit 7652719

File tree

5 files changed

+73
-18
lines changed

5 files changed

+73
-18
lines changed

.circleci/config.yml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
version: 2
1+
version: 2.1
22
jobs:
33
build:
44
working_directory: ~/Clever/ci-scripts
55
docker:
6-
- image: cimg/base:stable
6+
- image: cimg/go:1.22
77
environment:
8-
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
9-
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
8+
GOPRIVATE: github.com/Clever/*
109
steps:
11-
- run:
12-
command: cd $HOME && git clone --depth 1 -v https://github.com/Clever/ci-scripts.git && cd ci-scripts && git show --oneline -s
13-
name: Clone ci-scripts
1410
- checkout
15-
- run:
16-
command: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
17-
name: Set up CircleCI artifacts directories
18-
- run: mkdir artifacts
19-
- run: echo "foo" > artifacts/foo.txt
20-
- run:
21-
name: update version
22-
command: |-
23-
echo $CIRCLE_SHA1
24-
echo "${CIRCLE_SHA1:0:7}" > VERSION
25-
- run: ./circleci/github-release $GH_RELEASE_TOKEN artifacts/
11+
- run: make release
12+
- run: if [ "${CIRCLE_BRANCH}" == "master" ]; then ./circleci/github-release $GH_RELEASE_TOKEN artifacts; fi;

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor
22
.vscode
33
bin
44
tmp
5+
artifacts

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PHONY: release
2+
SHELL := /bin/bash
3+
VERSION := $(shell head -n 1 VERSION)
4+
5+
release:
6+
@GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.version=$(VERSION)" \
7+
-o="artifacts/goci-$(VERSION)-linux-amd64" ./cmd/goci
8+
@GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.version=$(VERSION)" \
9+
-o="artifacts/goci-$(VERSION)-darwin-amd64" ./cmd/goci
10+
@GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.version=$(VERSION)" \
11+
-o="artifacts/goci-$(VERSION)-darwin-arm64" ./cmd/goci

VERSION

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
v1.0.0
2+
Begin publishing goci binaries
3+
4+
Previously:
5+
- Call catalogue config with goci
6+
- build with goci
7+
- deploy with goci

circleci/install-goci

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# This script install the latest version of goci for the correct OS and architecture.
4+
5+
# Exit immediately if a command exits with a non-zero status
6+
set -e
7+
8+
GITHUB_TOKEN=$1
9+
if [[ -z $GITHUB_TOKEN ]]; then echo "Missing arg1 GITHUB_TOKEN" && exit 1; fi
10+
11+
# Configuration
12+
REPO="Clever/ci-scripts"
13+
INSTALL_DIR="/usr/local/bin"
14+
15+
# Detect OS and Architecture
16+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
17+
ARCH=$(uname -m)
18+
if [[ "$ARCH" == "x86_64" ]]; then
19+
ARCH="amd64"
20+
fi
21+
22+
# Fetch the latest release
23+
echo "Fetching the latest release from $REPO..."
24+
LATEST_RELEASE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$REPO/releases/latest")
25+
26+
if [ -z "$LATEST_RELEASE" ]; then
27+
echo "Error: No latest release found. Check repository permissions."
28+
exit 1
29+
fi
30+
31+
# Find the asset matching the OS and architecture
32+
ASSET_URL=$(echo "$LATEST_RELEASE" | jq -r ".assets[] | select(.name | test(\"$OS.*$ARCH\")) | .browser_download_url")
33+
34+
if [ -z "$ASSET_URL" ]; then
35+
echo "Error: No matching release asset found for OS=$OS and ARCH=$ARCH."
36+
exit 1
37+
fi
38+
39+
# Download the asset
40+
ASSET_NAME=$(basename "$ASSET_URL")
41+
echo "Downloading $ASSET_NAME..."
42+
curl -L -o "/tmp/$ASSET_NAME" "$ASSET_URL"
43+
44+
# Move the asset to the install directory and make it executable
45+
echo "Installing $ASSET_NAME to $INSTALL_DIR..."
46+
sudo mv "/tmp/$ASSET_NAME" "$INSTALL_DIR/goci"
47+
sudo chmod +x "$INSTALL_DIR/goci"
48+
49+
echo "Installation complete. goci is now available in \$PATH."

0 commit comments

Comments
 (0)