Skip to content

Commit

Permalink
ci: first cut of running tests on macOS
Browse files Browse the repository at this point in the history
Get a simple version of our tests running against "latest" Go and
"latest" Vim on macOS. We can update this to be more specific later. For
now neither capture nor upload any artefacts post build.

To install Vim we follow the approach laid out in:

    https://blog.myitcv.io/2020/02/04/portable-ci-cd-with-pure-go-github-actions.html

to create a local pure Go GitHub action to install Vim, rather than
relying on a third-party NodeJS action.

Updates #481
  • Loading branch information
myitcv committed Feb 11, 2020
1 parent 4f5867f commit 35bd3ac
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,32 @@ jobs:
with:
path: /home/runner/.artefacts
name: ${{ matrix.os }}_${{ matrix.go_version }}_${{ matrix.vim_flavor }}_${{ matrix.vim_version }}
name: artefacts

test-macos:
strategy:
fail-fast: false
matrix:
os: [macos-latest]
go_version: ['1.14.x']
vim_version: ["master"]
runs-on: ${{ matrix.os }}
env:
VIM_FLAVOR: vim
steps:
- name: Checkout code
uses: actions/checkout@722adc63f1aa60a57ec37892e133b1d319cae598
- name: Install Vim
uses: ./github/actions/setupvim
with:
version: ${{ matrix.vim_version }}
- name: Install Go
uses: actions/setup-go@9fbc767707c286e568c92927bbf57d76b73e0892
with:
go-version: ${{ matrix.go_version }}
- name: Vim version
run: vim --version
- name: Go version
run: go version
- name: Run tests
run: go run ./internal/cmd/dots go test -timeout 0s ./...
3 changes: 3 additions & 0 deletions github/actions/setupvim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### `github.com/govim/govim/github/actions/setupvim`

`setupvim` is a pure Go GitHub Action for install Vim on various platforms. It is a work-in-progress.
13 changes: 13 additions & 0 deletions github/actions/setupvim/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'Setup Vim'
description: 'Setup Vim in your workflow'
inputs:
version:
description: >
Version of Vim to install. Valid values are git refs (e.g. 'master', a branch name or commit hash)
or version tags (e.g. 'v8.2.0126')
required: false
default: 'master'

runs:
using: 'node12'
main: 'index.js'
5 changes: 5 additions & 0 deletions github/actions/setupvim/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/govim/govim/github/actions/setupvim

go 1.14

require github.com/sethvargo/go-githubactions v0.1.1
2 changes: 2 additions & 0 deletions github/actions/setupvim/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/sethvargo/go-githubactions v0.1.1 h1:u75rV0C+AvNjEUE4maSN844/U5eiy9Rlc3ahOU4EAfE=
github.com/sethvargo/go-githubactions v0.1.1/go.mod h1:ugCoIFQjs7HxIwwYiY7ty6H9T+7Z4ey481HxqA3VRKE=
22 changes: 22 additions & 0 deletions github/actions/setupvim/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";

const spawn = require("child_process").spawn;

async function run() {
var args = Array.prototype.slice.call(arguments);
const cmd = spawn(args[0], args.slice(1), {
stdio: "inherit",
cwd: __dirname
});
const exitCode = await new Promise((resolve, reject) => {
cmd.on("close", resolve);
});
if (exitCode != 0) {
process.exit(exitCode);
}
}

(async function() {
const path = require("path");
await run("go", "run", ".");
})();
56 changes: 56 additions & 0 deletions github/actions/setupvim/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// setupvim is a pure Go GitHub Action for install Vim on various platforms. It
// is a work-in-progress.
package main

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"

"github.com/sethvargo/go-githubactions"
)

const debug = true

func main() {
os.Exit(main1())
}

func main1() int {
if err := mainerr(); err != nil {
switch err := err.(type) {
case runCmdErr:
ee := err.error.(*exec.ExitError)
return ee.ProcessState.ExitCode()
default:
fmt.Fprintln(os.Stderr, err)
return 1
}
}
return 0
}

func mainerr() error {
td := tempDir("", "")
if !debug {
defer os.RemoveAll(td)
}
version := "master"
if v := githubactions.GetInput("version"); v != "" {
version = v
}
cmd("git", "clone", "-q", "--depth=1", "--single-branch", "--branch", version, "https://github.com/vim/vim", td).run()
id := tempDir("", "")
if !debug {
defer os.RemoveAll(id)
}
cmd("./configure", "--prefix="+id, "--with-features=huge", "--enable-fail-if-missing").runInDir(td)
cmd("make", "-j", strconv.Itoa(runtime.NumCPU())).runInDir(td)
cmd("make", "install").runInDir(td)
bin := filepath.Join(id, "bin")
githubactions.SetEnv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
return nil
}
64 changes: 64 additions & 0 deletions github/actions/setupvim/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
)

type command struct {
cmd *exec.Cmd
}

type runCmdErr struct {
error
}

func cmd(cmdname string, args ...string) *command {
cmd := exec.Command(cmdname, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return &command{
cmd: cmd,
}
}

func (c *command) run() {
format := "> "
wd, err := os.Getwd()
check(err, "failed to get working directory: %v", err)
runDir := wd
if d := c.cmd.Dir; d != "" {
rd, err := filepath.Abs(d)
check(err, "failed to make %v absolute: %v", d, err)
runDir = rd
}
if wd != runDir {
format += fmt.Sprintf("cd %v; ", runDir)
}
format += "%v\n"
fmt.Printf(format, strings.Join(c.cmd.Args, " "))
if err := c.cmd.Run(); err != nil {
panic(runCmdErr{err})
}
}

func (c *command) runInDir(dir string) {
c.cmd.Dir = dir
c.run()
}

func tempDir(dir, pattern string) string {
td, err := ioutil.TempDir(dir, pattern)
check(err, "failed to create temp dir: %v", err)
return td
}

func check(err error, format string, args ...interface{}) {
if err != nil {
panic(fmt.Errorf(format, args...))
}
}
29 changes: 29 additions & 0 deletions internal/cmd/genconfig/genconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,35 @@ jobs:
with:
path: /home/runner/.artefacts
name: ${{ matrix.os }}_${{ matrix.go_version }}_${{ matrix.vim_flavor }}_${{ matrix.vim_version }}
name: artefacts
test-macos:
strategy:
fail-fast: false
matrix:
os: [macos-latest]
go_version: ['1.14.x']
vim_version: ["master"]
runs-on: ${{ matrix.os }}
env:
VIM_FLAVOR: vim
steps:
- name: Checkout code
uses: actions/checkout@722adc63f1aa60a57ec37892e133b1d319cae598
- name: Install Vim
uses: ./github/actions/setupvim
with:
version: ${{ matrix.vim_version }}
- name: Install Go
uses: actions/setup-go@9fbc767707c286e568c92927bbf57d76b73e0892
with:
go-version: ${{ matrix.go_version }}
- name: Vim version
run: vim --version
- name: Go version
run: go version
- name: Run tests
run: go run ./internal/cmd/dots go test -timeout 0s ./...
`

const maxVersions = `# Code generated by genconfig. DO NOT EDIT.
Expand Down

0 comments on commit 35bd3ac

Please sign in to comment.