git » gofer » commit bcf593d

test: Add GitHub Actions configuration

author Alberto Bertogli
2022-10-07 01:06:27 UTC
committer Alberto Bertogli
2022-10-09 11:34:34 UTC
parent 40ca4e0587236c9d9b00abec50074ddf79aed1b2

test: Add GitHub Actions configuration

This patch sets up GitHub Actions, to run tests, coverage reports, and
static checks automatically on each push, and periodically once a week.

.github/workflows/govulncheck.yaml +24 -0
.github/workflows/tests.yaml +47 -0
.gitignore +2 -0
Makefile +1 -1
README.md +3 -0

diff --git a/.github/workflows/govulncheck.yaml b/.github/workflows/govulncheck.yaml
new file mode 100644
index 0000000..2455e16
--- /dev/null
+++ b/.github/workflows/govulncheck.yaml
@@ -0,0 +1,24 @@
+name: "govulncheck"
+
+on:
+  push:
+    branches: [ "master", "next" ]
+  pull_request:
+    # The branches below must be a subset of the branches above
+    branches: [ "master", "next" ]
+  schedule:
+    - cron: '29 21 * * 6'
+
+jobs:
+  govulncheck:
+    runs-on: ubuntu-latest
+    timeout-minutes: 5
+    steps:
+      - uses: actions/checkout@v3
+      - uses: actions/setup-go@v3
+        with:
+          go-version: ">=1.19.2"
+      - name: install govulncheck
+        run: go install golang.org/x/vuln/cmd/govulncheck@latest
+      - name: run govulncheck
+        run: govulncheck ./...
diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml
new file mode 100644
index 0000000..61ae50f
--- /dev/null
+++ b/.github/workflows/tests.yaml
@@ -0,0 +1,47 @@
+name: "tests"
+
+on:
+  push:
+    branches: [ "master", "next" ]
+  pull_request:
+    # The branches below must be a subset of the branches above
+    branches: [ "master", "next" ]
+  schedule:
+    - cron: '29 21 * * 6'
+
+jobs:
+  tests:
+    runs-on: ubuntu-latest
+    timeout-minutes: 5
+    steps:
+      - uses: actions/checkout@v3
+      - uses: actions/setup-go@v3
+        with:
+          go-version: ">=1.19"
+      - name: install cue
+        run: go install cuelang.org/go/cmd/cue@latest
+      - name: install goveralls
+        run: go install github.com/mattn/goveralls@latest
+
+      - name: make test
+        run: make test
+        timeout-minutes: 2
+
+      - name: make cover
+        run: make cover
+        timeout-minutes: 2
+      - name: upload coverage
+        run: goveralls -coverprofile=.cover/all.out -repotoken=${{ secrets.COVERALLS_TOKEN }}
+
+      # Upload the contents of test/ if there are failures, for
+      # troubleshooting. Note we need to tar them first because github has
+      # absurd limitations on file names.
+      - name: tar artifacts
+        if: failure()
+        run: tar -cvf test-dir.tar test/
+      - uses: actions/upload-artifact@v3
+        if: failure()
+        with:
+          name: test-artifacts
+          path: test-dir.tar
+          retention-days: 5
diff --git a/.gitignore b/.gitignore
index 966a8ea..e0a2534 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@
 # Exceptions to the rules above: files we care about that would otherwise be
 # excluded.
 !.gitignore
+!.github
 
 # The binaries.
 /gofer
@@ -15,6 +16,7 @@
 *.yaml
 *.pem
 !test/**/*.yaml
+!.github/**/*.yaml
 
 # Files generated by the performance tests.
 test/testdata/dir/perf*
diff --git a/Makefile b/Makefile
index cda8649..deb8999 100644
--- a/Makefile
+++ b/Makefile
@@ -25,7 +25,7 @@ test: vet
 	setsid -w ./test/test.sh
 
 cover:
-	rm -r .cover/
+	rm -rf .cover/
 	mkdir .cover/
 	go test -tags coverage \
 		-covermode=count \
diff --git a/README.md b/README.md
index e500d97..9e07363 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,9 @@ proxy.
 
 ## Status
 
+[![github tests](https://github.com/albertito/gofer/actions/workflows/tests.yaml/badge.svg)](https://github.com/albertito/gofer/actions)
+[![coverage](https://coveralls.io/repos/github/albertito/gofer/badge.svg?branch=next)](https://coveralls.io/github/albertito/gofer?branch=next)
+
 Gofer is under active development, and breaking changes are expected.
 It is fully functional and being used to serve some small websites.