-
Notifications
You must be signed in to change notification settings - Fork 116
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
runservice: add AGOLA_RUN_COUNTER variable #473
Conversation
tests/setup_test.go
Outdated
{ type: 'run', name:'check AGOLA_RUN_COUNTER variable exists', command: ' | ||
if [ "$AGOLA_RUN_COUNTER" != "%d" ]; then | ||
exit 1 | ||
fi |
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.
Don't do the check inside the run but in the test code. Se TestConfigContext
tests/setup_test.go
Outdated
@@ -7008,3 +7008,88 @@ func TestProjectCommitStatusRedelivery(t *testing.T) { | |||
} | |||
}) | |||
} | |||
|
|||
func TestAgolaRunCounterVariableIsDefined(t *testing.T) { |
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.
This test should be generalized to check all the required environment variables and the name should be something like TestRunRequiredEnvVariables
.
1d9615b
to
c77085f
Compare
c77085f
to
1ffae48
Compare
1ffae48
to
2af43dd
Compare
@@ -127,6 +128,9 @@ func GenExecutorTaskSpecData(r *types.Run, rt *types.RunTask, rc *types.RunConfi | |||
// run config Environment variables ovverride every other environment variable | |||
mergeEnv(environment, rc.Environment) | |||
|
|||
// AGOLA_RUN_COUNTER is generated at runtime since Counter doesn't exist before creating the run |
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.
This isn't really true, counter is created before creating the run.
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.
I mean it is not defined before call the api (it is not defined in RunCreateRequest run api types).
The counter is created in the same transaction before creating the run, but I thought it is not a good place to add variables to the run environment.
The comment could be for example AGOLA_RUN_COUNTER is generated at runtime since Counter is not defined before the save run transaction
?
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.
I think it should just be
The AGOLA_RUN_COUNTER environment variable is not saved in the runconfig StaticEnvironment map but populated here using the run counter.
tests/setup_test.go
Outdated
testutil.NilError(t, err) | ||
|
||
// update commit sha from annotations since it will change at every test | ||
tt.env["AGOLA_GIT_COMMITSHA"] = run.Annotations["commit_sha"] |
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.
move it at the start of the test.
tests/setup_test.go
Outdated
{ | ||
name: "test push with run count 1", | ||
config: fmt.Sprintf(config, 1), | ||
runNumber: 1, | ||
env: map[string]string{ | ||
"AGOLA_RUN_COUNTER": "1", | ||
"AGOLA_GIT_REF_TYPE": "branch", | ||
"AGOLA_GIT_REF": "refs/heads/master", | ||
"AGOLA_GIT_BRANCH": "master", | ||
"AGOLA_GIT_TAG": "", | ||
"AGOLA_GIT_COMMITSHA": "", | ||
}, | ||
}, | ||
{ | ||
name: "test push with run count 2", | ||
config: fmt.Sprintf(config, 2), | ||
runNumber: 2, | ||
env: map[string]string{ | ||
"AGOLA_RUN_COUNTER": "2", | ||
"AGOLA_GIT_REF_TYPE": "branch", | ||
"AGOLA_GIT_REF": "refs/heads/master", | ||
"AGOLA_GIT_BRANCH": "master", | ||
"AGOLA_GIT_TAG": "", | ||
"AGOLA_GIT_COMMITSHA": "", | ||
}, | ||
}, | ||
{ | ||
name: "test push with run count 3", | ||
config: fmt.Sprintf(config, 3), | ||
runNumber: 3, | ||
env: map[string]string{ | ||
"AGOLA_RUN_COUNTER": "3", | ||
"AGOLA_GIT_REF_TYPE": "branch", | ||
"AGOLA_GIT_REF": "refs/heads/master", | ||
"AGOLA_GIT_BRANCH": "master", | ||
"AGOLA_GIT_TAG": "", | ||
"AGOLA_GIT_COMMITSHA": "", | ||
}, | ||
}, | ||
{ | ||
name: "test push with run count 4", | ||
config: fmt.Sprintf(config, 4), | ||
runNumber: 4, | ||
env: map[string]string{ | ||
"AGOLA_RUN_COUNTER": "4", | ||
"AGOLA_GIT_REF_TYPE": "branch", | ||
"AGOLA_GIT_REF": "refs/heads/master", | ||
"AGOLA_GIT_BRANCH": "master", | ||
"AGOLA_GIT_TAG": "", | ||
"AGOLA_GIT_COMMITSHA": "", | ||
}, | ||
}, | ||
{ | ||
name: "test push with run count 5", | ||
config: fmt.Sprintf(config, 5), | ||
runNumber: 5, | ||
env: map[string]string{ | ||
"AGOLA_RUN_COUNTER": "5", | ||
"AGOLA_GIT_REF_TYPE": "branch", | ||
"AGOLA_GIT_REF": "refs/heads/master", | ||
"AGOLA_GIT_BRANCH": "master", | ||
"AGOLA_GIT_TAG": "", | ||
"AGOLA_GIT_COMMITSHA": "", | ||
}, | ||
}, |
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.
Why 5 identical tests?
tests/setup_test.go
Outdated
"AGOLA_GIT_REF": "refs/heads/master", | ||
"AGOLA_GIT_BRANCH": "master", | ||
"AGOLA_GIT_TAG": "", | ||
"AGOLA_GIT_COMMITSHA": "", |
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.
From this looks like AGOLA_GIT_COMMITSHA should be empty. No need to define it here if you're going to populate it later from annotations.
2af43dd
to
d4f2907
Compare
@@ -127,6 +128,9 @@ func GenExecutorTaskSpecData(r *types.Run, rt *types.RunTask, rc *types.RunConfi | |||
// run config Environment variables ovverride every other environment variable | |||
mergeEnv(environment, rc.Environment) | |||
|
|||
// The AGOLA_RUN_COUNTER environment variable is not saved in the runconfig StaticEnvironment map but it populated here using the run counter |
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.
I updated the comment (remove spurious 'it')
tests/setup_test.go
Outdated
for _, tt := range tests { | ||
push(t, tt.config, giteaRepo.CloneURL, giteaToken, "commit", false) | ||
} |
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.
It doesn't makes sense to push for every test. All of this should be put inside the tests loop (that could be parallelized).
d4f2907
to
7c3646b
Compare
], | ||
}, | ||
steps: [ | ||
{ type: 'run', command: 'env -u AGOLA_SSHPRIVKEY' }, |
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.
is -u ...
really needed?
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.
yes because AGOLA_SSHPRIVKEY can contains value with equal characters and the ParseEnv split will fail
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.
I'm not sure about which is the issue but there're already other tests that use don't have such issue. Anyway it should be fixed in ParseEnvs
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.
I are investigating well, in the other tests we get the log of directruns and I see they have AGOLA_SSHPRIVKEY variable with empty value, so they work.
In my test the AGOLA_SSHPRIVKEY is a multiline variable, so I think the best way is to skip this variable with -u
tests/setup_test.go
Outdated
"AGOLA_GIT_REF": "refs/heads/master", | ||
"AGOLA_GIT_BRANCH": "master", | ||
"AGOLA_GIT_TAG": "", | ||
"AGOLA_GIT_COMMITSHA": "", |
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.
remove this.
tests/setup_test.go
Outdated
{ | ||
name: "test push with run count 1", | ||
env: map[string]string{ | ||
"AGOLA_RUN_COUNTER": "", |
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.
remove this
5a2aed6
to
c4ae143
Compare
add AGOLA_RUN_COUNTER variable by default with run counter value to the run environment
c4ae143
to
fe0612d
Compare
add AGOLA_RUN_COUNTER variable by default with run counter value to the run environment
fix #362