This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
[WIP] Feature/poc GitHub actions #69
Open
botchk
wants to merge
23
commits into
main
Choose a base branch
from
feature/poc-github-actions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6520485
Add types from Act
didiladi 870b804
Add test data
didiladi da06129
Read action.yaml from github
didiladi e9b7053
add the reader
didiladi a55eecb
Add minimal config for github actions
didiladi c1fe76e
implement skeleton for putting all the pieces together
didiladi 94e2551
Add conversion of github action inputs to kubernetes job arguments
botchk 07d66de
wire together arg handling and mapping back
didiladi 06d6b02
Fix uses prefix -> always use master in POC
didiladi dda660a
added building of actions
afc7c98
Merge branch 'feature/poc-github-actions' of github.com:keptn-sandbox…
ef1a4f7
fix compile errors
botchk e6377a8
fix bug
botchk b746361
disable failing test
botchk 47d7745
actually execute the action
botchk 9587c8f
use correct secret for kaniko
botchk 579cf79
fix argument formatting
botchk 5148d60
improve logging and fix k8s connect to be only once
botchk fca8bab
fix issue with wrong image location passed to kaniko
botchk 80116b3
removed security context
00c75bc
remove securitycontext for builder
botchk b249f3f
add env for container registry
botchk 2894faf
Remove securityContext from job. Disable file mounting for github act…
botchk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
creationTimestamp: null | ||
labels: | ||
app: registry | ||
name: registry | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: registry | ||
strategy: {} | ||
template: | ||
metadata: | ||
creationTimestamp: null | ||
labels: | ||
app: registry | ||
spec: | ||
containers: | ||
- image: registry:2 | ||
name: registry | ||
ports: | ||
- containerPort: 5000 | ||
resources: {} | ||
status: {} | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
creationTimestamp: null | ||
labels: | ||
app: registry | ||
name: registry | ||
spec: | ||
ports: | ||
- port: 5000 | ||
protocol: TCP | ||
targetPort: 5000 | ||
selector: | ||
app: registry | ||
status: | ||
loadBalancer: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package github | ||
|
||
import ( | ||
"fmt" | ||
"keptn-sandbox/job-executor-service/pkg/github/model" | ||
"log" | ||
"strings" | ||
) | ||
|
||
func PrepareArgs(with map[string]string, inputs map[string]model.Input, args []string) ([]string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golint] reported by reviewdog 🐶 |
||
var filledArgs []string | ||
|
||
for inputKey, inputValue := range inputs { | ||
argKey := fmt.Sprintf("inputs.%s", inputKey) | ||
log.Printf("argKey: %v", argKey) | ||
|
||
for _, arg := range args { | ||
if strings.Contains(arg, argKey) { | ||
log.Printf("matched argKey: %v", argKey) | ||
|
||
argValue := inputValue.Default | ||
if withValue, ok := with[inputKey]; ok { | ||
argValue = withValue | ||
} else { | ||
if inputValue.Required { | ||
return nil, fmt.Errorf("required input '%s' not provided", inputKey) | ||
} | ||
} | ||
|
||
splittedArg := strings.Split(arg, "$") | ||
arg := strings.TrimSpace(splittedArg[0]) | ||
filledArgs = append(filledArgs, arg) | ||
filledArgs = append(filledArgs, argValue) | ||
} | ||
} | ||
} | ||
|
||
return filledArgs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package github | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gofmt] reported by reviewdog 🐶 |
||
|
||
import ( | ||
"gotest.tools/assert" | ||
"keptn-sandbox/job-executor-service/pkg/github/model" | ||
"log" | ||
"testing" | ||
) | ||
|
||
func TestPrepareArgs(t *testing.T) { | ||
with := map[string]string{"scan-type": "banana", "format": "cucumber"} | ||
inputs := map[string]model.Input{ | ||
"scan-type": { | ||
Required: false, | ||
Default: "", | ||
}, | ||
"format": { | ||
Required: false, | ||
Default: "", | ||
}, | ||
"template": { | ||
Required: false, | ||
Default: "table", | ||
}, | ||
} | ||
args := []string{"-a ${{ inputs.scan-type }}", "-b ${{ inputs.format }}", "-c ${{ inputs.template }}"} | ||
k8sArgs, err := PrepareArgs(with, inputs, args) | ||
assert.NilError(t, err) | ||
log.Printf("%v", k8sArgs) | ||
} | ||
|
||
func TestPrepareArgs_RequiredInput(t *testing.T) { | ||
with := map[string]string{} | ||
inputs := map[string]model.Input{ | ||
"scan-type": { | ||
Required: true, | ||
Default: "", | ||
}, | ||
} | ||
args := []string{"-a ${{ inputs.scan-type }}"} | ||
_, err := PrepareArgs(with, inputs, args) | ||
assert.Error(t, err, "required input 'scan-type' not provided") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package model | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gofmt] reported by reviewdog 🐶 |
||
|
||
import ( | ||
"gopkg.in/yaml.v3" | ||
"io" | ||
) | ||
|
||
// ActionRunsUsing is the type of runner for the action | ||
type ActionRunsUsing string | ||
|
||
const ( | ||
// ActionRunsUsingNode12 for running with node12 | ||
ActionRunsUsingNode12 = "node12" | ||
// ActionRunsUsingDocker for running with docker | ||
ActionRunsUsingDocker = "docker" | ||
// ActionRunsUsingComposite for running composite | ||
ActionRunsUsingComposite = "composite" | ||
) | ||
|
||
// ActionRuns are a field in Action | ||
type ActionRuns struct { | ||
Using ActionRunsUsing `yaml:"using"` | ||
Env map[string]string `yaml:"env"` | ||
Main string `yaml:"main"` | ||
Image string `yaml:"image"` | ||
Entrypoint []string `yaml:"entrypoint"` | ||
Args []string `yaml:"args"` | ||
Steps []Step `yaml:"steps"` | ||
} | ||
|
||
// Action describes a metadata file for GitHub actions. The metadata filename must be either action.yml or action.yaml. The data in the metadata file defines the inputs, outputs and main entrypoint for your action. | ||
type Action struct { | ||
Name string `yaml:"name"` | ||
Author string `yaml:"author"` | ||
Description string `yaml:"description"` | ||
Inputs map[string]Input `yaml:"inputs"` | ||
Outputs map[string]Output `yaml:"outputs"` | ||
Runs ActionRuns `yaml:"runs"` | ||
Branding struct { | ||
Color string `yaml:"color"` | ||
Icon string `yaml:"icon"` | ||
} `yaml:"branding"` | ||
} | ||
|
||
// Input parameters allow you to specify data that the action expects to use during runtime. GitHub stores input parameters as environment variables. Input ids with uppercase letters are converted to lowercase during runtime. We recommended using lowercase input ids. | ||
type Input struct { | ||
Description string `yaml:"description"` | ||
Required bool `yaml:"required"` | ||
Default string `yaml:"default"` | ||
} | ||
|
||
// Output parameters allow you to declare data that an action sets. Actions that run later in a workflow can use the output data set in previously run actions. For example, if you had an action that performed the addition of two inputs (x + y = z), the action could output the sum (z) for other actions to use as an input. | ||
type Output struct { | ||
Description string `yaml:"description"` | ||
Value string `yaml:"value"` | ||
} | ||
|
||
// ReadAction reads an action from a reader | ||
func ReadAction(in io.Reader) (*Action, error) { | ||
a := new(Action) | ||
err := yaml.NewDecoder(in).Decode(a) | ||
return a, err | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[gofmt] reported by reviewdog 🐶
file pkg/github/github.go is not gofmted