Skip to content

Commit f3264ca

Browse files
Merge remote-tracking branch 'upstream/master' into bump-nektos
2 parents 4699c3b + e7e158c commit f3264ca

File tree

13 files changed

+5249
-44
lines changed

13 files changed

+5249
-44
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
version: v1.53
2828
only-new-issues: true
29-
- uses: megalinter/megalinter/flavors/go@v7.3.0
29+
- uses: megalinter/megalinter/flavors/go@v7.4.0
3030
env:
3131
DEFAULT_BRANCH: master
3232
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ To run `act` with secrets, you can enter them interactively, supply them as envi
340340
- `act --secret-file my.secrets` - load secrets values from `my.secrets` file.
341341
- secrets file format is the same as `.env` format
342342

343+
# Vars
344+
345+
To run `act` with repository variables that are acessible inside the workflow via ${{ vars.VARIABLE }}, you can enter them interactively or load them from a file. The following options are available for providing github repository variables:
346+
347+
- `act --var VARIABLE=somevalue` - use `somevalue` as the value for `VARIABLE`.
348+
- `act --var-file my.variables` - load variables values from `my.variables` file.
349+
- variables file format is the same as `.env` format
350+
343351
# Configuration
344352

345353
You can provide default configuration flags to `act` by either creating a `./.actrc` or a `~/.actrc` file. Any flags in the files will be applied before any flags provided directly on the command line. For example, a file like below will always use the `nektos/act-environments-ubuntu:18.04` image for the `ubuntu-latest` runner:

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.51
1+
0.2.52

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
658658
func defaultImageSurvey(actrc string) error {
659659
var answer string
660660
confirmation := &survey.Select{
661-
Message: "Please choose the default image you want to use with act:\n\n - Large size image: +20GB Docker image, includes almost all tools used on GitHub Actions (IMPORTANT: currently only ubuntu-18.04 platform is available)\n - Medium size image: ~500MB, includes only necessary tools to bootstrap actions and aims to be compatible with all actions\n - Micro size image: <200MB, contains only NodeJS required to bootstrap actions, doesn't work with all actions\n\nDefault image and other options can be changed manually in ~/.actrc (please refer to https://github.com/nektos/act#configuration for additional information about file structure)",
661+
Message: "Please choose the default image you want to use with act:\n - Large size image: ca. 17GB download + 53.1GB storage, you will need 75GB of free disk space, snapshots of GitHub Hosted Runners without snap and pulled docker images\n - Medium size image: ~500MB, includes only necessary tools to bootstrap actions and aims to be compatible with most actions\n - Micro size image: <200MB, contains only NodeJS required to bootstrap actions, doesn't work with all actions\n\nDefault image and other options can be changed manually in ~/.actrc (please refer to https://github.com/nektos/act#configuration for additional information about file structure)",
662662
Help: "If you want to know why act asks you that, please go to https://github.com/nektos/act/issues/107",
663663
Default: "Medium",
664664
Options: []string{"Large", "Medium", "Micro"},
@@ -672,7 +672,7 @@ func defaultImageSurvey(actrc string) error {
672672
var option string
673673
switch answer {
674674
case "Large":
675-
option = "-P ubuntu-latest=catthehacker/ubuntu:full-latest\n-P ubuntu-latest=catthehacker/ubuntu:full-20.04\n-P ubuntu-18.04=catthehacker/ubuntu:full-18.04\n"
675+
option = "-P ubuntu-latest=catthehacker/ubuntu:full-latest\n-P ubuntu-22.04=catthehacker/ubuntu:full-22.04\n-P ubuntu-20.04=catthehacker/ubuntu:full-20.04\n-P ubuntu-18.04=catthehacker/ubuntu:full-18.04\n"
676676
case "Medium":
677677
option = "-P ubuntu-latest=catthehacker/ubuntu:act-latest\n-P ubuntu-22.04=catthehacker/ubuntu:act-22.04\n-P ubuntu-20.04=catthehacker/ubuntu:act-20.04\n-P ubuntu-18.04=catthehacker/ubuntu:act-18.04\n"
678678
case "Micro":

go.mod

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/andreaskoch/go-fswatch v1.0.0
1010
github.com/creack/pty v1.1.18
1111
github.com/docker/cli v24.0.6+incompatible
12-
github.com/docker/distribution v2.8.2+incompatible
12+
github.com/docker/distribution v2.8.3+incompatible
1313
github.com/docker/docker v24.0.6+incompatible // 24.0 branch
1414
github.com/docker/go-connections v0.4.0
1515
github.com/go-git/go-billy/v5 v5.5.0
@@ -25,15 +25,15 @@ require (
2525
github.com/opencontainers/image-spec v1.1.0-rc5
2626
github.com/opencontainers/selinux v1.11.0
2727
github.com/pkg/errors v0.9.1
28-
github.com/rhysd/actionlint v1.6.25
28+
github.com/rhysd/actionlint v1.6.26
2929
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
3030
github.com/sirupsen/logrus v1.9.3
3131
github.com/spf13/cobra v1.7.0
3232
github.com/spf13/pflag v1.0.5
3333
github.com/stretchr/testify v1.8.4
3434
github.com/timshannon/bolthold v0.0.0-20210913165410-232392fc8a6a
3535
go.etcd.io/bbolt v1.3.7
36-
golang.org/x/term v0.12.0
36+
golang.org/x/term v0.13.0
3737
gopkg.in/yaml.v3 v3.0.1
3838
gotest.tools/v3 v3.5.1
3939
)
@@ -47,6 +47,7 @@ require (
4747
github.com/containerd/containerd v1.7.2 // indirect
4848
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
4949
github.com/davecgh/go-spew v1.1.1 // indirect
50+
github.com/distribution/reference v0.5.0 // indirect
5051
github.com/docker/docker-credential-helpers v0.7.0 // indirect
5152
github.com/docker/go-units v0.5.0 // indirect
5253
github.com/emirpasic/gods v1.18.1 // indirect
@@ -61,7 +62,7 @@ require (
6162
github.com/kevinburke/ssh_config v1.2.0 // indirect
6263
github.com/klauspost/compress v1.16.3 // indirect
6364
github.com/mattn/go-colorable v0.1.13 // indirect
64-
github.com/mattn/go-runewidth v0.0.14 // indirect
65+
github.com/mattn/go-runewidth v0.0.15 // indirect
6566
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
6667
github.com/mitchellh/mapstructure v1.1.2 // indirect
6768
github.com/moby/sys/sequential v0.5.0 // indirect
@@ -71,7 +72,7 @@ require (
7172
github.com/pjbgf/sha1cd v0.3.0 // indirect
7273
github.com/pmezard/go-difflib v1.0.0 // indirect
7374
github.com/rivo/uniseg v0.4.4 // indirect
74-
github.com/robfig/cron v1.2.0 // indirect
75+
github.com/robfig/cron/v3 v3.0.1 // indirect
7576
github.com/sergi/go-diff v1.2.0 // indirect
7677
github.com/skeema/knownhosts v1.2.0 // indirect
7778
github.com/stretchr/objx v0.5.0 // indirect
@@ -83,7 +84,7 @@ require (
8384
golang.org/x/mod v0.12.0 // indirect
8485
golang.org/x/net v0.15.0 // indirect
8586
golang.org/x/sync v0.3.0 // indirect
86-
golang.org/x/sys v0.12.0 // indirect
87+
golang.org/x/sys v0.13.0 // indirect
8788
golang.org/x/text v0.13.0 // indirect
8889
golang.org/x/tools v0.13.0 // indirect
8990
gopkg.in/warnings.v0 v0.1.2 // indirect

go.sum

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG
3737
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3838
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3939
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
40+
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
41+
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
4042
github.com/docker/cli v24.0.6+incompatible h1:fF+XCQCgJjjQNIMjzaSmiKJSCcfcXb3TWTcc7GAneOY=
4143
github.com/docker/cli v24.0.6+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
42-
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
43-
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
44+
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
45+
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
4446
github.com/docker/docker v24.0.6+incompatible h1:hceabKCtUgDqPu+qm0NgsaXf28Ljf4/pWFL7xjWWDgE=
4547
github.com/docker/docker v24.0.6+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
4648
github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A=
@@ -109,8 +111,8 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
109111
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
110112
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
111113
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
112-
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
113-
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
114+
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
115+
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
114116
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
115117
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
116118
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
@@ -140,13 +142,13 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
140142
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
141143
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
142144
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
143-
github.com/rhysd/actionlint v1.6.25 h1:0Is99a51w1iocdxKUzNYiBNwjoSlO2Klqzll98joVj4=
144-
github.com/rhysd/actionlint v1.6.25/go.mod h1:Q+MtZKm1MdmJ9woOSKxLscMW7kU44/PShvjNy5ZKHA8=
145+
github.com/rhysd/actionlint v1.6.26 h1:zi7jPZf3Ks14gCXYAAL47uBziyFlX7+Xwilqhexct9g=
146+
github.com/rhysd/actionlint v1.6.26/go.mod h1:TIj1DlCgtYLOv5CH9wCK+WJTOr1qAdnFzkGi0IgSCO4=
145147
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
146148
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
147149
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
148-
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
149-
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
150+
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
151+
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
150152
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
151153
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
152154
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
@@ -250,15 +252,15 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
250252
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
251253
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
252254
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
253-
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
254-
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
255+
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
256+
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
255257
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
256258
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
257259
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
258260
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
259261
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
260-
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
261-
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
262+
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
263+
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
262264
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
263265
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
264266
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

pkg/exprparser/interpreter.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ import (
1212
)
1313

1414
type EvaluationEnvironment struct {
15-
Github *model.GithubContext
16-
Env map[string]string
17-
Job *model.JobContext
18-
Jobs *map[string]*model.WorkflowCallResult
19-
Steps map[string]*model.StepResult
20-
Runner map[string]interface{}
21-
Secrets map[string]string
22-
Vars map[string]string
23-
Strategy map[string]interface{}
24-
Matrix map[string]interface{}
25-
Needs map[string]Needs
26-
Inputs map[string]interface{}
15+
Github *model.GithubContext
16+
Env map[string]string
17+
Job *model.JobContext
18+
Jobs *map[string]*model.WorkflowCallResult
19+
Steps map[string]*model.StepResult
20+
Runner map[string]interface{}
21+
Secrets map[string]string
22+
Vars map[string]string
23+
Strategy map[string]interface{}
24+
Matrix map[string]interface{}
25+
Needs map[string]Needs
26+
Inputs map[string]interface{}
27+
HashFiles func([]reflect.Value) (interface{}, error)
2728
}
2829

2930
type Needs struct {
@@ -609,6 +610,9 @@ func (impl *interperterImpl) evaluateFuncCall(funcCallNode *actionlint.FuncCallN
609610
case "fromjson":
610611
return impl.fromJSON(args[0])
611612
case "hashfiles":
613+
if impl.env.HashFiles != nil {
614+
return impl.env.HashFiles(args)
615+
}
612616
return impl.hashFiles(args...)
613617
case "always":
614618
return impl.always()

pkg/runner/action_composite.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ func evaluateCompositeInputAndEnv(ctx context.Context, parent *RunContext, step
3737
env[envKey] = ee.Interpolate(ctx, input.Default)
3838
}
3939
}
40+
gh := step.getGithubContext(ctx)
41+
env["GITHUB_ACTION_REPOSITORY"] = gh.ActionRepository
42+
env["GITHUB_ACTION_REF"] = gh.ActionRef
4043

4144
return env
4245
}
@@ -53,11 +56,11 @@ func newCompositeRunContext(ctx context.Context, parent *RunContext, step action
5356
Name: parent.Name,
5457
JobName: parent.JobName,
5558
Run: &model.Run{
56-
JobID: "composite-job",
59+
JobID: parent.Run.JobID,
5760
Workflow: &model.Workflow{
5861
Name: parent.Run.Workflow.Name,
5962
Jobs: map[string]*model.Job{
60-
"composite-job": {},
63+
parent.Run.JobID: {},
6164
},
6265
},
6366
},

pkg/runner/expression.go

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package runner
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
7+
"path"
8+
"reflect"
69
"regexp"
710
"strings"
11+
"time"
12+
13+
_ "embed"
814

915
"github.com/nektos/act/pkg/common"
16+
"github.com/nektos/act/pkg/container"
1017
"github.com/nektos/act/pkg/exprparser"
1118
"github.com/nektos/act/pkg/model"
1219
"gopkg.in/yaml.v3"
@@ -75,13 +82,14 @@ func (rc *RunContext) NewExpressionEvaluatorWithEnv(ctx context.Context, env map
7582
Jobs: &workflowCallResult,
7683
// todo: should be unavailable
7784
// but required to interpolate/evaluate the step outputs on the job
78-
Steps: rc.getStepsContext(),
79-
Secrets: getWorkflowSecrets(ctx, rc),
80-
Vars: getWorkflowVars(ctx, rc),
81-
Strategy: strategy,
82-
Matrix: rc.Matrix,
83-
Needs: using,
84-
Inputs: inputs,
85+
Steps: rc.getStepsContext(),
86+
Secrets: getWorkflowSecrets(ctx, rc),
87+
Vars: getWorkflowVars(ctx, rc),
88+
Strategy: strategy,
89+
Matrix: rc.Matrix,
90+
Needs: using,
91+
Inputs: inputs,
92+
HashFiles: getHashFilesFunction(ctx, rc),
8593
}
8694
if rc.JobContainer != nil {
8795
ee.Runner = rc.JobContainer.GetRunnerContext(ctx)
@@ -95,6 +103,9 @@ func (rc *RunContext) NewExpressionEvaluatorWithEnv(ctx context.Context, env map
95103
}
96104
}
97105

106+
//go:embed hashfiles/index.js
107+
var hashfiles string
108+
98109
// NewExpressionEvaluator creates a new evaluator
99110
func (rc *RunContext) NewStepExpressionEvaluator(ctx context.Context, step step) ExpressionEvaluator {
100111
// todo: cleanup EvaluationEnvironment creation
@@ -131,7 +142,8 @@ func (rc *RunContext) NewStepExpressionEvaluator(ctx context.Context, step step)
131142
Needs: using,
132143
// todo: should be unavailable
133144
// but required to interpolate/evaluate the inputs in actions/composite
134-
Inputs: inputs,
145+
Inputs: inputs,
146+
HashFiles: getHashFilesFunction(ctx, rc),
135147
}
136148
if rc.JobContainer != nil {
137149
ee.Runner = rc.JobContainer.GetRunnerContext(ctx)
@@ -145,6 +157,67 @@ func (rc *RunContext) NewStepExpressionEvaluator(ctx context.Context, step step)
145157
}
146158
}
147159

160+
func getHashFilesFunction(ctx context.Context, rc *RunContext) func(v []reflect.Value) (interface{}, error) {
161+
hashFiles := func(v []reflect.Value) (interface{}, error) {
162+
if rc.JobContainer != nil {
163+
timeed, cancel := context.WithTimeout(ctx, time.Minute)
164+
defer cancel()
165+
name := "workflow/hashfiles/index.js"
166+
hout := &bytes.Buffer{}
167+
herr := &bytes.Buffer{}
168+
patterns := []string{}
169+
followSymlink := false
170+
171+
for i, p := range v {
172+
s := p.String()
173+
if i == 0 {
174+
if strings.HasPrefix(s, "--") {
175+
if strings.EqualFold(s, "--follow-symbolic-links") {
176+
followSymlink = true
177+
continue
178+
}
179+
return "", fmt.Errorf("Invalid glob option %s, available option: '--follow-symbolic-links'", s)
180+
}
181+
}
182+
patterns = append(patterns, s)
183+
}
184+
env := map[string]string{}
185+
for k, v := range rc.Env {
186+
env[k] = v
187+
}
188+
env["patterns"] = strings.Join(patterns, "\n")
189+
if followSymlink {
190+
env["followSymbolicLinks"] = "true"
191+
}
192+
193+
stdout, stderr := rc.JobContainer.ReplaceLogWriter(hout, herr)
194+
_ = rc.JobContainer.Copy(rc.JobContainer.GetActPath(), &container.FileEntry{
195+
Name: name,
196+
Mode: 0o644,
197+
Body: hashfiles,
198+
}).
199+
Then(rc.execJobContainer([]string{"node", path.Join(rc.JobContainer.GetActPath(), name)},
200+
env, "", "")).
201+
Finally(func(context.Context) error {
202+
rc.JobContainer.ReplaceLogWriter(stdout, stderr)
203+
return nil
204+
})(timeed)
205+
output := hout.String() + "\n" + herr.String()
206+
guard := "__OUTPUT__"
207+
outstart := strings.Index(output, guard)
208+
if outstart != -1 {
209+
outstart += len(guard)
210+
outend := strings.Index(output[outstart:], guard)
211+
if outend != -1 {
212+
return output[outstart : outstart+outend], nil
213+
}
214+
}
215+
}
216+
return "", nil
217+
}
218+
return hashFiles
219+
}
220+
148221
type expressionEvaluator struct {
149222
interpreter exprparser.Interpreter
150223
}

0 commit comments

Comments
 (0)