Skip to content

Commit 7f6b374

Browse files
authored
Merge pull request #47 from progrium/github-actions
tests: migrate tests from circleci to github actions
2 parents 5f673cf + f6084b8 commit 7f6b374

File tree

9 files changed

+172
-59
lines changed

9 files changed

+172
-59
lines changed

.circleci/config.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
---
12
version: 2
23
jobs:
34
build:
45
machine: true
56
working_directory: ~/progrium/go-basher
67
parallelism: 1
78
steps:
8-
- checkout
99
- run: |
10-
make build
11-
- run: |
12-
go get -d -t
13-
go test -v
10+
true

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
version: 2
3+
updates:
4+
- package-ecosystem: github-actions
5+
directory: "/"
6+
schedule:
7+
interval: daily
8+
open-pull-requests-limit: 10
9+
labels:
10+
- "type: dependencies"

.github/linters/.markdown-lint.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
default: true
3+
4+
# Line length
5+
# https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md013
6+
MD013: false
7+
8+
# Inline HTML
9+
# https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md033
10+
MD033: false

.github/linters/.yamllint.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
line-length: disable

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: CI
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
pull_request:
7+
branches:
8+
- "*"
9+
push:
10+
branches:
11+
- "master"
12+
13+
jobs:
14+
build:
15+
name: build
16+
runs-on: ubuntu-22.04
17+
strategy:
18+
fail-fast: true
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Build
23+
shell: bash
24+
run: |
25+
go mod init github.com/progrium/go-basher
26+
go mod tidy
27+
make build
28+
- name: Test
29+
shell: bash
30+
run: |
31+
go get -d -t
32+
go test -v

.github/workflows/lint.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: "lint"
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
pull_request:
7+
branches:
8+
- "*"
9+
push:
10+
branches:
11+
- "master"
12+
13+
jobs:
14+
markdown-lint:
15+
name: markdown-lint
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- name: Clone
19+
uses: actions/checkout@v4
20+
- name: Run markdown-lint
21+
uses: avto-dev/markdown-lint@04d43ee9191307b50935a753da3b775ab695eceb
22+
# v1.5.0 => 04d43ee9191307b50935a753da3b775ab695eceb
23+
with:
24+
config: ".github/linters/.markdown-lint.yml"
25+
args: "./README.md"
26+
27+
shellcheck:
28+
name: shellcheck
29+
runs-on: ubuntu-22.04
30+
steps:
31+
- name: Clone
32+
uses: actions/checkout@v4
33+
- name: Run shellcheck
34+
uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38
35+
# 1.1.0 => 94e0aab03ca135d11a35e5bfc14e6746dc56e7e9
36+
env:
37+
SHELLCHECK_OPTS: -e SC2034
38+
39+
shfmt:
40+
name: shfmt
41+
runs-on: ubuntu-22.04
42+
steps:
43+
- name: Clone
44+
uses: actions/checkout@v4
45+
- name: Run shfmt
46+
uses: luizm/action-sh-checker@c6edb3de93e904488b413636d96c6a56e3ad671a
47+
# v0.3.0 => 7f44869033b40ee4ffe7dc76c87a1bc66e3d025a
48+
env:
49+
SHFMT_OPTS: -l -bn -ci -i 2 -d
50+
with:
51+
sh_checker_shellcheck_disable: true
52+
53+
yamllint:
54+
name: yamllint
55+
runs-on: ubuntu-22.04
56+
steps:
57+
- name: Clone
58+
uses: actions/checkout@v4
59+
- name: Run yamllint
60+
uses: ibiqlik/action-yamllint@2576378a8e339169678f9939646ee3ee325e845c
61+
# v3.0.4 => ed2b6e911569708ed121c14b87d513860a7e36a7
62+
with:
63+
config_file: ".github/linters/.yamllint.yml"

Makefile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test:
77
go test -v
88

99
build:
10-
go install || true
10+
go install
1111

