Skip to content

Commit

Permalink
fix: Build and Publish
Browse files Browse the repository at this point in the history
  • Loading branch information
rtfpessoa committed Jan 9, 2020
1 parent e7bd671 commit 09871b2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
52 changes: 39 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1

orbs:
codacy: codacy/base@1.0.0
codacy: codacy/base@dev:1.3.0-addworkdircustomizationinversion.cf8a970

jobs:
build: # runs not using Workflows must have a `build` job as entry point
Expand All @@ -16,7 +16,9 @@ jobs:
TEST_RESULTS: /tmp/test-results # path to where test results will be saved

steps: # steps that comprise the `build` job
- checkout
- attach_workspace:
at: /go/src/github.com/codacy/helm-ssm

- run: mkdir -p $TEST_RESULTS # create the test results directory

- restore_cache: # restores saved cache if no changes are detected since last run
Expand All @@ -34,15 +36,10 @@ jobs:
- run: make dist # pull and build dependencies for the project

- run:
name: "Publish Release on GitHub"
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
go get github.com/tcnksm/ghr
VERSION=$(sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml)
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace ${VERSION} ./_dist/
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace latest ./_dist/
fi
- persist_to_workspace:
root: /go/src/github.com/codacy/helm-ssm
paths:
- '*'

- save_cache: # Store cache in the /go/pkg directory
key: v1-pkg-cache
Expand All @@ -56,13 +53,37 @@ jobs:
- store_test_results: # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/
path: /tmp/test-results

publish: # runs not using Workflows must have a `build` job as entry point
docker: # run the steps with Docker
# CircleCI Go images available at: https://hub.docker.com/r/circleci/golang/
- image: circleci/golang:1.12 #
# directory where steps are run. Path must conform to the Go Workspace requirements
working_directory: /go/src/github.com/codacy/helm-ssm
steps: # steps that comprise the `build` job
- attach_workspace:
at: /go/src/github.com/codacy/helm-ssm

- run:
name: "Publish Release on GitHub"
command: |
export VERSION="$(cat .version)"
echo "Publishing version ${VERSION}"
ls -lisah ./_dist/
go get github.com/tcnksm/ghr
if [ "${CIRCLE_BRANCH}" == "master" ]; then
export RELEASE_TAG="latest"
else
export RELEASE_TAG="dev"
fi
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${VERSION} ./_dist/
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${RELEASE_TAG} -replace ./_dist/
workflows:
version: 2
my-workflow:
ci:
jobs:
- codacy/checkout_and_version
- build:
context: CodacyGitHub
requires:
- codacy/checkout_and_version
- codacy/tag_version:
Expand All @@ -74,3 +95,8 @@ workflows:
branches:
only:
- master
- fix-build
- publish:
context: CodacyGitHub
requires:
- tag_version
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
vendor
bin
_dist
_dist
.version

3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HELM_PLUGIN_DIR ?= $(HELM_HOME)/plugins/helm-ssm
HELM_PLUGIN_NAME := helm-ssm
HAS_DEP := $(shell which dep)
DEP_VERSION := v0.5.1
VERSION := $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml)
VERSION := $(shell cat .version)
DIST := $(CURDIR)/_dist
LDFLAGS := "-X main.version=${VERSION}"

Expand Down Expand Up @@ -33,6 +33,7 @@ test: bootstrap
.PHONY: dist
dist:
mkdir -p $(DIST)
sed -i 's/version:.*/version: "'$(VERSION)'"/g' plugin.yaml
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${HELM_PLUGIN_NAME} -ldflags $(LDFLAGS) ./cmd
tar -zcvf $(DIST)/${HELM_PLUGIN_NAME}-linux.tgz ${HELM_PLUGIN_NAME} README.md LICENSE plugin.yaml
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ${HELM_PLUGIN_NAME} -ldflags $(LDFLAGS) ./cmd
Expand Down

0 comments on commit 09871b2

Please sign in to comment.