Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: switch to GitHub Actions #323

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an example of how this will fail when it flags an issue: https://github.com/metrumresearchgroup/bbi/actions/runs/10321533479

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:
Copy link
Collaborator Author

@kyleam kyleam Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This release job hasn't been tested. My thinking is that we can do a prerelease after the validation rework lands, and I can adjust as needed then.

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