1212
deps:
1313
go get -u github.com/a-urth/go-bindata/...
@@ -38,10 +38,3 @@ bash:
3838
go-bindata -tags=linux,amd64 -o=bash_linux_amd64.go -prefix=$(BASH_DIR)/linux-amd64 -pkg=basher $(BASH_DIR)/linux-amd64
3939
go-bindata -tags=darwin,arm64 -o=bash_darwin_arm64.go -prefix=$(BASH_DIR)/osx-arm64 -pkg=basher $(BASH_DIR)/osx-arm64
4040
go-bindata -tags=darwin,amd64 -o=bash_darwin_amd64.go -prefix=$(BASH_DIR)/osx-amd64 -pkg=basher $(BASH_DIR)/osx-amd64
41-
42-
circleci:
43-
rm ~/.gitconfig
44-
rm -rf /home/ubuntu/.go_workspace/src/github.com/$(OWNER)/$(NAME) && cd .. \
45-
&& mkdir -p /home/ubuntu/.go_workspace/src/github.com/$(OWNER) \
46-
&& mv $(NAME) /home/ubuntu/.go_workspace/src/github.com/$(OWNER)/$(NAME) \
47-
&& ln -s /home/ubuntu/.go_workspace/src/github.com/$(OWNER)/$(NAME) $(NAME)

