Feature: uses in composite (#793)

* 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>
This commit is contained in:
ChristopherHX
2021-12-22 20:19:50 +01:00
committed by GitHub
parent 2ef30c3776
commit 9868e13772
19 changed files with 465 additions and 159 deletions

View File

@@ -0,0 +1,8 @@
# Container image that runs your code
FROM node:12-buster-slim
# Copies your code file from your action repository to the filesystem path `/` of the container
COPY entrypoint.sh /entrypoint.sh
# Code file to execute when the docker container starts up (`entrypoint.sh`)
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -0,0 +1,15 @@
name: 'Hello World'
description: 'Greet someone and record the time'
inputs:
who-to-greet: # id of input
description: 'Who to greet'
required: true
default: 'World'
outputs:
time: # id of output
description: 'The time we greeted you'
runs:
using: 'docker'
image: 'Dockerfile'
env:
WHOAMI: ${{ inputs.who-to-greet }}

View File

@@ -0,0 +1,8 @@
#!/bin/sh -l
echo "Hello $1"
time=$(date)
echo ::set-output name=time::$time
echo ::set-output name=whoami::$WHOAMI
echo "SOMEVAR=$1" >>$GITHUB_ENV

View File

@@ -1,5 +1,8 @@
name: local-action-dockerfile
on: push
defaults:
run:
shell: bash
jobs:
test:
@@ -15,4 +18,10 @@ jobs:
env:
SOMEVAR: 'Not Mona'
- run: '[[ "${{ steps.dockerlocal.outputs.whoami }}" == "Mona the Octocat" ]]'
# Test if overriding args doesn't leak inputs
- uses: ./actions/docker-local-noargs
with:
args: ${{format('"{0}"', 'Mona is not the Octocat') }}
who-to-greet: 'Mona the Octocat'
- run: '[[ "${{ env.SOMEVAR }}" == "Mona is not the Octocat" ]]'
- uses: ./localdockerimagetest_

View File

@@ -0,0 +1,44 @@
inputs:
who-to-greet:
default: 'Mona the Octocat'
runs:
using: composite
steps:
# Test if GITHUB_ACTION_PATH is set correctly before all steps
- run: stat $GITHUB_ACTION_PATH/push.yml
shell: bash
- run: stat $GITHUB_ACTION_PATH/action.yml
shell: bash
- run: '[[ "$GITHUB_ACTION_REPOSITORY" == "" ]] && [[ "$GITHUB_ACTION_REF" == "" ]]'
shell: bash
- uses: ./actions/docker-local
id: dockerlocal
with:
who-to-greet: ${{inputs.who-to-greet}}
- run: '[[ "${{ env.SOMEVAR }}" == "${{inputs.who-to-greet}}" ]]'
shell: bash
- run: '[ "${SOMEVAR}" = "Not Mona" ] || exit 1'
shell: bash
env:
SOMEVAR: 'Not Mona'
- run: '[[ "${{ steps.dockerlocal.outputs.whoami }}" == "${{inputs.who-to-greet}}" ]]'
shell: bash
# Test if overriding args doesn't leak inputs
- uses: ./actions/docker-local-noargs
with:
args: ${{format('"{0}"', 'Mona is not the Octocat') }}
who-to-greet: ${{inputs.who-to-greet}}
- run: '[[ "${{ env.SOMEVAR }}" == "Mona is not the Octocat" ]]'
shell: bash
- uses: ./localdockerimagetest_
# Also test a remote docker action here
- uses: actions/hello-world-docker-action@main
with:
who-to-greet: 'Mona the Octocat'
# Test if GITHUB_ACTION_PATH is set correctly after all steps
- run: stat $GITHUB_ACTION_PATH/push.yml
shell: bash
- run: stat $GITHUB_ACTION_PATH/action.yml
shell: bash
- run: '[[ "$GITHUB_ACTION_REPOSITORY" == "" ]] && [[ "$GITHUB_ACTION_REF" == "" ]]'
shell: bash

View File

@@ -0,0 +1,9 @@
name: local-action-dockerfile
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./local-action-via-composite-dockerfile

View File

@@ -0,0 +1,11 @@
---
name: "Test Composite Action"
description: "Test action uses composite"
runs:
using: "composite"
steps:
- run: exit 1
shell: bash
- run: echo should not run in composite steps
shell: bash

View File

@@ -0,0 +1,12 @@
name: uses-docker-url
on: push
jobs:
failing-composite-action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./uses-composite-with-error/composite_action2
- run: echo should run
if: failure()
- run: echo should not run

View File

@@ -22,11 +22,15 @@ inputs:
description: "Required with default, due to an old bug of github actions this is allowed"
required: true
default: "test_input_optional_value"
secret_input:
description: test pass a secret as input
outputs:
test_output:
description: "Output value to pass up"
value: ${{ step.output.outputs.test_output }}
value: ${{ steps.output.outputs.test_output }}
secret_output:
description: test pass a secret as output
value: ${{ format('{0}/{1}', inputs.secret_input, env.secret_input) }}
runs:
using: "composite"
@@ -85,6 +89,8 @@ runs:
# Let's send up an output to test
- run: echo "::set-output name=test_output::test_output_value"
id: output
shell: bash
- run: echo "COMPOSITE_ACTION_ENV_OUTPUT=my test value" >> $GITHUB_ENV
shell: bash

View File

@@ -14,11 +14,21 @@ jobs:
test_input_optional_with_default_overriden: 'test_input_optional_with_default_overriden'
test_input_required_with_default: 'test_input_optional_value'
test_input_required_with_default_overriden: 'test_input_required_with_default_overriden'
secret_input: ${{secrets.test_input_optional || 'NO SUCH SECRET'}}
env:
secret_input: ${{secrets.test_input_optional || 'NO SUCH SECRET'}}
- if: steps.composite.outputs.test_output != "test_output_value"
run: |
echo "steps.composite.outputs.test_output=${{ steps.composite.outputs.test_output }}"
exit 1
- run: |
echo "steps.composite.outputs.secret_output=${{ steps.composite.outputs.secret_output }}"
[[ "${{steps.composite.outputs.secret_output == format('{0}/{0}', secrets.test_input_optional || 'NO SUCH SECRET')}}" = "true" ]] || exit 1
shell: bash
- run: |
echo "steps.composite.outputs.secret_output=$COMPOSITE_ACTION_ENV_OUTPUT"
[[ "${{env.COMPOSITE_ACTION_ENV_OUTPUT == 'my test value' }}" = "true" ]] || exit 1
shell: bash
# Now test again with default values
- uses: ./uses-composite/composite_action
@@ -30,5 +40,5 @@ jobs:
- if: steps.composite2.outputs.test_output != "test_output_value"
run: |
echo "steps.composite.outputs.test_output=${{ steps.composite.outputs.test_output }}"
echo "steps.composite.outputs.test_output=${{ steps.composite2.outputs.test_output }}"
exit 1

View File

@@ -0,0 +1,63 @@
---
name: "Test Composite Action"
description: "Test action uses composite"
inputs:
test_input_optional:
description: Test
runs:
using: "composite"
steps:
# The output of actions/setup-node@v2 seems to fail the workflow
# - uses: actions/setup-node@v2
# with:
# node-version: '16'
# - run: |
# console.log(process.version);
# console.log("Hi from node");
# console.log("${{ inputs.test_input_optional }}");
# if("${{ inputs.test_input_optional }}" !== "Test") {
# console.log("Invalid input test_input_optional expected \"Test\" as value");
# process.exit(1);
# }
# if(!process.version.startsWith('v16')) {
# console.log("Expected node v16, but got " + process.version);
# process.exit(1);
# }
# shell: node {0}
- uses: ./uses-composite/composite_action
id: composite
with:
test_input_required: 'test_input_required_value'
test_input_optional: 'test_input_optional_value'
test_input_optional_with_default_overriden: 'test_input_optional_with_default_overriden'
test_input_required_with_default: 'test_input_optional_value'
test_input_required_with_default_overriden: 'test_input_required_with_default_overriden'
secret_input: ${{inputs.test_input_optional}}
env:
secret_input: ${{inputs.test_input_optional}}
- run: |
echo "steps.composite.outputs.test_output=${{ steps.composite.outputs.test_output }}"
[[ "${{steps.composite.outputs.test_output == 'test_output_value'}}" = "true" ]] || exit 1
shell: bash
- run: |
echo "steps.composite.outputs.secret_output=${{ steps.composite.outputs.secret_output }}"
[[ "${{steps.composite.outputs.secret_output == format('{0}/{0}', inputs.test_input_optional)}}" = "true" ]] || exit 1
shell: bash
# Now test again with default values
- uses: ./uses-composite/composite_action
id: composite2
with:
test_input_required: 'test_input_required_value'
test_input_optional_with_default_overriden: 'test_input_optional_with_default_overriden'
test_input_required_with_default_overriden: 'test_input_required_with_default_overriden'
- run: |
echo "steps.composite2.outputs.test_output=${{ steps.composite2.outputs.test_output }}"
[[ "${{steps.composite2.outputs.test_output == 'test_output_value'}}" = "true" ]] || exit 1
shell: bash
- run: |
echo "steps.composite.outputs.secret_output=$COMPOSITE_ACTION_ENV_OUTPUT"
[[ "${{env.COMPOSITE_ACTION_ENV_OUTPUT == 'my test value' }}" = "true" ]] || exit 1
shell: bash

View File

@@ -0,0 +1,15 @@
name: uses-docker-url
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./uses-nested-composite/composite_action2
with:
test_input_optional: Test
- run: |
echo "steps.composite.outputs.secret_output=$COMPOSITE_ACTION_ENV_OUTPUT"
[[ "${{env.COMPOSITE_ACTION_ENV_OUTPUT == 'my test value' }}" = "true" ]] || exit 1
shell: bash