Skip to content

Commit e520382

Browse files
feat: GITHUB_STATE and GITHUB_OUTPUT file commands (#1391)
* feat: set-state and set-output file commands * increase test timeout from 10m to 15m * Prepare for HostExecutor PR Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent f2b98ed commit e520382

File tree

6 files changed

+113
-3
lines changed

6 files changed

+113
-3
lines changed

.github/workflows/checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
5151
restore-keys: |
5252
${{ runner.os }}-go-
53-
- run: go test -v -cover -coverprofile=coverage.txt -covermode=atomic ./...
53+
- run: go test -v -cover -coverprofile=coverage.txt -covermode=atomic -timeout 15m ./...
5454
- name: Upload Codecov report
5555
uses: codecov/[email protected]
5656
with:

pkg/runner/step.go

+37
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package runner
33
import (
44
"context"
55
"fmt"
6+
"path"
67
"strings"
78

89
"github.com/nektos/act/pkg/common"
10+
"github.com/nektos/act/pkg/container"
911
"github.com/nektos/act/pkg/exprparser"
1012
"github.com/nektos/act/pkg/model"
1113
)
@@ -94,6 +96,20 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo
9496
}
9597
logger.Infof("\u2B50 Run %s %s", stage, stepString)
9698

99+
// Prepare and clean Runner File Commands
100+
actPath := rc.JobContainer.GetActPath()
101+
outputFileCommand := path.Join("workflow", "outputcmd.txt")
102+
stateFileCommand := path.Join("workflow", "statecmd.txt")
103+
(*step.getEnv())["GITHUB_OUTPUT"] = path.Join(actPath, outputFileCommand)
104+
(*step.getEnv())["GITHUB_STATE"] = path.Join(actPath, stateFileCommand)
105+
_ = rc.JobContainer.Copy(actPath, &container.FileEntry{
106+
Name: outputFileCommand,
107+
Mode: 0666,
108+
}, &container.FileEntry{
109+
Name: stateFileCommand,
110+
Mode: 0666,
111+
})(ctx)
112+
97113
err = executor(ctx)
98114

99115
if err == nil {
@@ -117,6 +133,27 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo
117133

118134
logger.WithField("stepResult", rc.StepResults[rc.CurrentStep].Outcome).Errorf(" \u274C Failure - %s %s", stage, stepString)
119135
}
136+
// Process Runner File Commands
137+
orgerr := err
138+
state := map[string]string{}
139+
err = rc.JobContainer.UpdateFromEnv(path.Join(actPath, stateFileCommand), &state)(ctx)
140+
if err != nil {
141+
return err
142+
}
143+
for k, v := range state {
144+
rc.saveState(ctx, map[string]string{"name": k}, v)
145+
}
146+
output := map[string]string{}
147+
err = rc.JobContainer.UpdateFromEnv(path.Join(actPath, outputFileCommand), &output)(ctx)
148+
if err != nil {
149+
return err
150+
}
151+
for k, v := range output {
152+
rc.setOutput(ctx, map[string]string{"name": k}, v)
153+
}
154+
if orgerr != nil {
155+
return orgerr
156+
}
120157
return err
121158
}
122159
}

pkg/runner/step_action_local_test.go

+27-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package runner
22

33
import (
44
"context"
5+
"path/filepath"
56
"strings"
67
"testing"
78

@@ -63,7 +64,7 @@ func TestStepActionLocalTest(t *testing.T) {
6364
},
6465
}
6566

66-
salm.On("readAction", sal.Step, "/tmp/path/to/action", "", mock.Anything, mock.Anything).
67+
salm.On("readAction", sal.Step, filepath.Clean("/tmp/path/to/action"), "", mock.Anything, mock.Anything).
6768
Return(&model.Action{}, nil)
6869

6970
cm.On("UpdateFromImageEnv", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
@@ -78,7 +79,19 @@ func TestStepActionLocalTest(t *testing.T) {
7879
return nil
7980
})
8081

