Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Commit

Permalink
Add CI config (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 committed Apr 20, 2020
1 parent cebccd8 commit cea2cbe
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: 2
jobs:
build:
docker:
- image: cimg/go:1.14
steps:
- run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0
- checkout
- restore_cache:
keys:
- go-sum-{{ checksum "go.sum" }}
- run:
command: go get -v github.com/int128/goxzst github.com/int128/ghcp
working_directory: .circleci
- run: make check
- run: make dist
- run: |
if [ "$CIRCLE_TAG" ]; then
make release
fi
- save_cache:
key: go-sum-{{ checksum "go.sum" }}
paths:
- ~/go/pkg

workflows:
version: 2
all:
jobs:
- build:
context: open-source
filters:
tags:
only: /.*/
3 changes: 3 additions & 0 deletions .circleci/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/int128/awsswitch/.circleci

go 1.14
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/awsswitch
/.idea/
/dist/output/
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# CircleCI specific variables
CIRCLE_TAG ?= latest
GITHUB_USERNAME := $(CIRCLE_PROJECT_USERNAME)
GITHUB_REPONAME := $(CIRCLE_PROJECT_REPONAME)

TARGET := awsswitch
TARGET_OSARCH := linux_amd64 darwin_amd64 windows_amd64 linux_arm linux_arm64
VERSION ?= $(CIRCLE_TAG)
LDFLAGS := -X main.version=$(VERSION)

all: $(TARGET)

$(TARGET): $(wildcard **/*.go)
go build -o $@ -ldflags "$(LDFLAGS)"

.PHONY: check
check:
golangci-lint run

.PHONY: dist
dist: dist/output
dist/output:
# make the zip files for GitHub Releases
VERSION=$(VERSION) CGO_ENABLED=0 goxzst -d dist/output -i "LICENSE" -o "$(TARGET)" -osarch "$(TARGET_OSARCH)" -t "dist/awsswitch.rb" -- -ldflags "$(LDFLAGS)"
# test the zip file
zipinfo dist/output/awsswitch_linux_amd64.zip

.PHONY: release
release: dist
# publish the binaries
ghcp release -u "$(GITHUB_USERNAME)" -r "$(GITHUB_REPONAME)" -t "$(VERSION)" dist/output/
# publish the Homebrew formula
ghcp commit -u "$(GITHUB_USERNAME)" -r "homebrew-$(GITHUB_REPONAME)" -b "bump-$(VERSION)" -m "Bump the version to $(VERSION)" -C dist/output/ awsswitch.rb
ghcp pull-request -u "$(GITHUB_USERNAME)" -r "homebrew-$(GITHUB_REPONAME)" -b "bump-$(VERSION)" --title "Bump the version to $(VERSION)"

.PHONY: clean
clean:
-rm $(TARGET)
-rm -r dist/output/
13 changes: 13 additions & 0 deletions dist/awsswitch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Awsswitch < Formula
desc "Export the credentials variables to switch a role with MFA"
homepage "https://github.com/int128/awsswitch"
url "https://github.com/int128/awsswitch/releases/download/{{ env "VERSION" }}/awsswitch_darwin_amd64.zip"
version "{{ env "VERSION" }}"
sha256 "{{ sha256 .darwin_amd64_archive }}"
def install
bin.install "awsswitch"
end
test do
system "#{bin}/awsswitch -h"
end
end

0 comments on commit cea2cbe

Please sign in to comment.