From c7040d445e2e35cc3106acf11b8ecdfee48bbd6d Mon Sep 17 00:00:00 2001 From: Nick Albury Date: Sun, 10 Jan 2021 16:34:00 -0800 Subject: [PATCH] Makefile, build CI and build/install README updates --- .github/workflows/release.yml | 27 +++++++++++++++ .github/workflows/{main.yml => test.yml} | 18 ++++++++-- .gitignore | 1 + Makefile | 43 ++++++++++++++++++++++++ README.md | 20 +++++++++-- cmd/root.go | 2 +- 6 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/release.yml rename .github/workflows/{main.yml => test.yml} (56%) create mode 100644 Makefile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0e84f80 --- /dev/null +++ b/.github/workflows/release.yml @@ -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}" diff --git a/.github/workflows/main.yml b/.github/workflows/test.yml similarity index 56% rename from .github/workflows/main.yml rename to .github/workflows/test.yml index 87a0cdc..dfc7968 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/.gitignore b/.gitignore index 1377554..85f404f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.swp +build/* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ed38070 --- /dev/null +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index c64118b..6f54a55 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmd/root.go b/cmd/root.go index 40b7c24..7066c42 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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.`,