Skip to content

Commit

Permalink
feat: allow fogg ci to be configured with runners
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeyheath committed May 11, 2023
1 parent 954f930 commit 145dfe6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
3 changes: 2 additions & 1 deletion config/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ type CircleCI struct {
type GitHubActionsCI struct {
CommonCI `yaml:",inline"`

SSHKeySecrets []string `yaml:"ssh_key_secrets"`
SSHKeySecrets []string `yaml:"ssh_key_secrets"`
RunsOn *[]string `yaml:"runs_on,omitempty"`
}

type Env struct {
Expand Down
13 changes: 12 additions & 1 deletion plan/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type CircleCIConfig struct {
type GitHubActionsCIConfig struct {
CIConfig
SSHKeySecrets []string
RunsOn []string
}

type TravisCIConfig struct {
Expand Down Expand Up @@ -335,15 +336,25 @@ func (p *Plan) buildGitHubActionsConfig(c *v2.Config, foggVersion string) GitHub
}
}

var sshKeySecrets []string
var (
sshKeySecrets []string
runsOn []string
)

if c.Defaults.Tools != nil && c.Defaults.Tools.GitHubActionsCI != nil {
sshKeySecrets = c.Defaults.Tools.GitHubActionsCI.SSHKeySecrets
}

if c.Defaults.Tools != nil &&
c.Defaults.Tools.GitHubActionsCI != nil &&
c.Defaults.Tools.GitHubActionsCI.RunsOn != nil {
runsOn = *c.Defaults.Tools.GitHubActionsCI.RunsOn
}

ciConfig = ciConfig.populateBuckets(numBuckets)
return GitHubActionsCIConfig{
CIConfig: *ciConfig,
SSHKeySecrets: sshKeySecrets,
RunsOn: runsOn,
}
}
21 changes: 21 additions & 0 deletions templates/templates/.github/workflows/fogg_ci.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ concurrency:

jobs:
fogg-apply:
{{ if (eq (len $githubActionsCI.RunsOn) 0) -}}
runs-on: ubuntu-latest
{{ else -}}
runs-on: [{{ range $index, $element := $githubActionsCI.RunsOn -}}
{{if $index}},{{end -}}
{{$element -}}
{{end -}}]
{{ end -}}
steps:
- name: Generate token
id: generate_token
Expand Down Expand Up @@ -46,7 +53,14 @@ jobs:
message: |
commit from fogg_ci -- ran fogg apply and pushed
find-changed-dirs:
{{ if (eq (len $githubActionsCI.RunsOn) 0) -}}
runs-on: ubuntu-latest
{{ else -}}
runs-on: [{{ range $index, $element := $githubActionsCI.RunsOn -}}
{{if $index}},{{end -}}
{{$element -}}
{{end -}}]
{{ end -}}
outputs:
allChanges: {{`${{ steps.changedDirs.outputs.allChanges }}`}}
steps:
Expand Down Expand Up @@ -76,7 +90,14 @@ jobs:
console.log(`changedEnvs: ${JSON.stringify(changedEnvs)}`)
core.setOutput("allChanges", allChanges)
lint-changed-dirs:
{{ if (eq (len $githubActionsCI.RunsOn) 0) -}}
runs-on: ubuntu-latest
{{ else -}}
runs-on: [{{ range $index, $element := $githubActionsCI.RunsOn -}}
{{if $index}},{{end -}}
{{$element -}}
{{end -}}]
{{ end -}}
needs: find-changed-dirs
strategy:
matrix:
Expand Down
6 changes: 3 additions & 3 deletions testdata/github_actions/.github/workflows/fogg_ci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions testdata/github_actions/fogg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ defaults:
command: lint
enabled: true
test_buckets: 7
runs_on:
- self-hosted
- ARM64
version: 2

0 comments on commit 145dfe6

Please sign in to comment.