* feat: allow to spawn and run a local reusable workflow
This change contains the ability to parse/plan/run a local
reusable workflow.
There are still numerous things missing:
- inputs
- secrets
- outputs
* feat: add workflow_call inputs
* test: improve inputs test
* feat: add input defaults
* feat: allow expressions in inputs
* feat: use context specific expression evaluator
* refactor: prepare for better re-usability
* feat: add secrets for reusable workflows
* test: use secrets during test run
* feat: handle reusable workflow outputs
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* fix: step env is unavailable in with property expr
* don't run the test on windows
* fix: composite action add missing shell
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* refactor: share UpdateFromEnv logic
* Add test for GITHUB_OUTPUT
Co-authored-by: Ben Randall <veleek@gmail.com>
* Add GITHUB_STATE test
* Add test for the old broken parser
Co-authored-by: Ben Randall <veleek@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* refactor: move autoremove into the jobexecutor
breaking: docker container are removed after job exit
* reduce complexity
* remove linter exception
* reduce cyclic complexity
* fix: always allow 1 min for stopping and removing the runner, even if we were cancelled
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* feat: interpolate the step names
Step names could contain expressions refering to event data.
Fixes#1353
* test: add missing mock data
* fix: setup composite expression evaluator
The RunContext does contain a cached ExpressionEvaluator.
This should be the case the composite RunContext as well.
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Casey Lee <cplee@nektos.com>
* 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>
* fix: keep path to event json file in composite actions
The event.json paths need to be copied over, since it the
GithubContext is recreated from the composite RC. And that
does read some value for the event file if available.
* test: add test case
* test: paste the test correctly and revert a line
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This change does parse the different types of workflow jobs.
It is not much by itself but the start to implement reusable
workflows.
Relates to #826
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.
[1]: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* test: check workflow_dispatch inputs
This implements a test to check for `workflow_dispatch` inputs.
This will be a prerequisite for implementing the inputs.
* feat: map workflow_dispatch input to expression evaluator
This changes adds the workflow_dispatch event inputs
to the `inputs` context and maintaining the boolean type
* fix: coerce boolean input types
* fix: use step env if available, rc env otherwise
* test: add test for networking setup in act
This test makes sure that the hostname inside of act is resolvable.
* fix: only merge existing container options
When merging parsed container options without options being
set in a job, the default docker options are returned and
will override the expected defaults by act (e.g. network mode).
This is a first attempt to mitigate this behavior and only
merge settings if something was requested on a job.
* refactor: split config merging into own function
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
The env for remote composite actions need to be re-evaluated
at every stage (pre, main, post) as it is created during the
pre stage but there might be changes used as input to this
actions main stage (e.g. outputs for another action).
This is not required for local actions as their env is created
for the main stage (there is no pre stage).
Post stages do not need an updated env since they cannot recieve
inputs from other actions.
* fix: support docker create arguments from container.options (#1022)
* fix processing of errors, add verbose logging, fix test
* disable linter for code copied from docker/cli
* fix all linter issues
* Add license info
* Add opts_test.go from docker/cli and required testdata
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* test: add test case for #1319
* fix: setup of composite inputs
This change fixes the composite action setup handling of inputs.
All inputs are taken from the env now. The env is composed of
the 'level above'.
For example:
- step env -> taken from run context
- action env -> taken from step env
- composite env -> taken from action env
Before this change the env setup for steps, actions and composite
run contexts was harder to understand as all parts looked into
one of these: parent run context, step, action, composite run context.
Now the 'data flow' is from higher levels to lower levels which should
make it more clean.
Fixes#1319
* test: add simple remote composite action test
Since we don't have a remote composite test at all
before this, we need at least the simplest case.
This does not check every feature, but ensures basic
availability of remote composite actions.
* refactor: move ActionRef and ActionRepository
Moving ActionRef and ActionRepository from RunContext into the
step, allows us to remove the - more or less - ugly copy operations
from the RunContext.
This is more clean, as each step does hold the data required anyway
and the RunContext shouldn't know about the action details.
* refactor: remove unused properties
* fix: show workflow info even if on.push is not defined (#1329)
To fix listing of workflows in such cases list/graph filtering was split with planning.
Now act supports one of the following list (-l)/graph (-g) cases:
* show all jobs of loaded workflows: act -l
* show specific job JOBNAME: act -l -j JOBNAME
* show jobs of loaded workflows in which event EVENTNAME is set up: act -l EVENTNAME
* show jobs of loaded workflows in which first defined workflow event is set up: act -l --detect-event
For planning it supports:
* running specific job JOBNAME with triggered event determined from:
** CLI argument: act -j JOBNAME EVENTNAME
** first defined in loaded workflows event: act -j JOBNAME --detect-event
** only defined in loaded workflows event: act -j JOBNAME
** push event by default: act -j JOBNAME
* running jobs of loaded workflows in which event is set up, event is determined from:
** CLI argument: act EVENTNAME
** first defined in loaded workflows event: act --detect-event
** only defined in loaded workflows event: act
** push event by default: act
Except #1329 this PR fixes#1332, #1318
* Update docs/help
For log processing of the JSON logs, we want to be able to know which
keys/values of the matrices were used.
This commit adds the current matrix map to the job logger.
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* fix: align github.ref to GitHub Action
The `github.ref` value should be `refs/heads/branch` in most cases.
There are a few exceptions handled by the code.
This change prefixes the default case with `refs/heads` and adds
tests for this and the excpetional cases.
* fix: correct existing assertions
* refactor: ignore already closed error
This hides the `file already cloesd` error as it is
distracting in the output and does not provide any value.
* refactor: use go errors
Co-authored-by: Casey Lee <caseypl@amazon.com>
This fixes an issue in the chain of post steps introduced
while updating the step-logger for composite actions.
It includes a test case so we make sure this does not happen
again.
* walk submodule path instead of dir name
* use file path instead of relative path
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
when running nested composite actions, step ids were repeating
leading to errors in parsing the output. this patch adds the
parent step id to ste stepID field.
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Made env interpolated instead of evaluated.
* [skip ci] Add Test Workflow file
* Activate Test
* fix Test
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
currently build fail with:
```
run golangci-lint
Running [/home/runner/golangci-lint-1.47.0-linux-amd64/golangci-lint run --out-format=github-actions] in [] ...
Error: G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (gosec)
```
for example in this PR:
https://github.com/nektos/act/runs/7405009660?check_suite_focus=true
this sets the required ReadHeaderTimeout
* fix: the number in the github event is of type number
The go %s formattig option outputs the type if the given
input value is not of type string.
* test: update test data as well
* fix: use floats
This change stops act from rejecting valid entries such as
```
timeout-minutes: ${{ matrix.runtime == 'v8' && 30 || 15 }}
```
at the job level.
This change complements the fix that was already in place
for the Step struct, done in #1217. See:
52f5c4592c
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* feat(#1161): add --through-action to assigned actions from GitHub
* docs(flags): add --through-action and --through-action-token flags description
* test(action, remote): add test case for ThroughAction
* refactor(command): rename command from --through-action to --actions-from-github
* refactor(command): rename command from --actions-from-github to --replace-ghe-action-with-github-com
* Added tests for mid-size and big artifacts, reproducing a problem with chunked uploads.
* Added support for chunked uploads.
* Enforced overwriting uploaded artifacts on receiving the first chunk.
Co-authored-by: Casey Lee <cplee@nektos.com>
Do not initialize inputs a second time (in pre and main step).
When the action setup already run during pre step, we must not
re-run it during the main step, otherwise the inputs will be
overwritten by possible other action inputs.
* feat: use logger from context wherever possible
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* feat: add step/job id and results to json logs
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* test: value to be masked should not be hard-coded in the action
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* fix: replace values following ::add-mask:: in evaluated strings
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* feat: [DEBUG] identifier for debug logs to distinguish them
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* feat: replace logger with step logger
The container gets injected a job logger, but during the time that steps
are run, we want to use the step logger.
This commit wraps pre/main/post steps in an executor that replaces the
job logger with a step logger.
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* feat: add pre/post stage identifier fields to json log output
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* feat: add job/step result status to skipped steps/jobs
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* fix: skip local actions pre step in any case
We should skip local actions pre step, as it is not supported by github.
In turn we may need to late prepare remote actions which are run
as steps in a local composite action.
Fixes#1193
* test: remove obsolete test case
Since local actions does not run any pre-step anymore we don't test this case.
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
There might be use cases where users want to use GitHub's variables in
the environment variables, which is a valid use case.
This commits adds support for replacement of GitHub's env with GitHub's
values.
Signed-off-by: André Martins <aanm90@gmail.com>
* Update step_action_local.go
* Enable Tests for DRYRUN
* Update runner_test.go
* Update runner_test.go
* Move DRYRUN Test in it's own function
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* feat: handle context cancelation during docker exec
To allow interrupting docker exec (which could be long running)
we process the log output in a go routine and handle
context cancelation as well as command result.
In case of context cancelation a CTRL+C is written into the docker
container. This should be enough to terminate the running
command.
To make sure we do not get stuck during cleanup, we do
set the cleanup contexts with a timeout of 5 minutes
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Philipp Hinrichsen <philipp.hinrichsen@new-work.se>
* feat: handle SIGTERM signal and abort run
* test: on context cancel, abort running command
This test makes sure that whenever the act Context was canceled, the
currently running docker exec is sent a 0x03 (ctrl+c).
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* test: make sure the exec funcction handles command exit code
This test makes sure that the exec function does handle
docker command error results
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Philipp Hinrichsen <philipp.hinrichsen@new-work.se>
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* feat: add post step to actions and add state command
This commit includes requried changes for running post steps
for local and remote actions.
This allows general cleanup work to be done after executing
an action.
Communication is allowed between this steps, by using the
action state.
* feat: collect pre and post steps for composite actions
* refactor: move composite action logic into own file
* refactor: restructure composite handling
* feat: run composite post steps during post step lifecycle
* refactor: remove duplicate log output
* feat: run all composite post actions in a step
Since composite actions could have multiple pre/post steps inside,
we need to run all of them in a single top-level pre/post step.
This PR includes a test case for this and the correct order of steps
to be executed.
* refactor: remove unused lines of code
* refactor: simplify test expression
* fix: use composite job logger
* fix: make step output more readable
* fix: enforce running all post executor
To make sure every post executor/step is executed, it is chained
with it's own Finally executor.
* fix: do not run post step if no step result is available
Having no step result means we do not run any step (neither pre
nor main) and we do not need to run post.
* fix: setup defaults
If no pre-if or post-if is given, it should default to 'always()'.
This could be set even if there is no pre or post step.
In fact this is required for composite actions and included post
steps to run.
* fix: output step related if expression
* test: update expectation
* feat: run pre step from actions (#1110)
This PR implements running pre steps for remote actions.
This includes remote actions using inside local composite actions.
* fix: set correct expr default status checks
For post-if conditions the default status check should be
always(), while for all other if expression the default status
check is success()
References:
https://docs.github.com/en/actions/learn-github-actions/expressions#status-check-functionshttps://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runspost-if
* fix: remove code added during rebase
If a step does not have either a `run` or `uses` directive it is
considered invalid.
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* refactor: remove composite action runcontext workaround
The RunContext is cloned to execute a composite action with all its
steps in a similar context. This required some workaround, since
the command handler has kept a reference to the original RunContext.
This is solved now, by replacing the docker LogWriter with a proper
scoped LogWriter.
This prepares for a simpler setup of composite actions to be able
to create and re-create the composite RunContext for pre/main/post
action steps.
* test: check env-vars for local js and docker actions
* test: test remote docker and js actions
* fix: merge github context into env when read and setup
* refacotr: simplify composite context setup
* test: use a map matcher to test input setup
* fix: restore composite log output
Since we create a new line writer, we need to log the raw_output as well.
Otherwise no output will be available from the log-writer
* fix: add RunContext JobName to fill GITHUB_JOBNAME
* test: use nektos/act-test-actions
* fix: allow masking values in composite actions
To allow masking of values from composite actions, we need
to use a custom job logger with a reference to the masked
values for the composite run context.
* refactor: keep existing logger for composite actions
To not introduce another new logger while still be able to use
the masking from the composite action, we add the masks to
the go context. To leverage that context, we also add the context
to the log entries where the valueMasker then could get the actual
mask values.
With this way to 'inject' the masked values into the logger, we do
- keep the logger
- keep the coloring
- stay away from inconsistencies due to parallel jobs
* fix: re-add removed color increase
This one should have never removed :-)
* fix: add missing ExtraPath attribute
* fix: merge run context env into composite run context env
This adds a test and fix for the parent environment. It should be
inherited by the composite environment.
* test: add missing test case
* fix: store github token next to secrets
We must not expose the secrets to composite actions, but the
`github.token` is available inside composite actions.
To provide this we store the token in the config and create it in
the GithubContext from there.
The token can be used with `github.token` but is not available as
`secrets.GITHUB_TOKEN`.
This implements the same behavior as on GitHub.
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Marcus Noll <markus.noll@new-work.se>
* fixup! fix: allow masking values in composite actions
* style: use tabs instead of spaces to fix linter errors
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Marcus Noll <markus.noll@new-work.se>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
To make the test logs more readable, we should fold the
output per test into a group.
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This prevented JetBrains GoLand from recognising subtests and treated
it all as single big test, VSCode seems to be still broken in that regard
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Casey Lee <cplee@nektos.com>
Prevents random failing of all other runs when qemu binfmt
is not set up
Signed-off-by: Ryan <me@hackerc.at>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* don't merge env var if it exists already
* remove test workflow
* add some tests
* change mergeMaps order instead of checking for existence
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* fix: copy ignored tracked files
* fix
* refactor: Extract callback to fileCollector
fix: temporary tar archive not deletable on windows
fix: `.*` in gitignore ignores all files
* Move nolint: gocyclo
* pass context as parameter
* goimport
* Add fs interface + one test
* fix lint, also test for ignored non tracked file
* fix filename
* Apply suggestions from code review
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This change reduces the interfaces by removing
obsolete parameters from functions.
Obsolete parameters does not means unused ones, but
parameters which could be retrieved from other parameters
instead.
This should simplify logic and maintainability for these
functions.
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* refactor: split step_context into separate files
This commit moves functions from the step_context.go file into different
files, but does otherwise not change anything.
This is done to make it easier to review the changes made to these
functions in the next commit, where we introduce a step factory to
facilitate better unit testing of steps.
Co-authored-by: Marcus Noll <marcus.noll@new-work.se>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Robert Kowalski <robert.kowalski@new-work.se>
Co-authored-by: Philipp Hinrichsen <philipp.hinrichsen@new-work.se>
Co-authored-by: Jonas Holland <jonas.holland@new-work.se>
* refactor: introduce step factory and make steps testable
With this commit we're introducing the `stepFactory` and interfaces
and implementations for each different kind of step (run, docker,
local and remote actions).
Separating each step kind into its own interface and implementation
makes it easier to reason about and to change behaviour of the step.
By introducing interfaces we enable better unit testability as now
each step implementation, the step factory and the job executor can
be tested on their own by mocking out parts that are irrelevant.
This commits prepares us for implementing pre/post actions in a
later PR.
Co-authored-by: Marcus Noll <marcus.noll@new-work.se>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Robert Kowalski <robert.kowalski@new-work.se>
Co-authored-by: Philipp Hinrichsen <philipp.hinrichsen@new-work.se>
Co-authored-by: Jonas Holland <jonas.holland@new-work.se>
* fix: run post steps in reverse order
* test: add missing asserts for mocks
* refactor: use local reference instead of function
This may make code more easy to follow.
* refactor: correct typo in function name
* test: use named structs
* test: only expected valid calls
There are mocks which are only called on certain conditions.
* refactor: use step-model to get step name
Using the step-logger we have to get the logger name from the
step model.
* test: only mock stopContainer if required
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Marcus Noll <marcus.noll@new-work.se>
Co-authored-by: Robert Kowalski <robert.kowalski@new-work.se>
Co-authored-by: Philipp Hinrichsen <philipp.hinrichsen@new-work.se>
Co-authored-by: Jonas Holland <jonas.holland@new-work.se>
Co-authored-by: Casey Lee <cplee@nektos.com>
Co-authored-by: Christopher Homberger <christopher.homberger@web.de>
* Fix: panic: reflect: slice index out of range
* Update interpreter.go
* [no ci] Return null for negative indexes
* Add tests for index access
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
act has a feature that skips the checkout action to do a remote
checkout when a local checkout exists. in some cases, e.g. when
running act in a CI, you always want to clone the repository.
The function `WithTestContext` is never called in the project, and
there is just one usage of `TestContext`, inside one of our loggers
Co-authored-by: Casey Lee <cplee@nektos.com>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* feat: add step name to logger field
This change does add the step name to the logger fields. This does
not change the output for our users, but for the json logger, it
does make each step output traceable.
* fix: remove new logger
Since logrus and context both are immutable for our case, we
can just add a new field and store the logger in the context.
Co-authored-by: Casey Lee <cplee@nektos.com>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-Authored-By: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Casey Lee <cplee@nektos.com>
* feat: add json logger output
This will allow to format log output as json.
This is helpful in cases where act is not executed on a 'local' machine.
* refactor: use runner config
Using the runner config to configure logging is cleaner.
Co-authored-by: Casey Lee <cplee@nektos.com>
this commit adds support for the `::add-mask::` command, which was
implemented as a stub before.
it does not cover debug output that appears when you run act in
verbose mode
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* feat: run jobs in parallel
This changes fixes and restructures the parallel execution of jobs.
The previous changes limiting the parallel execution did break this
and allowed only one job in parallel.
While we run #CPU jobs in parallel now, the jobs added per job-matrix
add to this. So we might over-commit to the capacity, but at least
it is limited.
* fix: correctly build job pipeline
The job pipeline should just append all required pipeline steps.
The parallelism will be handled by the ParallelExecutor and we
shouldn't handle it during building the pipelines.
Also this adds a test, that the ParallelExecutor does run
a limited amount of parallel goroutines.
* test: correct test implementation
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* refactor: remove debug error output
Errors should always be logged with an error level and not debug level.
Since the error is returned here, it will be logged later as an error.
Presumably this was a leftover from debugging the executor chain in:
PR: #971
* refactor: debug log wich expression is going to be evaluated
* fix: handle nil in EvalBool
We've seen this issue when the env map is not set-up properly,
i.e. when the env map is nil, EvalBool might return nil, which should
be handled as a falsy value.
* fix: fail on error in if expression and return the evaluation error
Stop running the workflow in case an expression cannot be evaluated.
Fixes: #1008
* fix: remove quotes from inside expression syntax in test
It looks like having an expression inside double quotes inside the
expression syntax is not valid: https://github.com/ZauberNerd/act-test/actions/runs/1881986429
The workflow is not valid. .github/workflows/test.yml (Line: 10, Col: 13): Unexpected symbol: '"endsWith'. Located at position 1 within expression: "endsWith('Hello world', 'ld')"
* refactor: export IsTruthy function from exprparser package
* refactor: use IsTruthy function in EvalBool
* refactor: move debug log for expression rewrite to rewrite function
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* refactor: default empty `if:` statement to `if: success()` in evaluator
Previously the code to default an empty `if:` statement in the yaml file
was implemented in different files in the model package.
Now an empty `if:` statement defaults to `success()` in the expression
evaluator.
* refactor: remove obsolete `FixIfStatement` functions
The introduction of the expression evaluator seems to have made these
functions obsolete, as the test case `TestRunEvent/issue-598` works even
without these functions.
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This change extracts the functionality of reading an `action.y(a)ml` or
creation of a `(Synthetic Action)` into its own type to enable better
unit testing / mocking of those IO operations.
This is done in preparation for the implementation of pre/post action
support in act.
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
This splits the executor from the RunContext into its own function
called newJobExecutor.
We defined an interface called jobInfo which is implemented by the RunContext.
This enables better unit testing because only a small interface needs to
be mocked.
This is a preparation for implementing pre and post actions.
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Marcus Noll <marcus.noll@new-work.se>
Co-authored-by: Jonas Holland <jonas.holland@new-work.se>
Co-authored-by: Robert Kowalski <robert.kowalski@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Marcus Noll <marcus.noll@new-work.se>
Co-authored-by: Jonas Holland <jonas.holland@new-work.se>
Co-authored-by: Robert Kowalski <robert.kowalski@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Github sets the outcome and conclusion to skipped
and this PR does the same during the pipeline run for
the StepResults in act.
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
With this change `act` will try to populate the `githubContext.ref` and
`githubContext.sha` with values read from the event payload.
Caveats:
- `page_build` should not have a ref
- `status` should not have a ref
- `registry_package` should set the ref to the branch/tag but the
payload isn't documented
- `workflow_call` should set ref to the same value as its caller but the
payload isn't documented
- most of the events should set the sha to the last commit on the ref
but unfortunately the sha is not always included in the payload,
therefore we use the sha from the local git checkout
Co-Authored-By: Philipp Hinrichsen <philipp.hinrichsen@new-work.se>
Co-authored-by: Philipp Hinrichsen <philipp.hinrichsen@new-work.se>
* feat: implement expression evaluator
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Philipp Hinrichsen <philipp.hinrichsen@new-work.se>
* feat: integrate exprparser into act
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Philipp Hinrichsen <philipp.hinrichsen@new-work.se>
* Escape { and }, do not fail on missing properties
* Fix empty inputs context
* fix: contains() comparison for complex values
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Philipp Hinrichsen <philipp.hinrichsen@new-work.se>
Co-authored-by: Christopher Homberger <christopher.homberger@web.de>
This commit moves the githubContext, jobContext and stepResult structs
from the runner package to the model package in preparation for #908
because the expression.go file lives in the runner package and would
introduce cyclic dependencies with the exprparser package.
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Feature: uses in composite
* Negate logic
* Reduce complexity
* Update step_context.go
* Update step_context.go
* Update step_context.go
* Fix syntax error in test
* Bump
* Disable usage of actions/setup-node@v2
* Bump
* Fix step id collision
* Fix output command workaround
* Make secrets context inaccessible in composite
* Fix order after adding a workaround (needs tests)
Fixes https://github.com/nektos/act/pull/793#issuecomment-922329838
* Evaluate env before passing one step deeper
If env would contain any inputs, steps ctx or secrets there was undefined behaviour
* [no ci] prepare secret test
* Initial test pass inputs as env
* Fix syntax error
* extend test also for direct invoke
* Fix passing provided env as composite output
* Fix syntax error
* toUpper 'no such secret', act has a bug
* fix indent
* Fix env outputs in composite
* Test env outputs of composite
* Fix inputs not defined in docker actions
* Fix interpolate args input of docker actions
* Fix lint
* AllowCompositeIf now defaults to true
see https://github.com/actions/runner/releases/tag/v2.284.0
* Fix lint
* Fix env of docker action.yml
* Test calling a local docker action from composite
With input context hirachy
* local-action-dockerfile Test pass on action/runner
It seems action/runner ignores overrides of args,
if the target docker action has the args property set.
* Fix exec permissions of docker-local-noargs
* Revert getStepsContext change
* fix: handle composite action on error and continue
This change is a follow up of https://github.com/nektos/act/pull/840
and integrates with https://github.com/nektos/act/pull/793
There are two things included here:
- The default value for a step.if in an action need to be 'success()'
- We need to hand the error from a composite action back to the
calling executor
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
* Patch inputs can be bool, float64 and string
for workflow_call
Also inputs is now always defined, but may be null
* Simplify cherry-picked commit
* Minor style adjustments
* Remove chmod +x from tests
now fails on windows like before
* Fix GITHUB_ACTION_PATH some action env vars
Fixes GITHUB_ACTION_REPOSITORY, GITHUB_ACTION_REF.
* Add comment to CompositeRestrictions
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Ryan <me@hackerc.at>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* fix: rework `setupShellCommand`
* move all logic to separate function so we can test that later
* split `step.Shell` and `step.WorkingDirectory` setup into own funcs
* general cleanup of function
* use `ActPath` to not collide with checked out repository
* use `shellquote.Split()` instead of `strings.Fields()` for better command split
* replace single string concat with `fmt`
Signed-off-by: hackercat <me@hackerc.at>
* lint(editorconfig): ignore *_test.go due to mixed style
Signed-off-by: hackercat <me@hackerc.at>
* fix: continue jobs + steps after failure
To allow proper if expression handling on jobs and steps (like always,
success, failure, ...) we need to continue running all executors in
the prepared chain.
To keep the error handling intact we add an occurred error to the
go context and handle it later in the pipeline/chain.
Also we add the job result to the needs context to give expressions
access to it.
The needs object, failure and success functions are split between
run context (on jobs) and step context.
Closes#442
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* style: correct linter warnings
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* fix: job if value defaults to success()
As described in the documentation, a default value of "success()" is
applied when no "if" value is present on the job.
https://docs.github.com/en/actions/learn-github-actions/expressions#job-status-check-functions
Co-authored-by: Markus Wolf <mail@markus-wolf.de>
* fix: check job needs recursively
Ensure job result includes results of previous jobs
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* test: add runner test for job status check functions
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* test: add unit tests for run context if evaluation
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* refactor: move if expression evaluation
Move if expression evaluation into own function (step context) to
better support unit testing.
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* test: add unit tests for step context if evaluation
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
* fix: handle job error more resilient
The job error is not stored in a context map instead of a context
added value.
Since context values are immutable an added value requires to keep
the new context in all cases. This is fragile since it might slip
unnoticed to other parts of the code.
Storing the error of a job in the context map will make it more stable,
since the map is always there and the context of the pipeline is stable
for the whole run.
* feat: steps should use a default if expression of success()
* test: add integration test for if-expressions
* chore: disable editorconfig-checker for yaml multiline string
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
* feat: read docker credentials from local docker config
* fix: url.Parse requires protocol
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* fix: docker decides by the existence of . or : if...
... the image is in a custom registry or not.
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* fix: make docker hostname detection more robust
* test: mock docker config for getImagePullOptions test
By default github actions have a docker config set with a token to pull
images from docker hub.
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
We should reuse an existing context logger if in test context.
This will allow test to setup act with a null logger to assert
log messages.
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Adds option to rebuild local action docker images
Fixed up README due to missing flags after
PR #714 and #716
Signed-off-by: hackercat <me@hackerc.at>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* 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
* tests(pkg/common) add failing test case for SSH git URL
* fix(pkg/common) github SSH regex for missing .git extension
Co-authored-by: Ryan <me@hackerc.at>
We should reuse an existing context logger if available.
This will allow test to setup act with a null logger to assert
log messages.
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
* ci(golangci-lint): switch to latest
remove schema override since it was fixed in upstream
Signed-off-by: hackercat <me@hackerc.at>
* fix: apply lint fixes
* Add asset server and upload handling of binary files
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* Add asset download parts to the asset server
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* Add artifact-server-path flag
If the flag is not defined, the artifact server isn't started.
This includes the configuration of ACTIONS_RUNTIME_URL and
ACTIONS_RUNTIME_TOKEN which are set if the server is started.
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* Move ACTIONS_RUNTIME_* vars into the withGithubEnv setup
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* feat: add artifact server port as flag
This commits adds a flag to define the artifact server port.
If not given, the port defaults to 34567.
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
* test: add artifact server tests
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
* refactor: use fs.FS
This allows to add tests with in-memory file system
* feat: add support for gzip encoded uploads
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
* test: add artifact integration test
* chore: run act tests with asset server path
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
* docs: add new cli flags
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
* test: add test workflow to testdata
* feat: add log output
* refactor: log shutdown error instead of panic
* feat: use outbound ip for the asset server
This change should allow to use the host ip in macos and windows.
Since docker is running in an intermediate vm, localhost is not
sufficient to have the artifacts in the host system.
* fix: do not use canceled context
To shutdown artifact server, we should not use the already canceled
context but the parent context instead.
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* feat: shutdown artifact server at end of pipeline
When the pipeline is done the asset server should be shut down
gracefully.
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* fix: close server if graceful shutdown failed
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
* fix: ignore server closed error from listen call
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
* fix: set default shell for containers to sh
This matches GitHub Actions behaviour where,
runners use bash since it's guaranteed to exist there
while containers use sh for compatibility
* tests: fixup for default shell
* fix: rewrite StepContext env
step env from workflow should be last one to be written
fixes https://github.com/nektos/act/issues/777
* test: verify env correctness
* fix: move test into existing workflow
* fix: align other Docker executors to print action
* fix: formatting
* fix: add proper workdir support
* fix: replace script filepath after slice creation
* fix: match substring so it works for pwsh
+ rename containerPath to scriptPath to reflect what value it contains