Skip to content

Commit fd888d3

Browse files
committed
Initial commit
0 parents  commit fd888d3

File tree

11 files changed

+905
-0
lines changed

11 files changed

+905
-0
lines changed

.github/workflows/release.yml

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build:
10+
name: Release
11+
runs-on: ubuntu-18.04
12+
steps:
13+
- name: Set up Go 1.14
14+
uses: actions/setup-go@v1
15+
with:
16+
go-version: 1.14
17+
18+
- name: Check out code
19+
uses: actions/checkout@v2
20+
21+
- name: Build All
22+
run: make -j 2 release
23+
24+
- name: Create Release
25+
id: create_release
26+
uses: actions/create-release@v1
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
with:
30+
tag_name: ${{ github.ref }}
31+
release_name: Release ${{ github.ref }}
32+
draft: false
33+
prerelease: false
34+
35+
- name: Upload pcmd-darwin-amd64
36+
uses: actions/upload-release-asset@v1
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
with:
40+
upload_url: ${{ steps.create_release.outputs.upload_url }}
41+
asset_path: ./build/pcmd-darwin-amd64.zip
42+
asset_name: pcmd-darwin-amd64.zip
43+
asset_content_type: application/zip
44+
45+
- name: Upload pcmd-linux-amd64
46+
uses: actions/upload-release-asset@v1
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
with:
50+
upload_url: ${{ steps.create_release.outputs.upload_url }}
51+
asset_path: ./build/pcmd-linux-amd64.zip
52+
asset_name: pcmd-linux-amd64.zip
53+
asset_content_type: application/zip
54+
55+
- name: Upload pcmd-linux-386
56+
uses: actions/upload-release-asset@v1
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
with:
60+
upload_url: ${{ steps.create_release.outputs.upload_url }}
61+
asset_path: ./build/pcmd-linux-386.zip
62+
asset_name: pcmd-linux-386.zip
63+
asset_content_type: application/zip
64+
65+
- name: Upload pcmd-linux-arm64
66+
uses: actions/upload-release-asset@v1
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
with:
70+
upload_url: ${{ steps.create_release.outputs.upload_url }}
71+
asset_path: ./build/pcmd-linux-arm64.zip
72+
asset_name: pcmd-linux-arm64.zip
73+
asset_content_type: application/zip
74+
75+
- name: Upload pcmd-linux-arm
76+
uses: actions/upload-release-asset@v1
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
with:
80+
upload_url: ${{ steps.create_release.outputs.upload_url }}
81+
asset_path: ./build/pcmd-linux-arm.zip
82+
asset_name: pcmd-linux-arm.zip
83+
asset_content_type: application/zip
84+
85+
- name: Upload pcmd-freebsd-amd64
86+
uses: actions/upload-release-asset@v1
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
with:
90+
upload_url: ${{ steps.create_release.outputs.upload_url }}
91+
asset_path: ./build/pcmd-freebsd-amd64.zip
92+
asset_name: pcmd-freebsd-amd64.zip
93+
asset_content_type: application/zip
94+
95+
- name: Upload pcmd-freebsd-386
96+
uses: actions/upload-release-asset@v1
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
with:
100+
upload_url: ${{ steps.create_release.outputs.upload_url }}
101+
asset_path: ./build/pcmd-freebsd-386.zip
102+
asset_name: pcmd-freebsd-386.zip
103+
asset_content_type: application/zip
104+
105+
- name: Upload pcmd-freebsd-arm
106+
uses: actions/upload-release-asset@v1
107+
env:
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
with:
110+
upload_url: ${{ steps.create_release.outputs.upload_url }}
111+
asset_path: ./build/pcmd-freebsd-arm.zip
112+
asset_name: pcmd-freebsd-arm.zip
113+
asset_content_type: application/zip
114+
115+
- name: Upload pcmd-openbsd-amd64
116+
uses: actions/upload-release-asset@v1
117+
env:
118+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119+
with:
120+
upload_url: ${{ steps.create_release.outputs.upload_url }}
121+
asset_path: ./build/pcmd-openbsd-amd64.zip
122+
asset_name: pcmd-openbsd-amd64.zip
123+
asset_content_type: application/zip
124+
125+
- name: Upload pcmd-openbsd-386
126+
uses: actions/upload-release-asset@v1
127+
env:
128+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129+
with:
130+
upload_url: ${{ steps.create_release.outputs.upload_url }}
131+
asset_path: ./build/pcmd-openbsd-386.zip
132+
asset_name: pcmd-openbsd-386.zip
133+
asset_content_type: application/zip
134+
135+
- name: Upload pcmd-openbsd-arm
136+
uses: actions/upload-release-asset@v1
137+
env:
138+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139+
with:
140+
upload_url: ${{ steps.create_release.outputs.upload_url }}
141+
asset_path: ./build/pcmd-openbsd-arm.zip
142+
asset_name: pcmd-openbsd-arm.zip
143+
asset_content_type: application/zip
144+
145+
- name: Upload pcmd-netbsd-amd64
146+
uses: actions/upload-release-asset@v1
147+
env:
148+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149+
with:
150+
upload_url: ${{ steps.create_release.outputs.upload_url }}
151+
asset_path: ./build/pcmd-netbsd-amd64.zip
152+
asset_name: pcmd-netbsd-amd64.zip
153+
asset_content_type: application/zip
154+
155+
- name: Upload pcmd-netbsd-386
156+
uses: actions/upload-release-asset@v1
157+
env:
158+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
159+
with:
160+
upload_url: ${{ steps.create_release.outputs.upload_url }}
161+
asset_path: ./build/pcmd-netbsd-386.zip
162+
asset_name: pcmd-netbsd-386.zip
163+
asset_content_type: application/zip
164+
165+
- name: Upload pcmd-netbsd-arm
166+
uses: actions/upload-release-asset@v1
167+
env:
168+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
169+
with:
170+
upload_url: ${{ steps.create_release.outputs.upload_url }}
171+
asset_path: ./build/pcmd-netbsd-arm.zip
172+
asset_name: pcmd-netbsd-arm.zip
173+
asset_content_type: application/zip

