Skip to content

Commit

Permalink
feat: integrate GoReleaser for releasing binaries (#6)
Browse files Browse the repository at this point in the history
* chore: add release workflow with GoReleaser tool
* Fix linting issues
* Activate release workflow on push in main branch
* Disable releasing from old GH actions workflow
  • Loading branch information
pavel-snyk authored Mar 1, 2022
1 parent 1bbbe99 commit e0dd7c7
Show file tree
Hide file tree
Showing 24 changed files with 285 additions and 113 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release
on:
push:
branches:
- 'main'

jobs:
release:
name: goreleaser
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Unshallow
run: git fetch --prune --unshallow

# this step can be removed if setup-go will support reading go-version from go.mod
- name: Determine Go version
run: |
sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Set up Snyk CLI
uses: snyk/actions/setup@master

- name: Cache Go modules
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-

- name: Lint source code
run: |
make tools lint
- name: Run tests
env:
DEEPROXY_API_URL: ${{secrets.DEEPROXY_API_URL}}
SNYK_TOKEN: ${{secrets.SNYK_TOKEN }}
run: |
make clean test
- name: Set up Git actions user
uses: fregante/setup-git-user@v1

- name: Create release tag
run: |
git tag "v$(date +'%Y%m%d.%H%M%S')"
git push --tags
sudo mv snyk-linux* /usr/local/bin/
- name: Release binaries with GoReleaser
uses: goreleaser/goreleaser-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: release --rm-dist
19 changes: 10 additions & 9 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ jobs:
version: latest
files: output/*
args: "-9f --lzma"
- uses: "marvinpinto/action-automatic-releases@latest"
if: ${{ github.event_name == 'push' && !env.ACT }}
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{ env.NOW }}"
prerelease: false
title: "${{ env.NOW }}"
files: |
output/*
# TODO(pavel): refactor the current workflow after https://github.com/snyk/snyk-lsp/pull/6 is merged
# - uses: "marvinpinto/action-automatic-releases@latest"
# if: ${{ github.event_name == 'push' && !env.ACT }}
# with:
# repo_token: "${{ secrets.GITHUB_TOKEN }}"
# automatic_release_tag: "${{ env.NOW }}"
# prerelease: false
# title: "${{ env.NOW }}"
# files: |
# output/*
42 changes: 42 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
project_name: "snyk-lsp"

archives:
- format: zip
name_template: "{{ .ProjectName }}_{{ .Version}}_{{ .Os }}_{{ .Arch }}"

before:
hooks:
- go mod tidy

builds:
- flags:
- -trimpath
goarch:
- "386"
- amd64
- arm64
goos:
- darwin
- linux
- windows
ignore:
- goarch: "386"
goos: darwin
- goarch: arm64
goos: windows
ldflags:
- -s -w -X main.gitinfo={{.Version}}
mod_timestamp: "{{ .CommitTimestamp }}"
hooks:
post:
- upx -9fv --lzma "{{ .Path }}"

checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS"
algorithm: sha256

dist: build

env:
- GO111MODULE=on
- CGO_ENABLED=0
9 changes: 0 additions & 9 deletions .idea/.gitignore

This file was deleted.

8 changes: 5 additions & 3 deletions code/backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"

"github.com/rs/zerolog/log"
sglsp "github.com/sourcegraph/go-lsp"

"github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
sglsp "github.com/sourcegraph/go-lsp"
"io/ioutil"
"net/http"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion code/backend_service_interface.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package code

import (
"github.com/snyk/snyk-lsp/lsp"
sglsp "github.com/sourcegraph/go-lsp"

"github.com/snyk/snyk-lsp/lsp"
)

type BackendService interface {
Expand Down
8 changes: 5 additions & 3 deletions code/backend_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package code

import (
"encoding/json"
"github.com/snyk/snyk-lsp/util"
sglsp "github.com/sourcegraph/go-lsp"
"github.com/stretchr/testify/assert"
"net/http"
"os"
"testing"
"time"

sglsp "github.com/sourcegraph/go-lsp"
"github.com/stretchr/testify/assert"

"github.com/snyk/snyk-lsp/util"
)

const (
Expand Down
10 changes: 6 additions & 4 deletions code/bundle.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package code

import (
"github.com/rs/zerolog/log"
"github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
sglsp "github.com/sourcegraph/go-lsp"
"path/filepath"
"sync"
"time"

"github.com/rs/zerolog/log"
sglsp "github.com/sourcegraph/go-lsp"

"github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
)

var (
Expand Down
10 changes: 6 additions & 4 deletions code/bundle_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package code

import (
lsp2 "github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
"github.com/sourcegraph/go-lsp"
"github.com/stretchr/testify/assert"
"reflect"
"sync"
"testing"

"github.com/sourcegraph/go-lsp"
"github.com/stretchr/testify/assert"

lsp2 "github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
)

var (
Expand Down
10 changes: 6 additions & 4 deletions code/fake_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package code

import (
"fmt"
"github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
sglsp "github.com/sourcegraph/go-lsp"
"math/rand"
"path/filepath"

sglsp "github.com/sourcegraph/go-lsp"

"github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
)

var (
Expand All @@ -27,7 +29,7 @@ var (
Code: "SNYK-123",
Source: "snyk code",
Message: "This is a dummy error (severity error)",
//CodeDescription: lsp.CodeDescription{Href: "https://snyk.io"},
// CodeDescription: lsp.CodeDescription{Href: "https://snyk.io"},
}
FakeCodeLens = sglsp.CodeLens{
Range: sglsp.Range{
Expand Down
3 changes: 2 additions & 1 deletion diagnostics/code_lenses_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package diagnostics

import (
"testing"

sglsp "github.com/sourcegraph/go-lsp"
"github.com/stretchr/testify/assert"
"testing"
)

var (
Expand Down
6 changes: 4 additions & 2 deletions diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package diagnostics

import (
"sync"

"github.com/rs/zerolog/log"
sglsp "github.com/sourcegraph/go-lsp"

"github.com/snyk/snyk-lsp/code"
"github.com/snyk/snyk-lsp/iac"
"github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/oss"
sglsp "github.com/sourcegraph/go-lsp"
"sync"
)

var (
Expand Down
8 changes: 5 additions & 3 deletions diagnostics/diagnostics_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package diagnostics

import (
"github.com/snyk/snyk-lsp/code"
"github.com/snyk/snyk-lsp/lsp"
"testing"

sglsp "github.com/sourcegraph/go-lsp"
"github.com/stretchr/testify/assert"
"testing"

"github.com/snyk/snyk-lsp/code"
"github.com/snyk/snyk-lsp/lsp"
)

var (
Expand Down
16 changes: 9 additions & 7 deletions iac/iac.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package iac
import (
"encoding/json"
"fmt"
"github.com/gomarkdown/markdown"
"github.com/rs/zerolog/log"
"github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
sglsp "github.com/sourcegraph/go-lsp"
"os/exec"
"path/filepath"
"strings"
"sync"

"github.com/gomarkdown/markdown"
"github.com/rs/zerolog/log"
sglsp "github.com/sourcegraph/go-lsp"

"github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
)

var (
Expand Down Expand Up @@ -142,9 +144,9 @@ func convertDiagnostics(res testResult) []lsp.Diagnostic {
},
Severity: lspSeverity(issue.Severity),
Code: issue.PublicID,
//CodeDescription: lsp.CodeDescription{
// CodeDescription: lsp.CodeDescription{
// Href: issue.Documentation,
//},
// },
}
diagnostics = append(diagnostics, diagnostic)
}
Expand Down
12 changes: 7 additions & 5 deletions iac/iac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package iac

import (
"encoding/json"
lsp2 "github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
"github.com/sourcegraph/go-lsp"
"github.com/stretchr/testify/assert"
"os"
"path/filepath"
"strings"
"sync"
"testing"

"github.com/sourcegraph/go-lsp"
"github.com/stretchr/testify/assert"

lsp2 "github.com/snyk/snyk-lsp/lsp"
"github.com/snyk/snyk-lsp/util"
)

func Test_HandleFile(t *testing.T) {
Expand Down Expand Up @@ -52,7 +54,7 @@ func Test_convertCodeLenses_shouldOneCodeLensPerIssue(t *testing.T) {
bytes, _ := os.ReadFile("testdata/RBAC-iac-result.json")

var iacResult testResult
json.Unmarshal(bytes, &iacResult)
_ = json.Unmarshal(bytes, &iacResult)
assert.NotNil(t, iacResult)
assert.True(t, len(iacResult.IacIssues) > 0)

Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"bytes"
"flag"
"fmt"
"os"
"time"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/snyk/snyk-lsp/server"
"github.com/snyk/snyk-lsp/util"
"os"
"time"
)

var gitinfo = "SNAPSHOT" // set by build via go build -ldflags "-X main.gitinfo=xxx"
Expand Down
Loading

0 comments on commit e0dd7c7

Please sign in to comment.