Skip to content

Commit ff8b1df

Browse files
authored
Don't interpolate joboutputs, before job is done (#894)
* Don't interpolate joboutputs, before job is donei All credits go to @ChristopherHX which fixed this issue. I only created a PR for this so it will be fixed in the upstream binary. This fixes #758 * Added output test * Fix typo
1 parent 96cf907 commit ff8b1df

File tree

4 files changed

+60
-15
lines changed

4 files changed

+60
-15
lines changed

pkg/runner/run_context.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@ func (rc *RunContext) ActionCacheDir() string {
210210
return filepath.Join(xdgCache, "act")
211211
}
212212

213+
// Interpolate outputs after a job is done
214+
func (rc *RunContext) interpolateOutputs() common.Executor {
215+
return func(ctx context.Context) error {
216+
ee := rc.NewExpressionEvaluator()
217+
for k, v := range rc.Run.Job().Outputs {
218+
interpolated := ee.Interpolate(v)
219+
if v != interpolated {
220+
rc.Run.Job().Outputs[k] = interpolated
221+
}
222+
}
223+
return nil
224+
}
225+
}
226+
213227
// Executor returns a pipeline executor for all the steps in the job
214228
func (rc *RunContext) Executor() common.Executor {
215229
steps := make([]common.Executor, 0)
@@ -231,7 +245,7 @@ func (rc *RunContext) Executor() common.Executor {
231245
}
232246
steps = append(steps, rc.stopJobContainer())
233247

234-
return common.NewPipelineExecutor(steps...).Finally(func(ctx context.Context) error {
248+
return common.NewPipelineExecutor(steps...).Finally(rc.interpolateOutputs()).Finally(func(ctx context.Context) error {
235249
if rc.JobContainer != nil {
236250
return rc.JobContainer.Close()(ctx)
237251
}
@@ -275,7 +289,7 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
275289
rc.ExprEval = exprEval
276290

277291
common.Logger(ctx).Infof("\u2B50 Run %s", sc.Step)
278-
err = sc.Executor().Then(sc.interpolateOutputs())(ctx)
292+
err = sc.Executor()(ctx)
279293
if err == nil {
280294
common.Logger(ctx).Infof(" \u2705 Success - %s", sc.Step)
281295
} else {

pkg/runner/runner_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func TestRunEvent(t *testing.T) {
120120
{"testdata", "issue-597", "push", "", platforms, ""},
121121
{"testdata", "issue-598", "push", "", platforms, ""},
122122
{"testdata", "env-and-path", "push", "", platforms, ""},
123+
{"testdata", "outputs", "push", "", platforms, ""},
123124
{"../model/testdata", "strategy", "push", "", platforms, ""}, // TODO: move all testdata into pkg so we can validate it with planner and runner
124125
// {"testdata", "issue-228", "push", "", platforms, ""}, // TODO [igni]: Remove this once everything passes
125126

pkg/runner/step_context.go

-13
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ func (sc *StepContext) execJobContainer() common.Executor {
3939
}
4040
}
4141

42-
func (sc *StepContext) interpolateOutputs() common.Executor {
43-
return func(ctx context.Context) error {
44-
ee := sc.NewExpressionEvaluator()
45-
for k, v := range sc.RunContext.Run.Job().Outputs {
46-
interpolated := ee.Interpolate(v)
47-
if v != interpolated {
48-
sc.RunContext.Run.Job().Outputs[k] = interpolated
49-
}
50-
}
51-
return nil
52-
}
53-
}
54-
5542
type formatError string
5643

5744
func (e formatError) Error() string {

pkg/runner/testdata/outputs/push.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: output
2+
on: push
3+
4+
jobs:
5+
build_output:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- id: set_1
9+
run: |
10+
echo "::set-output name=var_1::$(echo var1)"
11+
echo "::set-output name=var_2::$(echo var2)"
12+
- id: set_2
13+
run: |
14+
echo "::set-output name=var_3::$(echo var3)"
15+
- id: set_3
16+
run: |
17+
echo "::set-output name=var_4::$(echo var4)"
18+
outputs:
19+
variable_1: ${{ steps.set_1.outputs.var_1 }}
20+
variable_2: ${{ steps.set_1.outputs.var_2 }}
21+
variable_3: ${{ steps.set_2.outputs.var_3 }}
22+
variable_4: ${{ steps.set_3.outputs.var_4 }}
23+
24+
build:
25+
needs: build_output
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Check set_1 var1
29+
run: |
30+
echo "${{ needs.build_output.outputs.variable_1 }}"
31+
echo "${{ needs.build_output.outputs.variable_1 }}" | grep 'var1' || exit 1
32+
- name: Check set_1 var2
33+
run: |
34+
echo "${{ needs.build_output.outputs.variable_2 }}"
35+
echo "${{ needs.build_output.outputs.variable_2 }}" | grep 'var2' || exit 1
36+
- name: Check set_2 var3
37+
run: |
38+
echo "${{ needs.build_output.outputs.variable_3 }}"
39+
echo "${{ needs.build_output.outputs.variable_3 }}" | grep 'var3' || exit 1
40+
- name: Check set_3 var4
41+
run: |
42+
echo "${{ needs.build_output.outputs.variable_4 }}"
43+
echo "${{ needs.build_output.outputs.variable_4 }}" | grep 'var4' || exit 1

0 commit comments

Comments
 (0)