fix: crash on invalid docker credentials (#1348)

* fix: crash on invalid docker credentials

* add test

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
ChristopherHX 2022-09-26 08:17:06 +02:00 committed by GitHub
parent 6037182487
commit 7d0407fa4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View file

@ -38,8 +38,6 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
return common.NewDebugExecutor("No steps found") return common.NewDebugExecutor("No steps found")
} }
preSteps = append(preSteps, info.startContainer())
for i, stepModel := range infoSteps { for i, stepModel := range infoSteps {
stepModel := stepModel stepModel := stepModel
if stepModel == nil { if stepModel == nil {
@ -104,7 +102,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
pipeline = append(pipeline, preSteps...) pipeline = append(pipeline, preSteps...)
pipeline = append(pipeline, steps...) pipeline = append(pipeline, steps...)
return common.NewPipelineExecutor(pipeline...). return common.NewPipelineExecutor(info.startContainer(), common.NewPipelineExecutor(pipeline...).
Finally(func(ctx context.Context) error { Finally(func(ctx context.Context) error {
var cancel context.CancelFunc var cancel context.CancelFunc
if ctx.Err() == context.Canceled { if ctx.Err() == context.Canceled {
@ -116,7 +114,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
return postExecutor(ctx) return postExecutor(ctx)
}). }).
Finally(info.interpolateOutputs()). Finally(info.interpolateOutputs()).
Finally(info.closeContainer()) Finally(info.closeContainer()))
} }
func useStepLogger(rc *RunContext, stepModel *model.Step, stage stepStage, executor common.Executor) common.Executor { func useStepLogger(rc *RunContext, stepModel *model.Step, stage stepStage, executor common.Executor) common.Executor {

View file

@ -156,6 +156,7 @@ func TestRunEvent(t *testing.T) {
{workdir, "checkout", "push", "", platforms}, {workdir, "checkout", "push", "", platforms},
{workdir, "job-container", "push", "", platforms}, {workdir, "job-container", "push", "", platforms},
{workdir, "job-container-non-root", "push", "", platforms}, {workdir, "job-container-non-root", "push", "", platforms},
{workdir, "job-container-invalid-credentials", "push", "failed to handle credentials: failed to interpolate container.credentials.password", platforms},
{workdir, "container-hostname", "push", "", platforms}, {workdir, "container-hostname", "push", "", platforms},
{workdir, "remote-action-docker", "push", "", platforms}, {workdir, "remote-action-docker", "push", "", platforms},
{workdir, "remote-action-js", "push", "", platforms}, {workdir, "remote-action-js", "push", "", platforms},

View file

@ -0,0 +1,13 @@
name: job-container-invalid-credentials
on: push
jobs:
fail-on-invalid-credentials:
runs-on: ubuntu-latest
container:
image: node:16-buster-slim
credentials:
username: "user"
password: "" # Empty password caused a crash in jobexecutor
steps:
- run: exit 0