Skip to content

Commit

Permalink
Merge pull request #23 from kralicky/ci
Browse files Browse the repository at this point in the history
Add simple test & binary release CI
  • Loading branch information
kralicky authored May 23, 2024
2 parents 4f86485 + abc9228 commit 5fcc252
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 2 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on:
pull_request:
paths-ignore:
- 'docs/**'
- '*.md'
- '.gitignore'
push:
branches:
- main
paths-ignore:
- 'docs/**'
- '*.md'
- '.gitignore'

permissions:
contents: read

jobs:
test-protols:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Test
run: go test -v -timeout 30s -coverprofile=cover.out -covermode=atomic -coverpkg=./... -race ./...
- name: Upload coverage
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./cover.out
flags: unittests
verbose: true

29 changes: 29 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name : Release

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v5
with:
go-version: 1.22
cache : false # prevents cache poisoning for release artifacts through go mod cache
- uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
go.work
go.work.sum
editors/vscode/*.vsix
dist
42 changes: 42 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- id: protols
main: ./cmd/protols
goos:
- linux
goarch:
- amd64
binary: protols
ldflags:
- -extldflags "-static"
- -s
- -w
- -X github.com/kralicky/protols/pkg/version.Version={{.Version}}
- -X github.com/kralicky/protols/pkg/version.Commit={{.Commit}}
flags:
- -trimpath
env:
- CGO_ENABLED=0

archives:
- id: protols
builds:
- protols
name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
checksum:
name_template: 'checksums.txt'
release:
prerelease : auto
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Protobuf Language Server

![Release](https://img.shields.io/github/v/release/kralicky/protols)
[![CI](https://github.com/kralicky/protols/actions/workflows/ci.yaml/badge.svg)](https://github.com/kralicky/protols/actions/workflows/test.yaml)
[![License](https://img.shields.io/github/license/kralicky/protols)](./LICENSE)

# Coming Soon™

A language server implementation for Protocol Buffers. Still in development.
Expand Down
2 changes: 2 additions & 0 deletions pkg/protols/commands/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"

"github.com/kralicky/protols/pkg/lsprpc"
"github.com/kralicky/protols/pkg/version"
"github.com/kralicky/tools-lite/pkg/event"
"github.com/kralicky/tools-lite/pkg/event/core"
"github.com/kralicky/tools-lite/pkg/event/keys"
Expand All @@ -24,6 +25,7 @@ func BuildServeCmd() *cobra.Command {
Use: "serve",
Short: "Start the language server",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Printf("Starting protols %s\n", version.FriendlyVersion())
slog.SetDefault(slog.New(slog.NewTextHandler(cmd.OutOrStderr(), &slog.HandlerOptions{
AddSource: true,
Level: slog.LevelDebug,
Expand Down
6 changes: 4 additions & 2 deletions pkg/protols/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"os"

"github.com/kralicky/protols/pkg/protols/commands"
"github.com/kralicky/protols/pkg/version"
"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
func BuildRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "protols",
Short: "Protobuf Language Server",
Use: "protols",
Short: "Protobuf Language Server",
Version: version.FriendlyVersion(),
}

rootCmd.AddCommand(commands.BuildFmtCmd())
Expand Down
13 changes: 13 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package version

import "fmt"

var (
Version = "v0.0.0-dev"
GitCommit = "HEAD"
)

// FriendlyVersion returns the version to be displayed on running --version
func FriendlyVersion() string {
return fmt.Sprintf("%s (%s)", Version, GitCommit)
}

0 comments on commit 5fcc252

Please sign in to comment.