Skip to content

Commit a7fb6b4

Browse files
authored
Merge pull request #227 from x-motemen/fix-misc-20250224
Update dependencies and release Docker image to ghcr.io
2 parents f2e73f6 + 2b94d70 commit a7fb6b4

17 files changed

+298
-209
lines changed

.dockerignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/gore
2+
/doc
3+
/goxz
4+
/CREDITS
5+
/.github
6+
*.exe
7+
*.test
8+
*.out
9+
*.md

.github/workflows/ci.yaml

+100-16
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,116 @@ name: CI
33
on:
44
push:
55
branches:
6-
- main
6+
- main
7+
tags:
8+
- v*
79
pull_request:
810

911
permissions:
1012
contents: read
1113

1214
jobs:
15+
build:
16+
name: Build
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
- name: Setup Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: 1.24.x
25+
- name: Build
26+
run: make build
27+
- name: Run command
28+
run: echo 'fmt.Sprint(42)' | ./gore --autoimport
29+
- name: Cross build
30+
run: make cross
31+
- name: Upload artifact
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: goxz
35+
path: goxz
36+
- name: Clean
37+
run: make clean
38+
1339
test:
1440
name: Test
1541
runs-on: ubuntu-latest
1642
strategy:
1743
matrix:
18-
go: [1.21.x, 1.20.x, 1.19.x]
44+
go: [1.24.x, 1.23.x, 1.22.x]
1945
fail-fast: false
2046
steps:
21-
- name: Checkout code
22-
uses: actions/checkout@v4
23-
- name: Setup Go
24-
uses: actions/setup-go@v4
25-
with:
26-
go-version: ${{ matrix.go }}
27-
- name: Install gocode
28-
run: go install github.com/mdempsky/gocode@latest
29-
- name: Build
30-
run: make build
31-
- name: Test
32-
run: make test
33-
- name: Lint
34-
run: make lint
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
- name: Setup Go
50+
uses: actions/setup-go@v5
51+
with:
52+
go-version: ${{ matrix.go }}
53+
- name: Install gocode
54+
run: go install github.com/mdempsky/gocode@latest
55+
- name: Build
56+
run: make build
57+
- name: Test
58+
run: make test
59+
- name: Lint
60+
run: make lint
61+
62+
docker:
63+
name: Docker
64+
permissions:
65+
packages: write
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Checkout code
69+
uses: actions/checkout@v4
70+
- name: Docker metadata
71+
uses: docker/metadata-action@v5
72+
id: metadata
73+
with:
74+
images: ghcr.io/${{ github.repository }}
75+
tags: |
76+
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
77+
type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
78+
type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
79+
type=sha,format=long,enable=${{ !startsWith(github.ref, 'refs/tags/v') }}
80+
- name: Set up QEMU
81+
uses: docker/setup-qemu-action@v3
82+
- name: Set up Docker Buildx
83+
uses: docker/setup-buildx-action@v3
84+
- name: Login to GitHub Container Registry
85+
if: startsWith(github.ref, 'refs/tags/v')
86+
uses: docker/login-action@v3
87+
with:
88+
registry: ghcr.io
89+
username: ${{ github.repository_owner }}
90+
password: ${{ secrets.GITHUB_TOKEN }}
91+
- name: Build and release Docker image
92+
uses: docker/build-push-action@v6
93+
with:
94+
context: .
95+
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
96+
provenance: false
97+
platforms: linux/amd64, linux/arm64
98+
tags: ${{ steps.metadata.outputs.tags }}
99+
labels: ${{ steps.metadata.outputs.labels }}
100+
101+
release:
102+
name: Release
103+
needs: [build, test, docker]
104+
if: startsWith(github.ref, 'refs/tags/v')
105+
permissions:
106+
contents: write
107+
runs-on: ubuntu-latest
108+
steps:
109+
- name: Download artifacts
110+
uses: actions/download-artifact@v4
111+
with:
112+
name: goxz
113+
path: goxz
114+
- name: Create release
115+
uses: ncipollo/release-action@v1
116+
with:
117+
name: Release ${{ github.ref_name }}
118+
artifacts: goxz/*

.github/workflows/release.yaml

-28
This file was deleted.

Dockerfile

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
FROM golang:1.19.4-alpine3.17
1+
FROM golang:1.24.0-alpine3.21
2+
3+
RUN apk add --no-cache git make \
4+
&& go install github.com/mdempsky/gocode@latest
25

3-
RUN apk add --no-cache git make
46
WORKDIR /go/src/github.com/x-motemen/gore/
7+
COPY go.* ./
8+
RUN go mod download
59
COPY . .
10+
ENV CGO_ENABLED=0
611
RUN make install
712

8-
RUN go install github.com/mdempsky/gocode@latest # for code completion
9-
1013
ENTRYPOINT ["gore"]

README.md

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# gore [![CI Status](https://github.com/x-motemen/gore/workflows/CI/badge.svg)](https://github.com/x-motemen/gore/actions)
1+
# gore
2+
[![CI Status](https://github.com/x-motemen/gore/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/x-motemen/gore/actions?query=branch:main)
3+
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/x-motemen/gore/blob/main/LICENSE)
4+
[![release](https://img.shields.io/github/release/x-motemen/gore/all.svg)](https://github.com/x-motemen/gore/releases)
5+
26
### Yet another Go REPL that works nicely. Featured with line editing, code completion, and more.
37

48
![Screencast](doc/screencast.gif)
@@ -58,18 +62,21 @@ go install github.com/mdempsky/gocode@latest # for code completion
5862
Or you can use Docker:
5963

6064
```sh
61-
git clone https://github.com/x-motemen/gore.git
62-
cd gore
63-
docker build -t gore .
64-
docker run -it --rm gore
65+
docker run -it --rm ghcr.io/x-motemen/gore
6566
```
6667

6768
## FAQ/Caveats
6869

69-
- gore runs code using `go run` for each input. All the inputted lines are
70-
evaluated again and again so you can't bind the evaluated time by
71-
`time.Now()`, for example. If you don't like this behavior, you may want to use
72-
[yaegi](https://github.com/containous/yaegi).
70+
- gore runs code using `go run` for each input. Every line entered is evaluated
71+
repeatedly ([#67](https://github.com/x-motemen/gore/issues/67)),
72+
so you can't bind the evaluated time by `time.Now()`, for example.
73+
This implementation also makes the execution fairly slow
74+
([#182](https://github.com/x-motemen/gore/issues/182)).
75+
This project started from a simple idea to use `go run` for all REPL input.
76+
I think this project has provided some value for Go users, but these days
77+
there are other REPL implementations that are more actively maintained
78+
and run faster. I recommend using [gomacro](https://github.com/cosmos72/gomacro)
79+
or [yaegi](https://github.com/containous/yaegi).
7380
- gore support Go modules. You can load local modules when you start gore at
7481
the project directory. You don't need to `go get` to check the usage of a
7582
remote repository, `:import github.com/...` will automatically download that
@@ -84,3 +91,4 @@ docker run -it --rm gore
8491
## Author
8592

8693
motemen &lt;<motemen@gmail.com>&gt;
94+
itchyny &lt;<itchyny@cybozu.co.jp>&gt;

command_name.go

+8-42
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,19 @@ import "strings"
44

55
type commandName string
66

7+
var commandAbbrReplacer = strings.NewReplacer("[", "", "]", "")
8+
79
func (s commandName) String() string {
8-
var b strings.Builder
9-
for _, c := range s {
10-
if c != '[' && c != ']' {
11-
b.WriteRune(c)
12-
}
13-
}
14-
return b.String()
10+
return commandAbbrReplacer.Replace(string(s))
1511
}
1612

1713
func (s commandName) matches(t string) bool {
18-
var grouping bool
19-
for i, j := 0, 0; j <= len(t); i, j = i+1, j+1 {
20-
if i >= len(s) {
21-
return j == len(t)
22-
}
23-
if s[i] == '[' {
24-
grouping = true
25-
i++
26-
}
27-
if j == len(t) {
28-
break
29-
}
30-
if s[i] == ']' {
31-
return false
32-
}
33-
if s[i] != t[j] {
34-
return false
35-
}
36-
}
37-
return grouping
14+
prefix, rest, _ := strings.Cut(string(s), "[")
15+
abbr, _, _ := strings.Cut(rest, "]")
16+
return strings.HasPrefix(t, prefix) &&
17+
strings.HasPrefix(abbr, t[len(prefix):])
3818
}
3919

4020
func (s commandName) matchesPrefix(t string) bool {
41-
for i, j := 0, 0; j < len(t); i, j = i+1, j+1 {
42-
if i >= len(s) {
43-
return false
44-
}
45-
if s[i] == '[' {
46-
i++
47-
}
48-
if s[i] == ']' {
49-
return false
50-
}
51-
if s[i] != t[j] {
52-
return false
53-
}
54-
}
55-
return true
21+
return strings.HasPrefix(string(s), t) || s.matches(t)
5622
}

command_name_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ func TestCommandName(t *testing.T) {
2525
{"foo[bar]", "foobar", "foo", true, true},
2626
{"foo[bar]", "foobar", "fo", false, true},
2727
{"foo[bar]", "foobar", "", false, true},
28-
{"foo[bar]", "foobar", "foo[bar]", false, false},
29-
{"foo[bar]", "foobar", "foobar]", false, false},
30-
{"foo[bar]", "foobar", "foo[]", false, false},
31-
{"foo[bar]", "foobar", "foo[", false, false},
32-
{"foo[bar]", "foobar", "[", false, false},
3328
{"[bar]", "bar", "foobar", false, false},
3429
{"[bar]", "bar", "bar", true, true},
3530
{"[bar]", "bar", "bra", false, false},

commands.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func actionWrite(s *Session, filename string) error {
324324
}
325325

326326
if filename == "" {
327-
filename = fmt.Sprintf("gore_session_%s.go", time.Now().Format("20060102_150405"))
327+
filename = time.Now().Format("gore_session_20060102_150405.go")
328328
}
329329

330330
err = os.WriteFile(filename, []byte(source), 0o644)

commands_test.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package gore
22

33
import (
4+
"go/version"
5+
"runtime"
46
"strings"
57
"testing"
68

@@ -9,6 +11,10 @@ import (
911
)
1012

1113
func TestAction_Type(t *testing.T) {
14+
if version.Compare(runtime.Version(), "go1.24") < 0 {
15+
t.Skipf("Skip on %s", runtime.Version())
16+
}
17+
1218
var stdout, stderr strings.Builder
1319
s, err := NewSession(&stdout, &stderr)
1420
t.Cleanup(func() { s.Clear() })
@@ -33,21 +39,25 @@ func TestAction_Type(t *testing.T) {
3339
_ = s.Eval(code)
3440
}
3541

36-
assert.Regexp(t, `string
42+
assert.Equal(t, `string
3743
int
3844
float64
39-
func\(\) \[\]int
40-
\[\]int
41-
func\(a \.\.\.(?:interface\{\}|any)\) string
42-
func\(a \.\.\.(?:interface\{\}|any)\) \(n int, err error\)
43-
func\(w io\.Writer\) \*encoding/json\.Encoder
45+
func() []int
46+
[]int
47+
func(a ...any) string
48+
func(a ...any) (n int, err error)
49+
func(w io.Writer) *encoding/json.Encoder
4450
`, stdout.String())
4551
assert.Equal(t, `type: cannot get type: x
4652
type: cannot get type: fmt
4753
`, stderr.String())
4854
}
4955

5056
func TestAction_Doc(t *testing.T) {
57+
if version.Compare(runtime.Version(), "go1.24") < 0 {
58+
t.Skipf("Skip on %s", runtime.Version())
59+
}
60+
5161
var stdout, stderr strings.Builder
5262
s, err := NewSession(&stdout, &stderr)
5363
t.Cleanup(func() { s.Clear() })

0 commit comments

Comments
 (0)