Skip to content

Commit

Permalink
Merge pull request #323 from metrumresearchgroup/gh-actions
Browse files Browse the repository at this point in the history
ci: switch to GitHub Actions
  • Loading branch information
kyleam authored Aug 13, 2024
2 parents 835953e + 1449d16 commit 5e1f919
Show file tree
Hide file tree
Showing 208 changed files with 188 additions and 254 deletions.
171 changes: 0 additions & 171 deletions .drone.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: lint
on:
push:
branches:
- main
- 'scratch/**'
pull_request:

# Note: this avoids golangci/golangci-lint-action to work around an
# error triggered by us pinning to a golangci-lint version built with
# an older Go. Revisit when moving from golangci-lint v1.47.2.
#
# https://github.com/golangci/golangci-lint-action/issues/442#issuecomment-1203786890
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install golangci-lint
shell: bash
run: |
bin=$(mktemp -d)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b "$bin" v1.47.2
echo "$bin" >>$GITHUB_PATH
- name: Run golangci-lint
shell: bash
run: |
command -v golangci-lint
golangci-lint run --out-format=github-actions
67 changes: 67 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: CI
on:
push:
branches:
- main
- 'scratch/**'
tags:
- 'v*'
pull_request:

jobs:
check:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.go }})
strategy:
fail-fast: false
matrix:
config:
- os: ubuntu-20.04
go: 1.21.x
- os: ubuntu-latest
go: stable
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.config.go }}
- name: Unit tests
shell: bash
run: go list ./... | grep -v integration | xargs go test
- name: Build bbi
shell: bash
run: |
version=$(git rev-parse 'HEAD^{tree}')
bin=$(mktemp -d)
go build -o "$bin/bbi" \
-ldflags "-X github.com/metrumresearchgroup/bbi/cmd.VERSION=$version" \
cmd/bbi/main.go
echo "$bin" >>$GITHUB_PATH
- name: Integration tests (postrun)
shell: bash
run: |
bbi version
go test ./integration/postrun
release:
if: github.ref_type == 'tag'
name: Make release
needs: check
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: stable
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: release --clean
workdir: cmd/bbi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 2 additions & 3 deletions cmd/nonmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -301,12 +300,12 @@ func copyFileToDestination(l *NonMemModel, modifyPath bool) error {
}
} else {
var input []byte
input, err = ioutil.ReadFile(l.Path)
input, err = os.ReadFile(l.Path)
if err != nil {
return fmt.Errorf("unable to read %s: %w", l.Path, err)
}

err = ioutil.WriteFile(path.Join(l.OutputDir, filename), input, stats.Mode())
err = os.WriteFile(path.Join(l.OutputDir, filename), input, stats.Mode())
if err != nil {
return fmt.Errorf("unable to write contents %s: %w", l.Path, err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"bytes"
"errors"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -281,7 +280,7 @@ func ExecutePostWorkDirectivesWithEnvironment(worker PostWorkExecutor) (string,
}).Debug("Writing contents to file in output directory")

// TODO: use more secure permission of 0600 or less
err = ioutil.WriteFile(filepath.Join(worker.GetWorkingPath(), "post_processing.sh"), processedBytes, 0755) // nolint:gosec
err = os.WriteFile(filepath.Join(worker.GetWorkingPath(), "post_processing.sh"), processedBytes, 0755) // nolint:gosec

if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/metrumresearchgroup/bbi

go 1.15
go 1.16

require (
github.com/clbanning/mxj v1.8.4
Expand Down
6 changes: 3 additions & 3 deletions integration/execute.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package integration

import (
"context"
Expand All @@ -10,7 +10,7 @@ import (
log "github.com/sirupsen/logrus"
)

func executeCommand(ctx context.Context, command string, args ...string) (string, error) {
func ExecuteCommand(ctx context.Context, command string, args ...string) (string, error) {
//Find it in path
binary, _ := exec.LookPath(command)
cmd := exec.CommandContext(ctx, binary, args...)
Expand Down Expand Up @@ -40,7 +40,7 @@ func executeCommand(ctx context.Context, command string, args ...string) (string
}

// nolint:unparam
func executeCommandNoErrorCheck(ctx context.Context, command string, args ...string) (string, error) {
func ExecuteCommandNoErrorCheck(ctx context.Context, command string, args ...string) (string, error) {
binary, _ := exec.LookPath(command)
cmd := exec.CommandContext(ctx, binary, args...)
cmd.Env = os.Environ()
Expand Down
1 change: 1 addition & 0 deletions integration/nonmem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains integration tests that rely on having NONMEM installed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"context"
Expand All @@ -8,6 +8,7 @@ import (
"strings"
"testing"

. "github.com/metrumresearchgroup/bbi/integration"
"github.com/metrumresearchgroup/bbi/utils"

"github.com/metrumresearchgroup/wrapt"
Expand Down Expand Up @@ -38,7 +39,7 @@ func TestBBIExpandsWithoutPrefix(tt *testing.T) {
filepath.Join(scenario.Workpath, "model", targets),
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down Expand Up @@ -107,7 +108,7 @@ func TestBBIExpandsWithPrefix(tt *testing.T) {
filepath.Join(scenario.Workpath, "model", targets),
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down Expand Up @@ -177,7 +178,7 @@ func TestBBIExpandsWithPrefixToPartialMatch(tt *testing.T) {
filepath.Join(scenario.Workpath, "model", targets),
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down
Loading

0 comments on commit 5e1f919

Please sign in to comment.