From d54b25d983155889fde45f0d08fc6dfb4e631aeb Mon Sep 17 00:00:00 2001
From: Casey Lee <cplee@nektos.com>
Date: Mon, 24 Feb 2020 15:04:33 -0800
Subject: [PATCH] makefile cleanups

---
 .github/workflows/push.yml | 17 ++++++++++++++++-
 .github/workflows/tag.yml  | 19 -------------------
 Makefile                   | 36 ++++++++++++++----------------------
 3 files changed, 30 insertions(+), 42 deletions(-)
 delete mode 100644 .github/workflows/tag.yml

diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index 66c241a..7abd601 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -5,7 +5,6 @@ jobs:
   lint:
     runs-on: ubuntu-latest
     steps:
-    - run: echo ${{github.ref}}
     - uses: actions/checkout@v2
     - uses: docker://golangci/golangci-lint:v1.23.6
       with:
@@ -24,3 +23,19 @@ jobs:
       env:
         CGO_ENABLED: 0
         GOFLAGS: -mod=vendor
+
+  release:
+    if: startsWith(github.ref, "refs/tags/v")
+    needs: 
+    - lint
+    - test
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+    - name: GoReleaser
+      uses: goreleaser/goreleaser-action@v1
+      with:
+        version: latest
+        args: release --rm-dist
+      env:
+        GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml
deleted file mode 100644
index f258c22..0000000
--- a/.github/workflows/tag.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-name: tag
-on: 
-  push:
-    tags:
-    - 'v*'
-
-jobs:
-  release:
-    if: startsWith(github.ref, "v")
-    runs-on: ubuntu-latest
-    steps:
-    - uses: actions/checkout@v2
-    - name: GoReleaser
-      uses: goreleaser/goreleaser-action@v1
-      with:
-        version: latest
-        args: release --rm-dist
-      env:
-        GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
diff --git a/Makefile b/Makefile
index d3e2387..abd9ec8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,29 +1,21 @@
-LATEST_VERSION := $(shell git tag -l --sort=creatordate | grep "^v[0-9]*.[0-9]*.[0-9]*$$" | tail -1 | cut -c 2-)
-ifeq "$(shell git tag -l v$(LATEST_VERSION) --points-at HEAD)" "v$(LATEST_VERSION)"
-### latest tag points to current commit, this is a release build
-VERSION ?= $(LATEST_VERSION)
-else
-### latest tag points to prior commit, this is a snapshot build
-MAJOR_VERSION := $(word 1, $(subst ., ,$(LATEST_VERSION)))
-MINOR_VERSION := $(word 2, $(subst ., ,$(LATEST_VERSION)))
-PATCH_VERSION := $(word 3, $(subst ., ,$(LATEST_VERSION)))
-VERSION ?= $(MAJOR_VERSION).$(MINOR_VERSION).$(shell echo $$(( $(PATCH_VERSION) + 1)) )-develop
-endif
+VERSION?=$(shell git describe --tags --dirty | cut -c 2-)
 IS_SNAPSHOT = $(if $(findstring -, $(VERSION)),true,false)
-TAG_VERSION = v$(VERSION)
+MAJOR_VERSION = $(word 1, $(subst ., ,$(VERSION)))
+MINOR_VERSION = $(word 2, $(subst ., ,$(VERSION)))
+PATCH_VERSION = $(word 3, $(subst ., ,$(word 1,$(subst -, , $(VERSION)))))
+NEW_VERSION ?= $(MAJOR_VERSION).$(MINOR_VERSION).$(shell echo $$(( $(PATCH_VERSION) + 1)) )
 
 ACT ?= go run main.go
 export GITHUB_TOKEN = $(shell cat ~/.config/github/token)
 
-check:
+build: 
+	go build -ldflags "-X main.version=$(VERSION)" -o dist/local/act main.go
+
+test:
 	$(ACT) -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 
 
-build: check
-	$(eval export SNAPSHOT_VERSION=$(VERSION))
-	$(ACT) -ra build
-
 install: build
-	@cp dist/$(shell go env GOOS)_$(shell go env GOARCH)/act /usr/local/bin/act
+	@cp dist/local/act /usr/local/bin/act
 	@chmod 755 /usr/local/bin/act
 	@act --version
 
@@ -32,7 +24,8 @@ installer:
 	godownloader -r nektos/act -o install.sh
 
 promote: vendor
-	@echo "VERSION:$(VERSION) IS_SNAPSHOT:$(IS_SNAPSHOT) LATEST_VERSION:$(LATEST_VERSION)"
+	@git fetch --tags
+	@echo "VERSION:$(VERSION) IS_SNAPSHOT:$(IS_SNAPSHOT) NEW_VERSION:$(NEW_VERSION)"
 ifeq (false,$(IS_SNAPSHOT))
 	@echo "Unable to promote a non-snapshot"
 	@exit 1
@@ -41,9 +34,8 @@ ifneq ($(shell git status -s),)
 	@echo "Unable to promote a dirty workspace"
 	@exit 1
 endif
-	$(eval NEW_VERSION := $(word 1,$(subst -, , $(TAG_VERSION))))
-	git tag -a -m "releasing $(NEW_VERSION)" $(NEW_VERSION)
-	git push origin $(NEW_VERSION)
+	git tag -a -m "releasing v$(NEW_VERSION)" v$(NEW_VERSION)
+	git push origin v$(NEW_VERSION)
 
 vendor:
 	go mod vendor