Skip to content

Commit d8662de

Browse files
authored
feat(runner): Integrate runner for CircleCI builds (#437)
Signed-off-by: Mattia Buccarella <[email protected]>
1 parent 05f3dff commit d8662de

File tree

9 files changed

+274
-54
lines changed

9 files changed

+274
-54
lines changed

app/cli/internal/action/workflow_run_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func humanizedRunnerType(in v1.CraftingSchema_Runner_RunnerType) string {
116116
*v1.CraftingSchema_Runner_GITLAB_PIPELINE.Enum(): "GitLab",
117117
*v1.CraftingSchema_Runner_AZURE_PIPELINE.Enum(): "Azure Pipeline",
118118
*v1.CraftingSchema_Runner_JENKINS_JOB.Enum(): "Jenkins Job",
119+
*v1.CraftingSchema_Runner_CIRCLECI_BUILD.Enum(): "CircleCI Build",
119120
}
120121

121122
hrt, ok := mapping[in]

app/cli/internal/action/workflow_run_list_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (s *workflowRunListSuite) TestHumanizedRunnerType() {
5252
name: "jenkins runner",
5353
testInput: v1.CraftingSchema_Runner_JENKINS_JOB,
5454
expectedOutput: "Jenkins Job",
55+
}, {
56+
name: "circleci runner",
57+
testInput: v1.CraftingSchema_Runner_CIRCLECI_BUILD,
58+
expectedOutput: "CircleCI Build",
5559
}, {
5660
name: "unknown runner",
5761
testInput: -34,

app/controlplane/api/gen/frontend/workflowcontract/v1/crafting_schema.ts

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go

Lines changed: 53 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/workflowcontract/v1/crafting_schema.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ message CraftingSchema {
4545
GITLAB_PIPELINE = 2;
4646
AZURE_PIPELINE = 3;
4747
JENKINS_JOB = 4;
48+
CIRCLECI_BUILD = 5;
4849
}
4950
}
5051

internal/attestation/crafter/runner.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ type supportedRunner interface {
3939
func NewRunner(t schemaapi.CraftingSchema_Runner_RunnerType) supportedRunner {
4040
switch t {
4141
case schemaapi.CraftingSchema_Runner_GITHUB_ACTION:
42-
return &runners.GitHubAction{}
42+
return runners.NewGithubAction()
4343
case schemaapi.CraftingSchema_Runner_GITLAB_PIPELINE:
44-
return &runners.GitlabPipeline{}
44+
return runners.NewGitlabPipeline()
4545
case schemaapi.CraftingSchema_Runner_AZURE_PIPELINE:
46-
return &runners.AzurePipeline{}
46+
return runners.NewAzurePipeline()
4747
case schemaapi.CraftingSchema_Runner_JENKINS_JOB:
48-
return &runners.JenkinsJob{}
48+
return runners.NewJenkinsJob()
49+
case schemaapi.CraftingSchema_Runner_CIRCLECI_BUILD:
50+
return runners.NewCircleCIBuild()
4951
default:
50-
return &runners.Generic{}
52+
return runners.NewGeneric()
5153
}
5254
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// Copyright 2023 The Chainloop Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package runners
17+
18+
import "os"
19+
20+
type CircleCIBuild struct{}
21+
22+
const CircleCIBuildID = "circleci-build"
23+
24+
func NewCircleCIBuild() *CircleCIBuild {
25+
return &CircleCIBuild{}
26+
}
27+
28+
func (r *CircleCIBuild) CheckEnv() bool {
29+
for _, envVarName := range []string{"CI", "CIRCLECI"} {
30+
if os.Getenv(envVarName) != "true" {
31+
return false
32+
}
33+
}
34+
35+
return true
36+
}
37+
38+
func (r *CircleCIBuild) ListEnvVars() []string {
39+
return []string{
40+
// Some info about the job
41+
"CIRCLE_BUILD_URL",
42+
"CIRCLE_JOB",
43+
44+
// Some info about the commit
45+
"CIRCLE_BRANCH",
46+
"CIRCLE_PR_NUMBER",
47+
48+
// Some info about the agent
49+
"CIRCLE_NODE_TOTAL",
50+
"CIRCLE_NODE_INDEX",
51+
}
52+
}
53+
54+
func (r *CircleCIBuild) ResolveEnvVars() map[string]string {
55+
return resolveEnvVars(r.ListEnvVars())
56+
}
57+
58+
func (r *CircleCIBuild) String() string {
59+
return JenkinsJobID
60+
}
61+
62+
func (r *CircleCIBuild) RunURI() string {
63+
return os.Getenv("CIRCLE_BUILD_URL")
64+
}

0 commit comments

Comments
 (0)