Skip to content

Commit

Permalink
chore: add release automation
Browse files Browse the repository at this point in the history
  • Loading branch information
armsnyder committed Jun 23, 2024
1 parent cd8ba00 commit e7aeffe
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 43 deletions.
37 changes: 37 additions & 0 deletions .github/.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json

version: 2

builds:
- goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
ldflags:
- "-X main.version={{ .Version }}"

universal_binaries:
- replace: false

archives:
- format: tar.gz
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "all" }}universal
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
format_overrides:
- goos: windows
format: zip
wrap_in_directory: true

checksum:
name_template: checksums.txt

changelog:
disable: true
6 changes: 6 additions & 0 deletions .github/release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"release-type": "go",
"packages": {},
"bump-minor-pre-major": true
}
73 changes: 73 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow

on:
push:
branches:
- main
pull_request: {}

jobs:
check-generated:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- run: go mod tidy
- run: go generate ./...
- run: git diff --exit-code

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- run: go install
- run: go test -cover ./...

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- uses: golangci/golangci-lint-action@v4
with:
version: v1.59.1

release-please:
runs-on: ubuntu-latest
needs: [check-generated, test, lint]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
outputs:
release_created: ${{ steps.release-please.outputs.release_created }}
tag_name: ${{ steps.release-please.outputs.tag_name }}
version: ${{ steps.release-please.outputs.version }}
steps:
- uses: googleapis/release-please-action@v4
with:
token: ${{ secrets.PAT }}
config-file: .github/release-please-config.json

release:
runs-on: ubuntu-latest
needs: [release-please]
if: needs.release-please.outputs.release_created
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --tags --force
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- uses: goreleaser/goreleaser-action@v6
with:
version: "~> v2"
args: release --clean --config .github/.goreleaser.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 0 additions & 38 deletions .github/workflows/test.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.out
/openapiv3-lsp
/dist
/tmp
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ for me to implement in this language server.

## Features


### Language Features

- [x] Jump to definition
Expand All @@ -36,10 +35,18 @@ for me to implement in this language server.

## Installation

### Using Go

```bash
go install github.com/armsnyder/openapiv3-lsp@latest
```

### From GitHub Releases

Download the latest release from [GitHub releases](https://github.com/armsnyder/openapiv3-lsp/releases).

## Usage

### Neovim Configuration Example

Assuming you are using Neovim and have the installed openapiv3-lsp binary in
Expand All @@ -52,6 +59,7 @@ your PATH, you can use the following Lua code to your Neovim configuration:
vim.lsp.start {
cmd = { 'openapiv3-lsp' },
filetypes = { 'yaml' },
root_dir = vim.fn.getcwd(),
}
end,
})
Expand Down
104 changes: 100 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"flag"
"fmt"
"io"
"log"
"os"

Expand All @@ -9,20 +12,113 @@ import (
"github.com/armsnyder/openapiv3-lsp/internal/lsp/types"
)

// NOTE(asanyder): Version is set by release-please.
const Version = "0.1.0"

func main() {
log.SetFlags(0)
// Parse command line flags.

var args struct {
version bool
help bool
testdata string
}

flag.BoolVar(&args.version, "version", false, "Print the version and exit")
flag.BoolVar(&args.version, "v", false, "Print the version and exit")
flag.BoolVar(&args.help, "help", false, "Print this help message and exit")
flag.BoolVar(&args.help, "h", false, "Print this help message and exit")
flag.StringVar(&args.testdata, "testdata", "", "Capture a copy of all input and output to the specified directory. Useful for debugging or generating test data.")

flag.Parse()

// Handle special flags.

if args.version {
//nolint:forbidigo // use of fmt.Println
fmt.Println(Version)
return
}

if args.help {
flag.Usage()
return
}

// Configure logging.

log.SetFlags(log.Lshortfile)

// Configure input and output.

var reader io.Reader = os.Stdin
var writer io.Writer = os.Stdout

if args.testdata != "" {
if err := os.MkdirAll(args.testdata, 0o755); err != nil {
log.Fatal("Failed to create testdata directory: ", err)
}

inputFile, err := os.Create(args.testdata + "/input.jsonrpc")
if err != nil {
log.Fatal("Failed to create input file: ", err)
}
defer inputFile.Close()

outputFile, err := os.Create(args.testdata + "/output.jsonrpc")
if err != nil {
//nolint:gocritic // exitAfterDefer
log.Fatal("Failed to create output file: ", err)
}
defer outputFile.Close()

reader = io.TeeReader(reader, inputFile)
writer = io.MultiWriter(writer, outputFile)
}

// Run the LSP server.

server := &lsp.Server{
ServerInfo: types.ServerInfo{
Name: "openapiv3-lsp",
Version: "0.1.0",
Version: Version,
},
Reader: os.Stdin,
Writer: os.Stdout,
Reader: reader,
Writer: writer,
Handler: &analysis.Handler{},
}

if err := server.Run(); err != nil {
log.Fatal("LSP server error: ", err)
}
}

// shadowReader wraps a primary reader and splits the input to a secondary
// writer.
type shadowReader struct {
reader io.Reader
shadow io.Writer
}

func (r shadowReader) Read(p []byte) (n int, err error) {
n, err = r.reader.Read(p)
_, _ = r.shadow.Write(p[:n])
return n, err
}

var _ io.Reader = shadowReader{}

// shadowWriter wraps a primary writer and splits the output to a secondary
// writer.
type shadowWriter struct {
writer io.Writer
shadow io.Writer
}

func (w shadowWriter) Write(p []byte) (n int, err error) {
n, err = w.writer.Write(p)
_, _ = w.shadow.Write(p)
return n, err
}

var _ io.Writer = shadowWriter{}

0 comments on commit e7aeffe

Please sign in to comment.