Skip to content

Commit

Permalink
Merge pull request #10 from nalbury/na-build-improvements
Browse files Browse the repository at this point in the history
Makefile, build CI and build/install README updates
  • Loading branch information
nalbury committed Jan 11, 2021
2 parents f72a734 + c7040d4 commit d48778d
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 6 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-20.04
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.13.x
- name: Checkout code
uses: actions/checkout@v2
- name: Create release artifacts
run: VERSION=${GITHUB_REF} make release
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
for f in ./build/artifacts/*
do
[ -f "$f" ] && assets+=(-a "$f")
done
hub release create -m "Release ${GITHUB_REF}" \
"${assets[@]}" "${GITHUB_REF}"
18 changes: 15 additions & 3 deletions .github/workflows/main.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
on: [push, pull_request]
name: Test
on:
push:
branches:
- master
paths-ignore:
- "README.md"
pull_request:
paths-ignore:
- "README.md"
jobs:
test:
strategy:
matrix:
go-version: [1.13.x,1.14.x]
os: [ubuntu-latest, macos-latest]
go-version:
- 1.13.x
- 1.14.x
os:
- ubuntu-20.04
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.swp
build/*
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
GOOS ?= darwin ## OS we're building for (e.g. linux)
GOARCH ?= amd64 ## Arch we're building for (e.g. amd64)
VERSION ?= master ## Version we're releasing

BUILD_PATH = ./build/bin/$(GOOS)/$(GOARCH)
ARTIFACT_PATH = ./build/artifacts

export GO_BUILD=GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(BUILD_PATH)/promql ./
export TAR=tar -czvf $(ARTIFACT_PATH)/promql-$(VERSION)-$(GOOS)-$(GOARCH).tar.gz -C $(BUILD_PATH) promql

help: ## Print Makefile help
@echo "Makefile for promql"
@echo "#### Examples ####"
@echo "Build a linux binary:"
@echo " GOOS=linux make build"
@echo "Build both linux and macOS binaries and create release artifacts:"
@echo " VERSION=v0.2.1 make release"
@echo "#### Environment Variables ####"
@awk '$$4 == "##" {gsub(/\?=./, "", $$0); $$2="(default: "$$2")"; printf "-- %s \n", $$0}' Makefile
@echo "#### Targets ####"
@awk '$$1 ~ /^.*:$$/ {gsub(":", "", $$1);printf "-- %s \n", $$0}' Makefile

setup: ## Setup build/artifact paths.
mkdir -p $(BUILD_PATH)
mkdir -p $(ARTIFACT_PATH)

clean: ## Cleanup build dir
rm -rf ./build/*

build: setup ## Build promql binary
$(GO_BUILD)

build-all: ## Build binaries for linux and macOS
GOOS="darwin" GOARCH="amd64" make build
GOOS="linux" GOARCH="amd64" make build

build-artifact: setup ## Build binary and create release artifact
$(GO_BUILD)
$(TAR)

release: ## Build binaries and create release artifactors for both linux and macOS
GOOS="darwin" GOARCH="amd64" make build-artifact
GOOS="linux" GOARCH="amd64" make build-artifact
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,27 @@ Use "promql [command] --help" for more information about a command.
```

## Installation
Binaries for macOS and Linux can be found on the [Releases page.](https://github.com/nalbury/promql-cli/releases)

They can also be built from source, you'll need golang 1.13.x or higher installed.

First clone the repo and `cd` into it.
```
curl -o /usr/local/bin/promql https://promql-cli.s3.amazonaws.com/latest/macos/promql && chmod +x /usr/local/bin/promql
git clone https://github.com/nalbury/promql-cli.git
cd promql-cli/
```

Specific versions can be installed by replacing `latest` in the URL above with any version tag (e.g. v0.2.0).
Then either use `make`

```
GOOS=linux make build
```

or you can build using `go build`

```
go build -o promql ./
```

## Usage

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func rangeQuery(host, queryString, output string, timeout time.Duration, r v1.Ra

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Version: "v0.2.0",
Version: "v0.2.1",
Use: "promql [query_string]",
Short: "Query prometheus from the command line",
Long: `Query prometheus from the command line for quick analysis.`,
Expand Down

0 comments on commit d48778d

Please sign in to comment.