Skip to content

Commit

Permalink
Migrate avro to GitHub actions (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdubeheetch authored Jul 27, 2023
1 parent 38654de commit 6c34fe4
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 136 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/avro.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: avro

on:
push:
branches:
- master
- main
paths:
- '**.go'
- 'go.*'
- '**.cue'
- Makefile
pull_request:
paths:
- '**.go'
- 'go.*'
- '**.cue'
- Makefile

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

env:
directory: "."
allow_lint_failure: "true"

jobs:
test:
runs-on: ubuntu-22.04
services:
registry:
image: lensesio/fast-data-dev:2.6.2-L0
ports:
- 8081:8081
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up env
uses: actions/setup-go@v3
with:
cache: true
check-latest: true
cache-dependency-path: ${{ env.directory }}/go.sum
go-version-file: ${{ env.directory }}/go.mod
- name: Install Tools
shell: bash
run: |
go install github.com/mfridman/[email protected]
tgz=$(mktemp)
ARCH="$(uname -s)_$(uname -m)"
curl "https://github.com/cuelang/cue/releases/download/v0.0.15/cue_0.0.15_$ARCH.tar.gz" -L -o $tgz
(cd /usr/local/bin && tar xzf $tgz cue)
- name: "Lint: static"
id: lint-static
continue-on-error: false
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
working-directory: ${{ env.directory }}
args: --timeout=5m
skip-cache: true
- name: "Lint: security"
id: lint-security
continue-on-error: true
working-directory: ${{ env.directory }}
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
- name: Build
run: |
make build
- name: Unit tests
working-directory: ${{ env.directory }}
env:
CGO_ENABLED: "1"
KAFKA_REGISTRY_ADDR: 127.0.0.1:8081
run: |
make test
84 changes: 0 additions & 84 deletions .github/workflows/test.yaml

This file was deleted.

10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

.PHONY: test build

build:
go build ./...

test:
go install ./cmd/...
go generate . ./cmd/...
go test ./... -cover -race -timeout=2m -json ./... | tparse
3 changes: 1 addition & 2 deletions cmd/avrogo/externaltype.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"go/format"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -133,7 +132,7 @@ func externalTypeInfoForGoTypes(gts map[goType]bool) (map[goType]avrotypemap.Ext
fmt.Printf("%s\n", buf.Bytes())
return nil, fmt.Errorf("cannot format typeinfo source: %v", err)
}
f, err := ioutil.TempFile(*dirFlag, "avro-introspect*.go")
f, err := os.CreateTemp(*dirFlag, "avro-introspect*.go")
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/avrogo/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"io"
"regexp"
"sort"
Expand Down Expand Up @@ -423,7 +425,7 @@ func (gc *generateContext) defaultFuncLiteral(v interface{}, t schema.AvroType)
func goName(s string) (string, error) {
lastIndex := strings.LastIndex(s, ".")
name := s[lastIndex+1:]
name = strings.Title(strings.Trim(name, "_"))
name = cases.Title(language.Und).String(strings.Trim(name, "_"))
if !isExportedGoIdentifier(name) {
return "", fmt.Errorf("cannot form an exported Go identifier from %q", s)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/avrogo/generatetestcode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions cmd/avrogo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
//
// Usage:
//
// usage: avrogo [flags] schema-file...
// -d string
// directory to write Go files to (default ".")
// -p string
// package name (defaults to $GOPACKAGE)
// -t generated files will have _test.go suffix
// -s string
// suffix for generated files (default "_gen")
// -tokenize
// if true, generate one dedicated file per qualified name found in the schema files
// usage: avrogo [flags] schema-file...
// -d string
// directory to write Go files to (default ".")
// -p string
// package name (defaults to $GOPACKAGE)
// -t generated files will have _test.go suffix
// -s string
// suffix for generated files (default "_gen")
// -tokenize
// if true, generate one dedicated file per qualified name found in the schema files
//
// By default, a type is generated for each Avro definition
// in the schema. Some additional metadata fields are
Expand All @@ -33,7 +33,6 @@ import (
stdflag "flag"
"fmt"
"go/format"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -216,7 +215,7 @@ func generateFile(outFile string, ns *parser.Namespace, definitions []schema.Qua
return fmt.Errorf("cannot create output directory: %v", err)
}
outFile = filepath.Join(*dirFlag, outFile)
if err := ioutil.WriteFile(outFile, resultData, 0666); err != nil {
if err := os.WriteFile(outFile, resultData, 0666); err != nil {
return err
}
return nil
Expand All @@ -230,7 +229,7 @@ func parseFiles(files []string) (*parser.Namespace, [][]schema.QualifiedName, er
var fileDefinitions [][]schema.QualifiedName
ns := parser.NewNamespace(false)
for _, f := range files {
data, err := ioutil.ReadFile(f)
data, err := os.ReadFile(f)
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/avrogo/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"go/token"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"reflect"
"regexp"
"strconv"
Expand Down Expand Up @@ -140,7 +142,7 @@ func defName(def schema.Definition) string {
}

func symbolName(e *schema.EnumDefinition, symbol string) string {
return defName(e) + strings.Title(symbol)
return defName(e) + cases.Title(language.Und).String(symbol)
}

func quote(s string) string {
Expand Down
5 changes: 2 additions & 3 deletions cmd/avsc2avdl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
stdflag "flag"
"fmt"
"io/ioutil"
"os"
"reflect"
"sort"
Expand Down Expand Up @@ -48,7 +47,7 @@ func main1() int {
// avsc2avdl converts the AVSC data in the file avscFile and writes
// it to outFile (or stdout if outFile is empty).
func avsc2avdl(avscFile, outFile string) error {
data, err := ioutil.ReadFile(avscFile)
data, err := os.ReadFile(avscFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -88,7 +87,7 @@ func avsc2avdl(avscFile, outFile string) error {
if outFile == "" {
os.Stdout.Write(g.buf.Bytes())
} else {
err := ioutil.WriteFile(outFile, g.buf.Bytes(), 0666)
err := os.WriteFile(outFile, g.buf.Bytes(), 0666)
if err != nil {
return fmt.Errorf("cannot create output file: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/go2avro/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
stdflag "flag"
"fmt"
"go/format"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -105,7 +104,7 @@ func buildGo(code []byte) (string, error) {
// Create the Go file in the current directory so that we
// take advantage of the current Go module.
// TODO avoid the side-effect of adding the avro import, somehow.
tmpFile, err := ioutil.TempFile(".", "go2avro_temp_*.go")
tmpFile, err := os.CreateTemp(".", "go2avro_temp_*.go")
if err != nil {
return "", fmt.Errorf("cannot generate temp file: %v", err)
}
Expand All @@ -115,7 +114,7 @@ func buildGo(code []byte) (string, error) {
if err != nil {
return "", fmt.Errorf("cannot write %q: %v", tmpFile.Name(), err)
}
tmpBinary, err := ioutil.TempFile(".", "go2avro_temp_bin")
tmpBinary, err := os.CreateTemp(".", "go2avro_temp_bin")
if err != nil {
return "", fmt.Errorf("cannot generate temp binary file: %v", err)
}
Expand Down
9 changes: 0 additions & 9 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,6 @@ func logicalType(t schema.AvroType) string {
return s
}

func timestampMillisEncoder(e *encodeState, v reflect.Value) {
t := v.Interface().(time.Time)
if t.IsZero() {
e.writeLong(0)
} else {
e.writeLong(t.Unix()*1e3 + int64(t.Nanosecond())/int64(time.Millisecond))
}
}

func timestampMicrosEncoder(e *encodeState, v reflect.Value) {
t := v.Interface().(time.Time)
if t.IsZero() {
Expand Down
Loading

0 comments on commit 6c34fe4

Please sign in to comment.