README.md

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A Go library for creating Bash environments, exporting Go functions in them as Bash functions, and running commands in that Bash environment. Combined with a tool like [go-bindata](https://github.com/jteeuwen/go-bindata), you can write programs that are part written in Go and part written in Bash that can be distributed as standalone binaries.
44

5-
[![Circle CI](https://circleci.com/gh/progrium/go-basher.svg?style=shield)](https://circleci.com/gh/progrium/go-basher) [![GoDoc](https://godoc.org/github.com/progrium/go-basher?status.svg)](http://godoc.org/github.com/progrium/go-basher)
5+
![Github Actions](https://github.com/github/docs/actions/workflows/ci.yml/badge.svg) [![GoDoc](https://godoc.org/github.com/progrium/go-basher?status.svg)](http://godoc.org/github.com/progrium/go-basher)
66

77
## Using go-basher
88

@@ -12,63 +12,64 @@ Here we have a simple Go program that defines a `reverse` function, creates a Ba
1212
package main
1313

1414
import (
15-
"os"
16-
"io/ioutil"
17-
"log"
18-
"strings"
15+
"os"
16+
"io/ioutil"
17+
"log"
18+
"strings"
1919

20-
"github.com/progrium/go-basher"
20+
"github.com/progrium/go-basher"
2121
)
2222

2323
func reverse(args []string) {
24-
bytes, err := ioutil.ReadAll(os.Stdin)
25-
if err != nil {
26-
log.Fatal(err)
27-
}
28-
runes := []rune(strings.Trim(string(bytes), "\n"))
29-
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
30-
runes[i], runes[j] = runes[j], runes[i]
31-
}
32-
println(string(runes))
24+
bytes, err := ioutil.ReadAll(os.Stdin)
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
29+
runes := []rune(strings.Trim(string(bytes), "\n"))
30+
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
31+
runes[i], runes[j] = runes[j], runes[i]
32+
}
33+
println(string(runes))
3334
}
3435

3536
func main() {
36-
bash, _ := basher.NewContext("/bin/bash", false)
37-
bash.ExportFunc("reverse", reverse)
38-
if bash.HandleFuncs(os.Args) {
39-
os.Exit(0)
40-
}
41-
42-
bash.Source("main.bash", nil)
43-
status, err := bash.Run("main", os.Args[1:])
44-
if err != nil {
45-
log.Fatal(err)
46-
}
47-
os.Exit(status)
37+
bash, _ := basher.NewContext("/bin/bash", false)
38+
bash.ExportFunc("reverse", reverse)
39+
if bash.HandleFuncs(os.Args) {
40+
os.Exit(0)
41+
}
42+
43+
bash.Source("main.bash", nil)
44+
status, err := bash.Run("main", os.Args[1:])
45+
if err != nil {
46+
log.Fatal(err)
47+
}
48+
os.Exit(status)
4849
}
4950
```
5051

5152
Here is our `main.bash` file, the actual heart of the program:
5253

5354
```bash
5455
main() {
55-
echo "Hello world" | reverse
56+
echo "Hello world" | reverse
5657
}
5758
```
5859

5960
## Using go-basher with go-bindata
6061

6162
You can bundle your Bash scripts into your Go binary using [go-bindata](https://github.com/jteeuwen/go-bindata). First install go-bindata:
6263

63-
$ go get github.com/jteeuwen/go-bindata/...
64+
go get github.com/jteeuwen/go-bindata/...
6465

6566
Now put all your Bash scripts in a directory called `bash`. The above example program would mean you'd have a `bash/main.bash` file. Run `go-bindata` on the directory:
6667

67-
$ go-bindata bash
68+
go-bindata bash
6869

6970
This will produce a `bindata.go` file that includes all of your Bash scripts.
7071

71-
> `bindata.go` includes a function called `Asset` that behaves like `ioutil.ReadFile` for files in your `bindata.go`.
72+
> `bindata.go` includes a function called `Asset` that behaves like `ioutil.ReadFile` for files in your `bindata.go`.
7273
7374
Here's how you embed it into the above example program:
7475

@@ -77,22 +78,22 @@ Here's how you embed it into the above example program:
7778
* method B: replace all code in the `main()`-function with the `Application()`-helper function (see below)
7879

7980
```Go
80-
basher.Application(
81-
map[string]func([]string){
82-
"reverse": reverse,
83-
}, []string{
84-
"bash/main.bash",
85-
},
86-
Asset,
87-
true,
88-
)
81+
basher.Application(
82+
map[string]func([]string){
83+
"reverse": reverse,
84+
}, []string{
85+
"bash/main.bash",
86+
},
87+
Asset,
88+
true,
89+
)
8990
```
9091

9192
## Batteries included, but replaceable
9293

9394
Did you already hear that term? Sometimes Bash binary is missing, for example when using alpine linux or busybox. Or sometimes its not the correct version. Like OSX ships with Bash 3.x which misses a lot of usefull features. Or you want to make sure to avoid shellshock attack.
9495

95-
For those reasons static versions of Bash binaries are included for linux and darwin. Statically linked bash binaries are released at: https://github.com/robxu9/bash-static. These are then turned into go code, with go-bindata: bindata_linux.go and bindata_darwin.go.
96+
For those reasons static versions of Bash binaries are included for linux and darwin. Statically linked bash binaries are released at: <https://github.com/robxu9/bash-static>. These are then turned into go code, with go-bindata: bindata_linux.go and bindata_darwin.go.
9697

9798
When you use the `basher.Application()` function, the built in Bash binary will be extracted into the `~/.basher/` dir.
9899

@@ -106,7 +107,9 @@ Go is a great compiled systems language, but it can still be faster to write and
106107

107108
Take a common task like making an HTTP request for JSON data. Parsing JSON is easy in Go, but without depending on a tool like `jq` it is not even worth trying in Bash. And some formats like YAML don't even have a good `jq` equivalent. Whereas making an HTTP request in Go in the *simplest* case is going to be 6+ lines, as opposed to Bash where you can use `curl` in one line. If we write our JSON parser in Go and fetch the HTTP doc with `curl`, we can express printing a field from a remote JSON object in one line:
108109

109-
curl -s https://api.github.com/users/progrium | parse-user-field email
110+
```shell
111+
curl -s https://api.github.com/users/progrium | parse-user-field email
112+
```
110113

111114
In this case, the command `parse-user-field` is an app specific function defined in your Go program.
112115

example/bash/example.bash

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
set -eo pipefail
22

33
hello-bash() {
4-
echo "Hello world from Bash"
4+
echo "Hello world from Bash"
55
}
66

77
main() {
8-
echo "Arguments:" "$@"
9-
hello-bash | reverse
10-
curl -s https://api.github.com/repos/progrium/go-basher | json-pointer /owner/login
8+
echo "Arguments:" "$@"
9+
hello-bash | reverse
10+
curl -s https://api.github.com/repos/progrium/go-basher | json-pointer /owner/login
1111
}

0 commit comments

Comments
 (0)