Skip to content

Commit

Permalink
Format the code and add badges
Browse files Browse the repository at this point in the history
  • Loading branch information
mikogs committed Oct 5, 2024
1 parent 0ce0019 commit 104aa47
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# github-actions-validator

[![Go Reference](https://pkg.go.dev/badge/github.com/Cardinal-Cryptography/github-actions-validator.svg)](https://pkg.go.dev/github.com/Cardinal-Cryptography/github-actions-validator) [![Go Report Card](https://goreportcard.com/badge/github.com/Cardinal-Cryptography/github-actions-validator)](https://goreportcard.com/report/github.com/Cardinal-Cryptography/github-actions-validator) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/Cardinal-Cryptography/github-actions-validator?sort=semver)

Quick tool to validate workflows and actions in .github directory

## Checks
Expand Down
4 changes: 2 additions & 2 deletions pkg/action/action_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (ar *ActionRuns) IsStepOutputExist(step string, output string, d IDotGithub
if m {
action := d.GetAction(strings.Replace(s.Uses, "./.github/actions/", "", -1))
if action != nil {
for duaOutputName, _ := range action.Outputs {
for duaOutputName := range action.Outputs {
if duaOutputName == output {
return 0
}
Expand All @@ -61,7 +61,7 @@ func (ar *ActionRuns) IsStepOutputExist(step string, output string, d IDotGithub
if m {
action := d.GetExternalAction(s.Uses)
if action != nil {
for duaOutputName, _ := range action.Outputs {
for duaOutputName := range action.Outputs {
if duaOutputName == output {
return 0
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/action_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (as *ActionStep) validateUsesExternalAction(actionName string, workflowJobN
func (as *ActionStep) validateEnv(action string, workflowJob string, step string) ([]string, error) {
var validationErrors []string
if as.Env != nil {
for envName, _ := range as.Env {
for envName := range as.Env {
m, err := regexp.MatchString(`^[A-Z][A-Z0-9_]+$`, envName)
if err != nil {
return validationErrors, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (w *Workflow) validateFileName() (string, error) {
func (w *Workflow) validateEnv() ([]string, error) {
var validationErrors []string
if w.Env != nil {
for envName, _ := range w.Env {
for envName := range w.Env {
m, err := regexp.MatchString(`^[A-Z][A-Z0-9_]+$`, envName)
if err != nil {
return validationErrors, err
Expand All @@ -164,7 +164,7 @@ func (w *Workflow) validateMissingFields() ([]string, error) {
func (w *Workflow) validateJobs(d IDotGithub) ([]string, error) {
var validationErrors []string
if len(w.Jobs) == 1 {
for jobName, _ := range w.Jobs {
for jobName := range w.Jobs {
if jobName != "main" {
validationErrors = append(validationErrors, w.formatError("NW106", "When workflow has only one job, it should be named 'main'"))
}
Expand Down Expand Up @@ -267,7 +267,7 @@ func (w *Workflow) validateCalledInputs() ([]string, error) {
}

func (w *Workflow) validateCalledVarsNotInDoubleQuotes() ([]string, error) {

var validationErrors []string
re := regexp.MustCompile(`\"\${{[ ]*([a-zA-Z0-9\\-_.]+)[ ]*}}\"`)
found := re.FindAllSubmatch(w.Raw, -1)
Expand Down
18 changes: 9 additions & 9 deletions pkg/workflow/workflow_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
)

type WorkflowJob struct {
Name string `yaml:"name"`
Uses string `yaml:"uses"`
RunsOn interface{} `yaml:"runs-on"`
Steps []*action.ActionStep `yaml:"steps"`
Env map[string]string `yaml:"env"`
Needs interface{} `yaml:"needs,omitempty"`
Name string `yaml:"name"`
Uses string `yaml:"uses"`
RunsOn interface{} `yaml:"runs-on"`
Steps []*action.ActionStep `yaml:"steps"`
Env map[string]string `yaml:"env"`
Needs interface{} `yaml:"needs,omitempty"`
}

func (wj *WorkflowJob) SetParentType(t string) {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (wj *WorkflowJob) validateName(workflow string, job string) (string, error)
func (wj *WorkflowJob) validateEnv(workflow string, job string) ([]string, error) {
var validationErrors []string
if wj.Env != nil {
for envName, _ := range wj.Env {
for envName := range wj.Env {
m, err := regexp.MatchString(`^[A-Z][A-Z0-9_]+$`, envName)
if err != nil {
return validationErrors, err
Expand Down Expand Up @@ -159,7 +159,7 @@ func (wj *WorkflowJob) IsStepOutputExist(step string, output string, d IDotGithu
if m {
action := d.GetAction(strings.Replace(s.Uses, "./.github/actions/", "", -1))
if action != nil {
for duaOutputName, _ := range action.Outputs {
for duaOutputName := range action.Outputs {
if duaOutputName == output {
return 0
}
Expand All @@ -172,7 +172,7 @@ func (wj *WorkflowJob) IsStepOutputExist(step string, output string, d IDotGithu
if m {
action := d.GetExternalAction(s.Uses)
if action != nil {
for duaOutputName, _ := range action.Outputs {
for duaOutputName := range action.Outputs {
if duaOutputName == output {
return 0
}
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const VERSION = "0.5.2"
const VERSION = "0.5.3"

0 comments on commit 104aa47

Please sign in to comment.