Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format-go boilerplate #42

Merged
merged 1 commit into from
Mar 30, 2023
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
Add format-go boilerplate
  • Loading branch information
ashishb committed Mar 30, 2023
commit a35fd85d14b9b1ab2ce90867b5360a05a39570d6
33 changes: 21 additions & 12 deletions src/gabo/internal/generator/all_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
type Option string

const (
_BuildAndroid Option = "build-android"
_BuildDocker Option = "build-docker"

_FormatGo Option = "format-go"

_LintAndroid Option = "lint-android"
_LintDocker Option = "lint-docker"
_LintGo Option = "lint-go"
Expand All @@ -19,8 +24,6 @@ const (
_LintSolidity Option = "lint-solidity"
_LintYaml Option = "lint-yaml"

_BuildAndroid Option = "build-android"
_BuildDocker Option = "build-docker"
_TranslateAndroid Option = "translate-android"

// _LintHtml Option = "lint-html"
Expand All @@ -32,11 +35,11 @@ const (
)

var _options = []Option{
_TranslateAndroid,

_BuildAndroid,
_BuildDocker,

_FormatGo,

_LintAndroid,
_LintDocker,
_LintGo,
Expand All @@ -45,6 +48,8 @@ var _options = []Option{
_LintShellScript,
_LintSolidity,
_LintYaml,

_TranslateAndroid,
}

func GetOptions() []string {
Expand All @@ -67,6 +72,12 @@ func IsValid(val string) bool {
// repoDir is root dir of the repository
func (option Option) getOutputFileName(repoDir string) string {
switch option {
case _BuildAndroid:
return getPath(repoDir, "build-android.yaml")
case _BuildDocker:
return getPath(repoDir, "build-docker.yaml")
case _FormatGo:
return getPath(repoDir, "format-go.yaml")
case _LintAndroid:
return getPath(repoDir, "lint-android.yaml")
case _LintDocker:
Expand All @@ -84,10 +95,6 @@ func (option Option) getOutputFileName(repoDir string) string {
case _LintYaml:
return getPath(repoDir, "lint-yaml.yaml")

case _BuildAndroid:
return getPath(repoDir, "build-android.yaml")
case _BuildDocker:
return getPath(repoDir, "build-docker.yaml")
case _TranslateAndroid:
return getPath(repoDir, "translate-android.yaml")
default:
Expand All @@ -98,6 +105,12 @@ func (option Option) getOutputFileName(repoDir string) string {

func (option Option) getYamlConfig(repoDir string) (*string, error) {
switch option {
case _BuildAndroid:
return generateBuildAndroidYaml(repoDir)
case _BuildDocker:
return generateBuildDockerYaml(repoDir)
case _FormatGo:
return &_formatGoYaml, nil
case _LintAndroid:
return &_lintAndroidYaml, nil
case _LintDocker:
Expand All @@ -115,10 +128,6 @@ func (option Option) getYamlConfig(repoDir string) (*string, error) {
case _LintYaml:
return &_lintYamlYaml, nil

case _BuildAndroid:
return generateBuildAndroidYaml(repoDir)
case _BuildDocker:
return generateBuildDockerYaml(repoDir)
case _TranslateAndroid:
return &_translateAndroidYaml, nil

Expand Down
54 changes: 54 additions & 0 deletions src/gabo/internal/generator/data/format-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
name: Validate Go code formatting

on: # yamllint disable-line rule:truthy
push:
branches: [main, master]
paths:
- "**/*.go"
- ".github/workflows/format-go.yaml"
pull_request:
branches: [main, master]
paths:
- "**/*.go"
- ".github/workflows/format-go.yaml"


concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

validateCodeFormatGo:
runs-on: ubuntu-latest
timeout-minutes: 15

strategy:
matrix:
# Without quotes, 1.20 becomes 1.2!
go-version: ["1.20"]
steps:
- name: checkout
uses: actions/checkout@v3

- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

# Ref: https://github.com/actions/cache/blob/main/examples.md#go---modules
# Warning: This is Linux specific
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Validate code formatting
run: |
gofmt -l .
test -z $(gofmt -l .)
2 changes: 2 additions & 0 deletions src/gabo/internal/generator/yaml_embed_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package generator
import _ "embed"

var (
//go:embed data/format-go.yaml
_formatGoYaml string
//go:embed data/lint-android.yaml
_lintAndroidYaml string
//go:embed data/lint-docker.yaml
Expand Down