Skip to content
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
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.git
.idea
.vscode
.claude
.DS_Store
_docs
mmd-cli
mmd-cli-*
*.svg
*.png
*.pdf
compose.yaml
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release

on:
push:
tags:
- "v*"

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25"

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Tests

on:
push:
branches:
- "**"
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25"

- name: Run tests
run: go clean -testcache && go test ./...
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mmd-cli
/bin/
/dist/
*.test
coverage.out
coverage.html
go.work
go.work.sum
.idea/
.vscode/
.DS_Store
Thumbs.db
*.svg
*.png
*.pdf
!web/*.js
_docs
32 changes: 32 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 2

builds:
- main: ./cmd/mmd-cli
binary: mmd-cli
ldflags:
- -s -w -X github.com/coolamit/mermaid-cli/internal/cli.Version={{.Version}}
goos:
- linux
- darwin
goarch:
- amd64
- arm64

archives:
- format: tar.gz
name_template: "mmd-cli_{{.Version}}_{{ if eq .Os \"darwin\" }}macos{{ else }}{{ .Os }}{{ end }}_{{ if eq .Arch \"amd64\" }}x64{{ else }}{{ .Arch }}{{ end }}"

checksum:
name_template: checksums.txt

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

release:
github:
owner: coolamit
name: mermaid-cli
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM golang:1.25-alpine AS builder

WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o mmd-cli ./cmd/mmd-cli

FROM alpine:3.21

# Install Chromium
RUN apk add --no-cache \
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont \
font-noto-emoji

# Tell chromedp where to find the browser
ENV CHROME_BIN=/usr/bin/chromium-browser

WORKDIR /data

COPY --from=builder /app/mmd-cli /usr/local/bin/mmd-cli

ENTRYPOINT ["mmd-cli"]
109 changes: 109 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Go build configuration
BINARY_NAME=mmd-cli
GO=/usr/local/go/bin/go
GOFMT=/usr/local/go/bin/gofmt
VERSION?=$(shell cat version)
LDFLAGS=-ldflags '-s -w -X github.com/coolamit/mermaid-cli/internal/cli.Version=$(VERSION)'

# Declare phony targets
.PHONY: ssh-cmd up down build clean test tidy format build-linux-x64 build-linux-arm64 build-macos-x64 build-macos-arm64 build-all docker-up docker-down docker-run docker-run-aloof docker-clean

# Common function definitions
define CURRENT_HOMESTEAD_STATUS
cd ../.. && \
if vagrant status | grep -qE "running \(virtualbox\)|running \(parallels\)"; then echo "running"; else echo "stopped"; fi
endef

define SSH_EXEC
PROJECT_NAME=$$(basename $$(pwd)) && \
(cd ../.. && vagrant ssh -- -t "cd code/$$PROJECT_NAME && $(1)")
endef

# This command will start Homestead if it is not already running.
up:
@echo "Checking Homestead status..."
@STATUS=$$($(CURRENT_HOMESTEAD_STATUS)) && \
if [ "$$STATUS" = "running" ]; then \
echo "Homestead is already running."; \
else \
echo "Starting Homestead..." && cd ../.. && vagrant up; \
fi

# This command will stop Homestead if it is running.
down:
@echo "Checking Homestead status..."
@STATUS=$$($(CURRENT_HOMESTEAD_STATUS)) && \
if [ "$$STATUS" = "running" ]; then \
echo "Stopping Homestead..." && cd ../.. && vagrant halt; \
else \
echo "Homestead is NOT currently running."; \
fi

# Command to allow any command to be run in Homestead VM
# Usage: use -- separator before the command
# Example: make ssh-cmd -- ls -alt
# : make ssh-cmd -- mod tidy
ssh-cmd:
@$(call SSH_EXEC,$(filter-out $@,$(MAKECMDGOALS)))

# The wildcard rule is needed to allow for artisan or other ssh commands which can have any name.
# This ensures that the catch-all only matches targets that come after
# 'ssh-cmd' in the command line.
ifneq (,$(filter $(firstword $(MAKECMDGOALS)),ssh-cmd docker-run docker-run-aloof))
%:
@:
endif

# Go build targets (run inside Homestead VM)
build:
@$(call SSH_EXEC,$(GO) build $(LDFLAGS) -o $(BINARY_NAME) ./cmd/mmd-cli)
@echo "Built $(BINARY_NAME)"

test:
@$(call SSH_EXEC,$(GO) clean -testcache && $(GO) test ./...)

tidy:
@$(call SSH_EXEC,$(GO) mod tidy)

format:
@$(call SSH_EXEC,$(GOFMT) -l -w .)

clean:
@$(call SSH_EXEC,rm -f $(BINARY_NAME))
@echo "Cleaned"

# Cross-compilation targets
build-linux-x64:
@$(call SSH_EXEC,GOOS=linux GOARCH=amd64 $(GO) build $(LDFLAGS) -o $(BINARY_NAME)-linux-x64 ./cmd/mmd-cli)

build-linux-arm64:
@$(call SSH_EXEC,GOOS=linux GOARCH=arm64 $(GO) build $(LDFLAGS) -o $(BINARY_NAME)-linux-arm64 ./cmd/mmd-cli)

build-macos-x64:
@$(call SSH_EXEC,GOOS=darwin GOARCH=amd64 $(GO) build $(LDFLAGS) -o $(BINARY_NAME)-macos-x64 ./cmd/mmd-cli)

build-macos-arm64:
@$(call SSH_EXEC,GOOS=darwin GOARCH=arm64 $(GO) build $(LDFLAGS) -o $(BINARY_NAME)-macos-arm64 ./cmd/mmd-cli)

build-all: build-linux-x64 build-linux-arm64 build-macos-x64 build-macos-arm64
@echo "Built all platforms"

# Docker Compose targets (run on host, not in Homestead VM)
docker-up:
docker compose up -d

docker-down:
docker compose stop

# Run a command in the running Docker container.
# Example: make docker-run -- mmd-cli -i diagram.mmd -o diagram.svg
docker-run:
docker compose exec mmd-cli $(filter-out $@,$(MAKECMDGOALS))

# Run mmd-cli in an ephemeral container (no docker-up needed).
# Example: make docker-run-aloof -- -i diagram.mmd -o diagram.svg
docker-run-aloof:
docker compose run --rm --entrypoint mmd-cli mmd-cli $(filter-out $@,$(MAKECMDGOALS))

docker-clean:
docker compose down --rmi local --volumes --remove-orphans
Loading