81-
salm.On("runAction", sal, "/tmp/path/to/action", (*remoteAction)(nil)).Return(func(ctx context.Context) error {
82+
cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(func(ctx context.Context) error {
83+
return nil
84+
})
85+
86+
cm.On("UpdateFromEnv", "/var/run/act/workflow/statecmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
87+
return nil
88+
})
89+
90+
cm.On("UpdateFromEnv", "/var/run/act/workflow/outputcmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
91+
return nil
92+
})
93+
94+
salm.On("runAction", sal, filepath.Clean("/tmp/path/to/action"), (*remoteAction)(nil)).Return(func(ctx context.Context) error {
8295
return nil
8396
})
8497

@@ -275,6 +288,18 @@ func TestStepActionLocalPost(t *testing.T) {
275288
})
276289
}
277290
cm.On("Exec", suffixMatcher("pkg/runner/local/action/post.js"), sal.env, "", "").Return(func(ctx context.Context) error { return tt.err })
291+
292+
cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(func(ctx context.Context) error {
293+
return nil
294+
})
295+
296+
cm.On("UpdateFromEnv", "/var/run/act/workflow/statecmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
297+
return nil
298+
})
299+
300+
cm.On("UpdateFromEnv", "/var/run/act/workflow/outputcmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
301+
return nil
302+
})
278303
}
279304

280305
err := sal.post()(ctx)

pkg/runner/step_action_remote_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@ func TestStepActionRemote(t *testing.T) {
172172
}
173173
if tt.mocks.run {
174174
sarm.On("runAction", sar, suffixMatcher("act/remote-action@v1"), newRemoteAction(sar.Step.Uses)).Return(func(ctx context.Context) error { return tt.runError })
175+
176+
cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(func(ctx context.Context) error {
177+
return nil
178+
})
179+
180+
cm.On("UpdateFromEnv", "/var/run/act/workflow/statecmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
181+
return nil
182+
})
183+
184+
cm.On("UpdateFromEnv", "/var/run/act/workflow/outputcmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
185+
return nil
186+
})
175187
}
176188

177189
err := sar.pre()(ctx)
@@ -582,6 +594,18 @@ func TestStepActionRemotePost(t *testing.T) {
582594
}
583595
if tt.mocks.exec {
584596
cm.On("Exec", []string{"node", "/var/run/act/actions/remote-action@v1/post.js"}, sar.env, "", "").Return(func(ctx context.Context) error { return tt.err })
597+
598+
cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(func(ctx context.Context) error {
599+
return nil
600+
})
601+
602+
cm.On("UpdateFromEnv", "/var/run/act/workflow/statecmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
603+
return nil
604+
})
605+
606+
cm.On("UpdateFromEnv", "/var/run/act/workflow/outputcmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
607+
return nil
608+
})
585609
}
586610

587611
err := sar.post()(ctx)

pkg/runner/step_docker_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ func TestStepDockerMain(t *testing.T) {
8686
return nil
8787
})
8888

89+
cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(func(ctx context.Context) error {
90+
return nil
91+
})
92+
93+
cm.On("UpdateFromEnv", "/var/run/act/workflow/statecmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
94+
return nil
95+
})
96+
97+
cm.On("UpdateFromEnv", "/var/run/act/workflow/outputcmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
98+
return nil
99+
})
100+
89101
err := sd.main()(ctx)
90102
assert.Nil(t, err)
91103

pkg/runner/step_run_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ func TestStepRun(t *testing.T) {
6565
return nil
6666
})
6767

68+
cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(func(ctx context.Context) error {
69+
return nil
70+
})
71+
72+
cm.On("UpdateFromEnv", "/var/run/act/workflow/statecmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
73+
return nil
74+
})
75+
76+
cm.On("UpdateFromEnv", "/var/run/act/workflow/outputcmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
77+
return nil
78+
})
79+
6880
ctx := context.Background()
6981

7082
err := sr.main()(ctx)

0 commit comments

Comments
 (0)