-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate releases and update README.md
- Loading branch information
1 parent
683c4b1
commit fbecd95
Showing
4 changed files
with
246 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
build_linux: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.19' | ||
|
||
- name: Build Linux | ||
run: 'make release' | ||
|
||
- name: Upload Linux Build | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: linux_build_${{ github.run_id }} | ||
path: build | ||
|
||
build_darwin: | ||
runs-on: macos-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.19' | ||
|
||
- name: Build Darwin | ||
run: 'make release' | ||
|
||
- name: Upload Darwin Build | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: darwin_build_${{ github.run_id }} | ||
path: build | ||
|
||
release: | ||
runs-on: ubuntu-latest | ||
needs: [build_linux, build_darwin] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Download Linux Build | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: linux_build_${{ github.run_id }} | ||
|
||
- name: Download Darwin Build | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: darwin_build_${{ github.run_id }} | ||
|
||
- name: Upload Release Assets | ||
id: upload_release_assets | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: '*.zip' | ||
tag: ${{ github.ref }} | ||
overwrite: true | ||
file_glob: true | ||
|
||
update_latest: | ||
runs-on: ubuntu-latest | ||
needs: [release] | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.19' | ||
- name: Update go package to latest | ||
run: go install github.com/robgonnella/ops@"${GITHUB_REF#refs/tags/}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,109 @@ | ||
PREFIX = $(shell pwd)/build | ||
#### Vars #### | ||
|
||
platform = $(shell uname -s) | ||
|
||
prefix = $(shell pwd)/build | ||
|
||
app_name = ops | ||
|
||
go_deps = $(shell find . -name '*.go') | ||
|
||
tag = $(shell git describe --tags $(shell git rev-list --tags --max-count=1)) | ||
|
||
flags = -ldflags '-s -w' | ||
|
||
#### Build Objects #### | ||
component = $(app_name)_$(tag) | ||
component_path = $(prefix)/$(component) | ||
|
||
linux_objects = $(component_path)_linux_amd64 \ | ||
$(component_path)_linux_arm_5 \ | ||
$(component_path)_linux_arm_6 \ | ||
$(component_path)_linux_arm_7 \ | ||
$(component_path)_linux_arm64 | ||
|
||
darwin_object = $(component_path)_darwin_amd64 \ | ||
$(component_path)_darwin_arm64 | ||
|
||
#### Gather Objects #### | ||
|
||
ifeq ($(platform),Linux) | ||
objects := $(linux_objects) | ||
else | ||
objects := $(darwin_object) | ||
endif | ||
|
||
#### Zip File Objects #### | ||
$(foreach o,$(objects), $(eval zips += $(o).zip)) | ||
|
||
#### Helper Functions #### | ||
|
||
define get_goos | ||
$(word 3, $(subst _, ,$1)) | ||
endef | ||
|
||
define get_goarch | ||
$(word 4, $(subst _, ,$1)) | ||
endef | ||
|
||
define get_goarm | ||
$(word 5, $(subst _, ,$1)) | ||
endef | ||
|
||
#### Rules Section #### | ||
|
||
# builds main executable | ||
.PHONY: all | ||
all: $(PREFIX)/ops | ||
all: $(app_name) | ||
|
||
$(PREFIX)/ops: $(go_deps) | ||
cd cli && go build -ldflags '-s -w' -o $(@) | ||
# builds main executable | ||
$(prefix)/$(app_name): $(go_deps) | ||
go build $(flags) -o $(@) | ||
|
||
$(PREFIX)/ops-dev: $(go_deps) | ||
cd cli && go build -race -ldflags '-s -w' -o $(@) | ||
# build main executable | ||
.PHONY: $(app_name) | ||
$(app_name): $(prefix)/$(app_name) | ||
|
||
.PHONY: ops | ||
ops: $(PREFIX)/ops | ||
# build develpment version of main executable | ||
$(prefix)/$(app_name)-dev: $(go_deps) | ||
go build -race $(flags) -o $(@) | ||
|
||
# build develpment version of main executable | ||
.PHONY: dev | ||
dev: $(PREFIX)/ops-dev | ||
dev: $(prefix)/$(app_name)-dev | ||
|
||
# installs main executable in user's default bin for golang | ||
.PHONY: install | ||
install: | ||
go install $(flags) | ||
|
||
# cross compiles binaries for linux and darwin | ||
$(objects): $(go_deps) | ||
$(eval goos=$(call get_goos, $(@))) | ||
$(eval goarch=$(call get_goarch, $(@))) | ||
$(eval goarm=$(call get_goarm, $(@))) | ||
GOOS=$(goos) GOARCH=$(goarch) GOARM=$(goarm) go build $(flags) -o $(@) | ||
|
||
# creates zips of pre-built binaries | ||
$(zips): $(objects) | ||
zip -j $(@) $(@:.zip=) | ||
|
||
# generates a relase of all pre-built binaries | ||
.PHONY: release | ||
release: $(zips) | ||
|
||
# run tests | ||
.PHONY: test | ||
test: | ||
go test -v -race ./... | ||
|
||
# generate mocks | ||
.PHONY: mock | ||
mock: | ||
go generate ./... | ||
|
||
# remove buid directory and installed executable | ||
.PHONY: clean | ||
clean: | ||
rm -rf $(PREFIX) | ||
rm -f $(GOPATH)/bin/$(app_name) | ||
rm -rf $(prefix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.