Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit f11304b

Browse files
committed
Adds github fmt, lint, test ci
1 parent 025e1bd commit f11304b

File tree

6 files changed

+79
-3
lines changed

6 files changed

+79
-3
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- name: Checkout
1010
uses: actions/checkout@v1
1111
- name: Build
12-
run: ./ci/build.sh
12+
run: ./ci/steps/build.sh
1313
- name: Upload
1414
uses: actions/upload-artifact@v2
1515
with:

.github/workflows/test.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: ci
2+
on: [push, pull_request]
3+
4+
jobs:
5+
fmt:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v1
9+
- uses: actions/cache@v1
10+
with:
11+
path: ~/go/pkg/mod
12+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
13+
restore-keys: |
14+
${{ runner.os }}-go-
15+
- name: fmt
16+
uses: ./ci/image
17+
with:
18+
args: ./ci/steps/fmt.sh
19+
lint:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v1
23+
- uses: actions/cache@v1
24+
with:
25+
path: ~/go/pkg/mod
26+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27+
restore-keys: |
28+
${{ runner.os }}-go-
29+
- name: lint
30+
uses: ./ci/image
31+
with:
32+
args: ./ci/steps/lint.sh
33+
test:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v1
37+
- uses: actions/cache@v1
38+
with:
39+
path: ~/go/pkg/mod
40+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
41+
restore-keys: |
42+
${{ runner.os }}-go-
43+
- name: test
44+
uses: ./ci/image
45+
with:
46+
args: go test ./...

ci/image/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM golang:1
2+
3+
ENV GOFLAGS="-mod=readonly"
4+
ENV CI=true
5+
6+
RUN go get golang.org/x/tools/cmd/goimports
7+
RUN go get golang.org/x/lint/golint
8+
RUN go get github.com/mattn/goveralls

ci/build.sh renamed to ci/steps/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ mkdir -p bin
1414

1515
build(){
1616
tmpdir=$(mktemp -d)
17-
go build -ldflags "-s -w -X main.version=${tag}" -o "$tmpdir/coder" ../cmd/coder
17+
go build -ldflags "-s -w -X main.version=${tag}" -o "$tmpdir/coder" ../../cmd/coder
1818

1919
pushd "$tmpdir"
2020
tarname="coder-cli-$GOOS-$GOARCH.tar.gz"
2121
tar -czf "$tarname" coder
2222
popd
2323

24-
cp "$tmpdir/$tarname" bin
24+
cp "$tmpdir/$tarname" ../bin
2525
rm -rf "$tmpdir"
2626
}
2727

ci/steps/fmt.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
echo "Formatting..."
3+
4+
go mod tidy
5+
gofmt -w -s .
6+
goimports -w "-local=$$(go list -m)" .
7+
8+
if [ "$CI" != "" ]; then
9+
if [[ $(git ls-files --other --modified --exclude-standard) != "" ]]; then
10+
echo "Files need generation or are formatted incorrectly:"
11+
git -c color.ui=always status | grep --color=no '\e\[31m'
12+
echo "Please run the following locally:"
13+
echo " ./ci/fmt.sh"
14+
exit 1
15+
fi
16+
fi

ci/steps/lint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
echo "Linting..."
4+
5+
go vet ./...
6+
golint -set_exit_status ./...

0 commit comments

Comments
 (0)