mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-10-10 19:32:04 +00:00
fix: a composite action must not change the result of the calling step before it completes (#1019)
Resolves forgejo/runner#1014 --- Manual testing can also be done using the [reproducer from the issue](https://code.forgejo.org/forgejo/runner/issues/1014#issuecomment-60694). ## Before The first step of the local composite action sets the step result of the job to success which confuses Forgejo display.  ## After Forgejo displays the progress of the composite action in the step calling it.  <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1019): <!--number 1019 --><!--line 0 --><!--description Zml4OiBhIGNvbXBvc2l0ZSBhY3Rpb24gbXVzdCBub3QgY2hhbmdlIHRoZSByZXN1bHQgb2YgdGhlIGNhbGxpbmcgc3RlcCBiZWZvcmUgaXQgY29tcGxldGVz-->fix: a composite action must not change the result of the calling step before it completes<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1019 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
71bd44f9a0
commit
ed7dcb0081
3 changed files with 85 additions and 1 deletions
63
act/runner/logger_test.go
Normal file
63
act/runner/logger_test.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package runner
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.forgejo.org/forgejo/runner/v11/act/common"
|
||||
|
||||
"github.com/sirupsen/logrus/hooks/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRunner_GetOuterStepResult(t *testing.T) {
|
||||
nullLogger, hook := test.NewNullLogger()
|
||||
ctx := common.WithLogger(t.Context(), nullLogger)
|
||||
|
||||
t.Run("no stepResult", func(t *testing.T) {
|
||||
hook.Reset()
|
||||
common.Logger(ctx).Info("✅ Success")
|
||||
entry := hook.LastEntry()
|
||||
require.NotNil(t, entry)
|
||||
assert.Nil(t, GetOuterStepResult(entry))
|
||||
})
|
||||
|
||||
t.Run("stepResult and no stepID", func(t *testing.T) {
|
||||
hook.Reset()
|
||||
common.Logger(ctx).WithField("stepResult", "success").Info("✅ Success")
|
||||
entry := hook.LastEntry()
|
||||
require.NotNil(t, entry)
|
||||
assert.Nil(t, GetOuterStepResult(entry))
|
||||
})
|
||||
|
||||
stepNumber := 123
|
||||
stepID := "step id"
|
||||
stepName := "readable name"
|
||||
stageName := "Main"
|
||||
ctx = withStepLogger(ctx, stepNumber, stepID, stepName, stageName)
|
||||
|
||||
t.Run("stepResult and stepID", func(t *testing.T) {
|
||||
hook.Reset()
|
||||
common.Logger(ctx).WithField("stepResult", "success").Info("✅ Success")
|
||||
entry := hook.LastEntry()
|
||||
actualStepIDs, ok := entry.Data["stepID"]
|
||||
require.True(t, ok)
|
||||
require.Equal(t, []string{stepID}, actualStepIDs)
|
||||
require.NotNil(t, entry)
|
||||
assert.Equal(t, "success", GetOuterStepResult(entry))
|
||||
})
|
||||
|
||||
compositeStepID := "composite step id"
|
||||
ctx = WithCompositeStepLogger(ctx, compositeStepID)
|
||||
|
||||
t.Run("stepResult and composite stepID", func(t *testing.T) {
|
||||
hook.Reset()
|
||||
common.Logger(ctx).WithField("stepResult", "success").Info("✅ Success")
|
||||
entry := hook.LastEntry()
|
||||
actualStepIDs, ok := entry.Data["stepID"]
|
||||
require.True(t, ok)
|
||||
require.Equal(t, []string{stepID, compositeStepID}, actualStepIDs)
|
||||
require.NotNil(t, entry)
|
||||
assert.Nil(t, GetOuterStepResult(entry))
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue