diff options
-rw-r--r-- | .forgejo/workflows/test.yml | 25 | ||||
-rw-r--r-- | pkg/runner/action.go | 6 | ||||
-rw-r--r-- | pkg/runner/run_context.go | 2 | ||||
-rw-r--r-- | pkg/runner/runner_test.go | 38 | ||||
-rw-r--r-- | pkg/runner/step.go | 2 | ||||
-rw-r--r-- | pkg/runner/testdata/skip/skip.yml | 9 |
6 files changed, 73 insertions, 9 deletions
diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml index a985814..5498dac 100644 --- a/.forgejo/workflows/test.yml +++ b/.forgejo/workflows/test.yml @@ -11,8 +11,7 @@ env: GOCACHE: /go_cache jobs: - lint: - name: check and test + unit: runs-on: docker container: image: 'code.forgejo.org/oci/node:20-bookworm' @@ -48,6 +47,24 @@ jobs: run: go build -v ./... - name: build without docker run: go build -tags WITHOUT_DOCKER -v ./... - - name: test + - name: unit test run: go test -v ./pkg/jobparser ./pkg/model ./pkg/exprparser - # TODO test more packages + + integration: + runs-on: lxc-bookworm + needs: [unit] + steps: + - uses: https://code.forgejo.org/actions/checkout@v4 + + - uses: https://code.forgejo.org/actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: apt install docker.io + run: | + export DEBIAN_FRONTEND=noninteractive + apt-get update -qq + apt-get -q install -qq -y docker.io + + - name: integration test + run: go test -run=TestRunSkipped -v ./pkg/runner diff --git a/pkg/runner/action.go b/pkg/runner/action.go index 416e5e4..fd52c0b 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -619,17 +619,17 @@ func shouldRunPostStep(step actionStep) common.Conditional { stepResult := stepResults[step.getStepModel().ID] if stepResult == nil { - log.WithField("stepResult", model.StepStatusSkipped).Debugf("skipping post step for '%s'; step was not executed", step.getStepModel()) + log.WithField("stepResult", model.StepStatusSkipped).Infof("skipping post step for '%s'; step was not executed", step.getStepModel()) return false } if stepResult.Conclusion == model.StepStatusSkipped { - log.WithField("stepResult", model.StepStatusSkipped).Debugf("skipping post step for '%s'; main step was skipped", step.getStepModel()) + log.WithField("stepResult", model.StepStatusSkipped).Infof("skipping post step for '%s'; main step was skipped", step.getStepModel()) return false } if step.getActionModel() == nil { - log.WithField("stepResult", model.StepStatusSkipped).Debugf("skipping post step for '%s': no action model available", step.getStepModel()) + log.WithField("stepResult", model.StepStatusSkipped).Infof("skipping post step for '%s': no action model available", step.getStepModel()) return false } diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 8ecdb2b..6aaf2d8 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -911,7 +911,7 @@ func (rc *RunContext) isEnabled(ctx context.Context) (bool, error) { } if !runJob { - l.WithField("jobResult", "skipped").Debugf("Skipping job '%s' due to '%s'", job.Name, job.If.Value) + l.WithField("jobResult", "skipped").Infof("Skipping job '%s' due to '%s'", job.Name, job.If.Value) return false, nil } diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 70e9634..ecb5ce5 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -187,6 +187,7 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config GitHubInstance: "github.com", ContainerArchitecture: cfg.ContainerArchitecture, Matrix: cfg.Matrix, + JobLoggerLevel: cfg.JobLoggerLevel, } runner, err := New(runnerConfig) @@ -490,6 +491,43 @@ func TestRunDifferentArchitecture(t *testing.T) { tjfi.runTest(context.Background(), t, &Config{ContainerArchitecture: "linux/arm64"}) } +type runSkippedHook struct { + found bool +} + +func (h *runSkippedHook) Levels() []log.Level { + return []log.Level{log.InfoLevel} +} + +func (h *runSkippedHook) Fire(entry *log.Entry) error { + if v, ok := entry.Data["stepResult"]; ok { + h.found = (v == model.StepStatusSkipped) + } + return nil +} + +func TestRunSkipped(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + + tjfi := TestJobFileInfo{ + workdir: workdir, + workflowPath: "skip", + eventName: "push", + errorMessage: "", + platforms: platforms, + } + + h := &runSkippedHook{} + ctx := common.WithLoggerHook(context.Background(), h) + + jobLoggerLevel := log.InfoLevel + tjfi.runTest(ctx, t, &Config{ContainerArchitecture: "linux/arm64", JobLoggerLevel: &jobLoggerLevel}) + + assert.True(t, h.found) +} + type maskJobLoggerFactory struct { Output bytes.Buffer } diff --git a/pkg/runner/step.go b/pkg/runner/step.go index c67b5b0..ec3cfe2 100644 --- a/pkg/runner/step.go +++ b/pkg/runner/step.go @@ -94,7 +94,7 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo if !runStep { stepResult.Conclusion = model.StepStatusSkipped stepResult.Outcome = model.StepStatusSkipped - logger.WithField("stepResult", stepResult.Outcome).Debugf("Skipping step '%s' due to '%s'", stepModel, ifExpression) + logger.WithField("stepResult", stepResult.Outcome).Infof("Skipping step '%s' due to '%s'", stepModel, ifExpression) return nil } diff --git a/pkg/runner/testdata/skip/skip.yml b/pkg/runner/testdata/skip/skip.yml new file mode 100644 index 0000000..7f6d303 --- /dev/null +++ b/pkg/runner/testdata/skip/skip.yml @@ -0,0 +1,9 @@ +name: skip +on: push + +jobs: + check: + runs-on: ubuntu-latest + steps: + - if: false + run: echo nothing |