.github/workflows/test.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
build:
11+
name: Test
12+
runs-on: ubuntu-18.04
13+
steps:
14+
- name: Set up Go 1.14
15+
uses: actions/setup-go@v1
16+
with:
17+
go-version: 1.14
18+
19+
- name: Check out code
20+
uses: actions/checkout@v2
21+
22+
- name: Set $GOCACHE
23+
run: echo "::set-env name=GOCACHE::$(go env GOCACHE)"
24+
25+
- name: Cache $GOCACHE
26+
uses: actions/cache@v1
27+
env:
28+
cache-name: GOCACHE
29+
with:
30+
path: ${{ env.GOCACHE }}
31+
key: ${{ runner.os }}-${{ env.cache-name }}
32+
33+
- name: Test
34+
run: make -j 2 test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
.pcmd

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2020 Andrew Hamon
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Populate build and version dynamically. These are extracted as scripts to make
2+
# them more easily accessible from Github Actions workflows.
3+
BUILD:=$(shell bin/get-build)
4+
VERSION:=$(shell bin/get-version)
5+
6+
# LDFLAGS is used to inject version information into the binary build. No need
7+
# to keep multiple constants in sync.
8+
LDFLAGS:=-ldflags "-X main.Version=$(VERSION) -X main.Build=$(BUILD)"
9+
10+
.PHONY: all build release test clean
11+
.SILENT: clean
12+
.PRECIOUS: build/%/pcmd build/%/README.md build/%/LICENSE
13+
14+
################################################################################
15+
############################### Main Entrypoints ###############################
16+
################################################################################
17+
18+
all: build test
19+
20+
build: build/pcmd
21+
22+
release: \
23+
build/pcmd-darwin-amd64.zip \
24+
build/pcmd-linux-amd64.zip \
25+
build/pcmd-linux-386.zip \
26+
build/pcmd-linux-arm64.zip \
27+
build/pcmd-linux-arm.zip \
28+
build/pcmd-freebsd-amd64.zip \
29+
build/pcmd-freebsd-386.zip \
30+
build/pcmd-freebsd-arm.zip \
31+
build/pcmd-openbsd-amd64.zip \
32+
build/pcmd-openbsd-386.zip \
33+
build/pcmd-openbsd-arm.zip \
34+
build/pcmd-netbsd-amd64.zip \
35+
build/pcmd-netbsd-386.zip \
36+
build/pcmd-netbsd-arm.zip \
37+
38+
test: $(GOFILES)
39+
go test ${LDFLAGS} ./...
40+
41+
clean:
42+
rm -r build .pcmd 2> /dev/null || :
43+
44+
################################################################################
45+
################################ Binary Targets ################################
46+
################################################################################
47+
48+
GO_FILES:=$(wildcard *.go)
49+
50+
build/pcmd: $(GO_FILES)
51+
go build ${LDFLAGS} -o build/pcmd .
52+
53+
# Given the pattern build/pcmd-GOOS-GOARCH, create some helpers to extract
54+
# GOOS and GOARCH
55+
go-os = $(word 2,$(subst -, ,$(word 2,$(subst /, ,$1))))
56+
go-arch = $(word 3,$(subst -, ,$(word 2,$(subst /, ,$1))))
57+
58+
build/%/pcmd: $(GO_FILES)
59+
GOOS=$(call go-os,$@) GOARCH=$(call go-arch,$@) go build ${LDFLAGS} -o $@ .
60+
61+
################################################################################
62+
############################### Release Bundles ################################
63+
################################################################################
64+
65+
build/%/README.md: README.md
66+
mkdir -p $(shell dirname $@)
67+
cp README.md $@
68+
69+
build/%/LICENSE: LICENSE
70+
mkdir -p $(shell dirname $@)
71+
cp LICENSE $@
72+
73+
build/%.zip: build/%/pcmd build/%/README.md build/%/LICENSE
74+
cd build && zip -r $(patsubst build/%.zip,%,$@) $(patsubst build/%.zip,%,$@)

0 commit comments

Comments
 (0)