Commit graph

30 commits

Author SHA1 Message Date
Markus Wolf
6744e68ee2
fix: correct ref and ref_name (#1672)
* fix: correct ref and ref_name

The ref in the GitHub context is always full qualified
(e.g. refs/heads/branch, refs/tags/v1).
The ref_name is the ref with the strippep prefix.
In case of pull_requests, this is the merge commit ref
(e.g. refs/pull/123/merge -> 123/merge).

* test: update test data
2023-03-09 20:03:13 +00:00
Alex Savchuk
5500c928eb
fix: github.job property is empty, GITHUB_JOB should be job id (#1646)
* fix: github.job property is empty, GITHUB_JOB should be job id

fix: github.job property is empty #1621
fix: GITHUB_JOB should be the id not the name #1473

* fix linter problem.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2023-02-27 19:10:31 +00:00
ChristopherHX
f2b98ed301
feat: Host environment (#1293) 2022-11-16 21:29:45 +00:00
Markus Wolf
97c083e902
fix: align github.ref to GitHub Action (#1362)
* 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
2022-09-26 22:49:19 +00:00
Björn Brauer
4391a10d5a
Improve logging (#1171)
* 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>
2022-06-17 15:55:21 +00:00
Markus Wolf
943a0e6eea
implement pre and post steps (#1089)
* 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-functions
https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runspost-if

* fix: remove code added during rebase
2022-05-24 13:36:06 +00:00
Markus Wolf
e360811570
refactor: remove composite action runcontext workaround (#1085)
* 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>
2022-05-11 19:06:05 +00:00
Ryan
72dd2d344c
tests(runner): move arm64 test to own func (#1095)
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>
2022-04-05 15:41:36 +00:00
Seunghyun Hwang
407d324ec1
implement volume mount for container job (#1101)
* implement volume mount for container job

* Update pkg/runner/run_context.go

Co-authored-by: Ryan <me@hackerc.at>

* add tests for container volume mount options

* remove unused code

* prefer if-else instead of if-continue

* remove continue

* add some tests

Co-authored-by: Ryan <me@hackerc.at>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-04-04 18:01:13 +00:00
Liam Murphy
9dc17f9144
Allow passed in env vars to supersede ones declared in the workflow (#1100)
* 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>
2022-04-04 17:24:49 +00:00
Björn Brauer
eba71f98fe
Refactor expression evaluator to use parser from actionlint package (#908)
* 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>
2022-01-21 08:07:20 -08:00
Björn Brauer
ed01f464ed
refactor: export and move shared contexts into pkg/model (#931)
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>
2021-12-22 19:52:09 +00:00
Markus Wolf
1891c72ab1
fix: continue jobs + steps after failure (#840)
* 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>
2021-12-08 20:57:42 +00:00
Victor Popkov
e793d03f4b
Add more steps context support (#887)
* feat: add more steps context support

- Add step outcome
- Remove step success in favour of conclusion

* feat: add conclusion and outcome steps context tests

Add corresponding tests and extend pkg/runner/expression.go vmSteps() to
handle steps context conclusion and outcome iota as strings.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-11-27 17:55:26 +00:00
Ryan
94fd0ac899
Simplify Matrix decode, add defaults for fail-fast and max-parallel, add test (#763)
* fix[workflow]: multiple fixes for workflow/matrix

fix[workflow]: default `max-parallel`
fix[workflow]: default `fail-fast`, it's `true`, not `false`
fix[workflow]: skipping over the job when `strategy:` is defined but `matrix:` isn't (fixes #625)
fix[workflow]: skip non-existing includes keys and hard fail on non-existing excludes keys
fix[workflow]: simplify Matrix decode (because I "think" I know how `yaml` works) (fixes #760)
fix[tests]: add test for planner and runner

* fix(workflow): use yaml node for env key

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-08-09 15:35:05 +00:00
Ryan (hackercat)
a9fe038347
Update images, fix extrapath (#723)
* fix: typo

* fix: remove debug for git references

it generates a massive amount of logs

* feat: read values from env

allows to test act on GHA when it's not a main repo

* fix: merge extrapath with PATH

* fix(tests): add additional shells for testing

* fix(image): update images

pin node to major version only, current node version: 12.22.1
replace most images with `node:12-buster-slim` to prevent
errors on macOS runner due to DockerHub pull limit
replace ocaml image

Co-authored-by: Casey Lee <cplee@nektos.com>
2021-06-10 23:12:05 +00:00
Justin Grote
a9295c9db2
Test fixups for Windows/Forks (#681)
* Test fixups for Windows/Forks

* revert change for repo/actor/owner

this is fixed via https://github.com/nektos/act/pull/723

Co-authored-by: Ryan (hackercat) <me@hackerc.at>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-06-10 18:27:35 +00:00
Ryan (hackercat)
d794e2fe4c
Move actions path outside of workdir (#701)
* feat: add option to specify user for exec

* fix: move actions to static path outside workdir

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-05-24 17:09:03 +00:00
Ryan (hackercat)
f571290b25
refactor: remove gotest.tools (#688)
* refactor: remove `gotest.tools`

* remove all references to `gotest.tools` and replace it with
  `github.com/stretchr/testify` which was originally used for tests
* bump `golangci-lint` version
* add `depguard` and `importas` to prevent import of unwanted packages
* add custom schema and information about config since
  schemastore.org has broken schema for `golangci-lint` config

* fix: handle more error cases
2021-05-17 23:14:49 -07:00
Josh Soref
a144e71a1b
Add various GitHub environment variables (#604)
* define GITHUB_ACTION_PATH #603

* Add more environment variables

* Add job name

Note: the job name gets a suffix for matrix builds, but this is not part of the env var

* fix: remove unnecessary variables

* feat: add `RepositoryOwner`

credit: @KnisterPeter

* feat: add test for `getGithubContext()`

Co-authored-by: Ryan (hackercat) <me@hackerc.at>
2021-05-06 20:02:29 +00:00
Justin Grote
0f049426f6
Separate Container Workdir from host Workdir (#635)
* Separate Container Workdir from Host Workdir

* Add delegated component to MacOS Test

* Lint: Remove leading newline

* Fix trailing path issue
2021-05-04 14:50:35 -07:00
Ryan (hackercat)
cec63488f3
Add super-linter + fix lint issues (#650)
* feat: bump `golangci-lint`, add `super-linter`, replace outdated linter

Bump `golangci-lint` version.
Add `super-linter` to lint other languages.
Go linter is disabled because it's currently broken:
https://github.com/github/super-linter/pull/370
Replacing `scopelint` with `exportloopref`: "[runner] The linter
'scopelint' is deprecated (since v1.39.0) due to: The repository of the
linter has been deprecated by the owner.  Replaced by exportloopref."
Fixed formatting in `.golangci.yml`
Add addtional linters:
  `misspell`: purely style, detects typos in comments
  `whitespace`: detects leading and trailing whitespace
  `goimports`: it's gofmt + checks unused imports

* fix: lint/fix `go` files

* fix: lint with `standardjs`

* fix: lint/fix with `markdownlint`, make template more verbose

* feat: add lint stuff to makefile

* fix: `UseGitIgnore` formatting

* fix: lint/fix `README.md`

Co-authored-by: Casey Lee <cplee@nektos.com>
2021-05-03 09:52:03 -07:00
Josh Soref
5752a03dcd
Support running commands in repositories without action.yaml (#293)
* Comment for public function

* Add git describe fallback

* spelling: github

* Set initial branch to satisfy tests for modern git

* Clarify -even- if

* Go 1.16

* Support running commands in repositories without action.yaml

Support runnings commands with only a Docker file

Co-authored-by: Casey Lee <cplee@nektos.com>
2021-03-30 12:26:25 -07:00
hackercat
09679f0156
Update test workflows and improve expression_test.go/run_context_test.go (#560)
* fix: give case insensitive secret more meanigful name

* refactor: use `string` in generating `env:` and `steps:` for workflows

Smaller text generation is much better to read with normal strings than
raw string literals.

* feat: sort keys for `env:` so it's always in specific order

* fix: update test workflows
2021-03-12 16:25:10 -08:00
Ed
c7b3869b2f
Report error when if expression is invalid (#485)
Co-authored-by: Ed Tan <edtan@users.noreply.github.com>
Co-authored-by: Casey Lee <cplee@nektos.com>
2021-01-18 11:44:27 -08:00
Torbjørn Vatn
b3299ecd30
Act env (#417)
* Test more if env variants

* The correct negation syntax is !=

* Make the Interpolate function support negated booleans from envs

* Move assert := a.New(t) into t.Run

This uncovered that some of the test premisses was wrong and the
Eval Bool function also had flaws

* Remove a stray logrus import

* Add an ACT env set to true

This can be used to skip certain steps that you don't want to run locally
when testing. E.g. steps that sends messages to Slack channels on successful
builds etc.

* Add a description about env.ACT to the readme

* A new attempt at Interpolation and EvalBool

* One small merge fix

* Remove some fmt.Printfs

* Fix some merge conflicts
2020-11-18 07:14:34 -08:00
Torbjørn Vatn
8ba3306aa4
EvalBool and Interpolation fixes (#424)
* A new attempt at Interpolation and EvalBool

* One small merge fix

* Remove some fmt.Printfs
2020-11-17 09:31:05 -08:00
Torbjørn Vatn
3f4998a4ed
envs in if: - take 2 (#412)
* Test more if env variants

* The correct negation syntax is !=

* Make the Interpolate function support negated booleans from envs

* Move assert := a.New(t) into t.Run

This uncovered that some of the test premisses was wrong and the
Eval Bool function also had flaws

* Remove a stray logrus import
2020-11-12 08:15:09 -08:00
Stan Wohlwend
d4e41a90a2
Fix container volumes being reused sometimes (#283) 2020-06-18 08:21:55 -07:00
Torbjørn Vatn
a149cf8ca2
Make envs available in if conditionals (#225)
* Ignore .idea

* Add Env to the RunContext vm so we can Evaluate and Interpolate `env.xx`

* Make EvalBool support expressions more in line with the github runner

* Turns out Boolean(value) is what github is doing after all

* Add test for github context as well
2020-05-04 12:18:13 -07:00