Skip to content

Commit

Permalink
add CI github action
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-codes committed Sep 27, 2024
1 parent 7a30129 commit b7f2d7b
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Install gofumpt
run: go install mvdan.cc/gofumpt@v0.7.0

- name: Install dependencies
run: make deps || exit 1

- name: Lint
run: make lint || exit 1

- name: Check format
run: make format || exit 1

- name: Run tests
run: make test || exit 1
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run: {}
51 changes: 51 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.DEFAULT_GOAL = check
.PHONY: FORCE

CC = /usr/local/musl/bin/musl-gcc
GOFLAGS = -ldflags '-linkmode external -extldflags "-static"'
OUTDIR = bin
TESTGEN_BINARY = $(OUTDIR)/testgen

build-testgen: $(TESTGEN_BINARY)
.PHONY: build-testgen

clean:
rm -f $(TESTGEN_BINARY)
.PHONY: clean

format:
gofumpt -l .
@if gofumpt -l . | grep -q .; then \
exit 1; \
fi
.PHONY: format

format-fix:
gofumpt -w .
.PHONY: format-fix

lint:
golangci-lint run --config .golangci.yml
.PHONY: lint

lint-fix:
golangci-lint run --fix --config .golangci.yml
.PHONY: lint-fix

test:
go test -v -p=4 ./...
.PHONY: test

check: format lint test
.PHONY: check

$(TESTGEN_BINARY): FORCE
@mkdir -p $(OUTDIR)
CC=$(CC) go build $(GOFLAGS) -o $@ ./cmd/testgen/main.go

deps: FORCE
go mod tidy
go mod verify

all: clean deps
.PHONY: all
2 changes: 2 additions & 0 deletions cmd/testgen/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux

package main

import (
Expand Down
4 changes: 4 additions & 0 deletions internal/testgen/cgetopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func cGetOpt(cArgc C.int, cArgv []*C.char, optstring string, longoptstring strin
name := parseName(cLongoptions, char, optopt, flag)
mutArgs := copyCArgv(cArgc, cArgv)

if err == "-1" {
optarg = ""
}

if (err == "?" || err == ":") && (char == "" && name == "") {
val := strings.TrimPrefix(curr_arg, "-")
val = strings.TrimPrefix(val, "-")
Expand Down

0 comments on commit b7f2d7b

Please sign in to comment.