Skip to content

Commit

Permalink
New job that checks that pkged.go is up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
creker committed Aug 7, 2020
1 parent 49e10b1 commit 0ff9396
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 37 deletions.
88 changes: 57 additions & 31 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,72 @@ name: Go

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
pkger:
name: pkger
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.14
id: go

- name: Install pkger
run: go get github.com/markbates/pkger/cmd/pkger

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: check generated files
run: |
export PATH=$PATH:$(go env GOPATH)/bin
sum_before=$(go run ./cmd/nan/ -checksum)
go generate
sum_after=$(go run ./cmd/nan/ -checksum)
echo "$sum_before"
echo "$sum_after"
if [ "$sum_before" != "$sum_after" ] ; then
exit 2
fi
coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.14
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Calc coverage
run: |
go test -v -covermode=count -coverprofile=coverage.out .
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.14
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Calc coverage
run: |
go test -v -covermode=count -coverprofile=coverage.out .
- name: Convert coverage to lcov
uses: jandelgado/gcov2lcov-action@v1.0.0
with:
- name: Convert coverage to lcov
uses: jandelgado/gcov2lcov-action@v1.0.0
with:
infile: coverage.out
outfile: coverage.lcov

- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v1.0.1
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v1.0.1
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
25 changes: 20 additions & 5 deletions cmd/nan/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"crypto/md5"
"flag"
"fmt"
"io"
Expand All @@ -14,6 +15,7 @@ import (
)

func main() {
checksum := flag.Bool("checksum", false, "calculates checksum over embedded files. Used in CI")
cql := flag.Bool("cql", false, "emit implementation of gocql.Marshaler and gocql.Unmarshaler")
easyjson := flag.Bool("easyjson", false, "emit implementation of easyjson.Marshaler and easyjson.Unmarshaler")
json := flag.Bool("json", false, "emit implementation of json.Marshaler and json.Unmarshaler")
Expand All @@ -31,23 +33,36 @@ func main() {
}

files := []string{pkger.Include("/nan.go"), pkger.Include("/LICENSE")}
if *cql {
if *cql || *checksum {
files = append(files, pkger.Include("/cql.go"))
files = append(files, pkger.Include("/cql_helpers.go"))
}
if *easyjson {
if *easyjson || *checksum {
files = append(files, pkger.Include("/easyjson.go"))
}
if *json {
if *json || *checksum {
files = append(files, pkger.Include("/json.go"))
}
if *jsoniter {
if *jsoniter || *checksum {
files = append(files, pkger.Include("/jsoniter.go"))
}
if *sql {
if *sql || *checksum {
files = append(files, pkger.Include("/sql.go"))
files = append(files, pkger.Include("/sql_convert.go"))
}
if *checksum {
sum := md5.New()
for i := range files {
in, err := pkger.Open(files[i])
if err != nil {
panic(err)
}
io.Copy(sum, in)
in.Close()
}
fmt.Printf("%x\n", sum.Sum(nil))
return
}

for i := range files {
_, filename := filepath.Split(files[i])
Expand Down

0 comments on commit 0ff9396

Please sign in to comment.