Skip to content

Commit

Permalink
Merge pull request #24 from grafana/21-github-workflow-support
Browse files Browse the repository at this point in the history
GitHub workflow support
  • Loading branch information
szkiba authored Nov 25, 2024
2 parents 79ba070 + 4d605d9 commit 8995c83
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 78 deletions.
60 changes: 1 addition & 59 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dist: build/dist
builds:
- env:
- CGO_ENABLED=0
goos: ["darwin", "linux", "windows"]
goos: ["linux", "windows"]
goarch: ["amd64", "arm64"]
ldflags:
- "-s -w -X main.version={{.Version}} -X main.appname={{.ProjectName}}"
Expand Down Expand Up @@ -39,61 +39,3 @@ changelog:
- "^chore:"
- "^docs:"
- "^test:"

dockers:
- id: amd64
dockerfile: Dockerfile.goreleaser
use: buildx
image_templates:
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:v{{ .Major }}-amd64"
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}-amd64"
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:latest-amd64"

build_flag_templates:
- "--platform=linux/amd64"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.licenses=AGPL-3.0-only"
- id: arm64
dockerfile: Dockerfile.goreleaser
use: buildx
image_templates:
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:{{ .Tag }}-arm64"
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:v{{ .Major }}-arm64"
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}-arm64"
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:latest-arm64"

build_flag_templates:
- "--platform=linux/arm64"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.licenses=AGPL-3.0-only"

docker_manifests:
- id: tag
name_template: "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:{{ .Tag }}"
image_templates:
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:{{ .Tag }}-arm64"
- id: major
name_template: "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:v{{ .Major }}"
image_templates:
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:v{{ .Major }}-amd64"
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:v{{ .Major }}-arm64"
- id: major-minor
name_template: "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}"
image_templates:
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}-amd64"
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}-arm64"
- id: latest
name_template: "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:latest"
image_templates:
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:latest-amd64"
- "{{ .Env.IMAGE_OWNER }}/{{ .ProjectName }}:latest-arm64"
11 changes: 0 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,6 @@ goreleaser build --snapshot --clean --single-target -o k6lint

[snapshot]: <#snapshot---creating-an-executable-binary-with-a-snapshot-version>

### docker - Build docker image

Building a Docker image. Before building the image, it is advisable to perform a snapshot build using goreleaser. To build the image, it is advisable to use the same `Docker.goreleaser` file that `goreleaser` uses during release.

Requires
: snapshot

```bash
docker build -t k6lint -f Dockerfile.goreleaser .
```

### clean - Delete the build directory

```bash
Expand Down
8 changes: 0 additions & 8 deletions Dockerfile.goreleaser

This file was deleted.

42 changes: 42 additions & 0 deletions cmd/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"fmt"
"log/slog"
"os"
"path/filepath"

"github.com/grafana/k6lint"
)

//nolint:forbidigo
func isGitHubAction() bool {
return os.Getenv("GITHUB_ACTIONS") == "true"
}

//nolint:forbidigo
func emitOutput(compliance *k6lint.Compliance) error {
ghOutput := os.Getenv("GITHUB_OUTPUT")
if len(ghOutput) == 0 {
return nil
}

file, err := os.Create(filepath.Clean(ghOutput))
if err != nil {
return err
}

slog.Debug("Compliance", "grade", compliance.Grade, "level", compliance.Level)

_, err = fmt.Fprintf(file, "grade=%s\n", compliance.Grade)
if err != nil {
return err
}

_, err = fmt.Fprintf(file, "level=%d\n", compliance.Level)
if err != nil {
return err
}

return file.Close()
}
6 changes: 6 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ func run(ctx context.Context, args []string, opts *options) (result error) {
return err
}

if isGitHubAction() {
if err := emitOutput(compliance); err != nil {
return err
}
}

if opts.quiet {
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions releases/v0.3.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
k6lint `v0.3.2` is here 🎉!

Tweaks in this release:

- Emit `grade` and `level` output variables if runing inside of GitHub workflow.

0 comments on commit 8995c83

Please sign in to comment.