Skip to content

Commit

Permalink
ci: setup earthly and vhs (#13)
Browse files Browse the repository at this point in the history
* ci: setup earthly
* ci: replace custom demo with vhs
  • Loading branch information
brumhard authored Jan 21, 2025
1 parent 259ddcb commit da6dc37
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 72 deletions.
70 changes: 70 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
VERSION 0.8

FROM golang:1.22
ARG --global BINPATH=/usr/local/bin/
ARG --global GOCACHE=/go-cache

deps:
WORKDIR /src
ENV GO111MODULE=on
ENV CGO_ENABLED=0
COPY go.mod go.sum ./
RUN go mod download
SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum

build:
FROM +deps
COPY main.go .
ARG GOOS=linux
ARG GOARCH=amd64
RUN --mount=type=cache,target=$GOCACHE \
go build -ldflags="-w -s" -o krewfile main.go
SAVE ARTIFACT krewfile

lint:
FROM +deps
COPY +golangci-lint/golangci-lint $BINPATH
COPY *.go .
ARG GOLANGCI_LINT_CACHE=/golangci-cache
RUN --mount=type=cache,target=$GOCACHE \
--mount=type=cache,target=$GOLANGCI_LINT_CACHE \
golangci-lint run -v ./...

test:
FROM +deps
COPY *.go .
ARG GO_TEST="go test"
RUN --mount=type=cache,target=$GOCACHE \
$GO_TEST ./...

e2e:
COPY +krew/krew $BINPATH
COPY +build/krewfile $BINPATH
RUN echo "stern" > /root/.krewfile
RUN krewfile
RUN krew list 2>/dev/null | grep "stern" >/dev/null

vhs:
FROM ghcr.io/charmbracelet/vhs:v0.9.0
RUN apt install -y git
COPY +krew/krew $BINPATH
ENV PATH="$PATH:/root/.krew/bin"
COPY +build/krewfile $BINPATH
COPY demo.tape .
RUN krew install stern
RUN vhs demo.tape
SAVE ARTIFACT demo.gif AS LOCAL docs/demo.gif

###########
# helper
###########

golangci-lint:
FROM golangci/golangci-lint:v1.61.0
SAVE ARTIFACT /usr/bin/golangci-lint

krew:
FROM +deps
RUN go install sigs.k8s.io/krew/cmd/krew@v0.4.4
SAVE ARTIFACT /go/bin/krew
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bundle)](https://github.com/Homebrew/homebrew-bundle) or

## Demo

![krewfile demo](docs/term-animation.svg)
![krewfile demo](docs/demo.gif)

## Usage

Expand Down
56 changes: 0 additions & 56 deletions ci/type-command.sh

This file was deleted.

28 changes: 28 additions & 0 deletions demo.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Output demo.gif

Set Theme nord
Set WindowBar Colorful

Type "krew list"
Enter
Sleep 1s

Enter
Type "echo 'explore' > /root/.krewfile"
Enter
Sleep 1s

Enter
Type "krewfile --help"
Enter
Sleep 1s

Enter
Type "krewfile"
Enter
Sleep 5s

Enter
Type "krew list"
Enter
Sleep 2s
Binary file added docs/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion docs/term-animation.svg

This file was deleted.

16 changes: 2 additions & 14 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
packages = with pkgs; [
go

# for terminal gifs
nodejs
nodePackages.npm
pv
asciinema
(pkgs.writeShellScriptBin "gen-term-animations" ''
npx svg-term \
--command="bash ./ci/type-command.sh" \
--out docs/term-animation.svg \
--window=true \
--width=80
'')
go_1_22
earthly
];

shellHook = '''';
Expand Down

0 comments on commit da6dc37

Please sign in to comment.