[PR #514] [MERGED] Add support for composite actions #1480

Closed
opened 2026-03-01 21:51:21 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/nektos/act/pull/514
Author: @mdelillo
Created: 2/2/2021
Status: Merged
Merged: 4/2/2021
Merged by: @cplee

Base: masterHead: composite-actions


📝 Commits (10+)

  • 31531c1 Add support for composite actions
  • 2442b3e Merge branch 'master' into composite-actions
  • a9900d4 Fix to make more complex composite actions work
  • 0a71ead Merge pull request #1 from nektos/master
  • 63c4fba Merge branch 'master' into PLOPS-427_fix_act_composite_actions
  • fd3e08b Fix to make more complex composite actions work
  • 2d183a3 Let's validate the steps in the composite steps to fail on uses and run's without shell, like the real world
  • bc0012f Add support for composite actions
  • 2652416 Add workflow to test composite actions
  • 383b3b4 Log instead of panicing when output is mismatched

📊 Changes

11 files changed (+236 additions, -16 deletions)

View changed files

.github/actions/composite/action.yml (+22 -0)
.github/actions/composite/script.sh (+1 -0)
.github/workflows/test-composite.yml (+25 -0)
📝 pkg/model/action.go (+6 -1)
📝 pkg/model/workflow.go (+9 -0)
📝 pkg/runner/command.go (+15 -2)
📝 pkg/runner/run_context.go (+28 -13)
📝 pkg/runner/runner_test.go (+2 -0)
📝 pkg/runner/step_context.go (+62 -0)
pkg/runner/testdata/uses-composite/composite_action/action.yml (+48 -0)
pkg/runner/testdata/uses-composite/push.yml (+18 -0)

📄 Description

This is my first attempt at implementing #339. It supports most features I've tested (using this repo) including using inputs and outputs. One missing feature is using the Default value of an input that is not provided.

Before going too far I wanted to get feedback on how to implement some functionality. For convenience I put most of the logic into the runAction method, but I'm sure there are better ways to organize this code.

The first problem I ran into is that ${{ github.action_path }} was getting interpolated to an empty string. The quick fix was just to do strings.ReplaceAll on the Run field.

The next problem was that outputs from the action were not available due to them being associated with the wrong step. Considering this example, the action declares an output called random-number. But the value must be retrieved from the random-id output of the random-number-generator step.

The hacky way I solved this was to add OutputMappings to the RunContext which is used to map outputs from action steps to outputs of the action itself. The CurrentStep of the RunContext also needed to be updated to the ID of the step within the action to know whether the value needs to be mapped. When the action is run, all of the outputs are parsed into this map which is later used by setOutput.

Using the above example, the random number will be stored in rc.StepResults[foo].Outputs[random-number] instead of rc.StepResults[foo].Outputs[random-id].


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/nektos/act/pull/514 **Author:** [@mdelillo](https://github.com/mdelillo) **Created:** 2/2/2021 **Status:** ✅ Merged **Merged:** 4/2/2021 **Merged by:** [@cplee](https://github.com/cplee) **Base:** `master` ← **Head:** `composite-actions` --- ### 📝 Commits (10+) - [`31531c1`](https://github.com/nektos/act/commit/31531c1c36eaa95ee902adad28dac2a2a0d86e66) Add support for composite actions - [`2442b3e`](https://github.com/nektos/act/commit/2442b3e0adbd581e1272372d826b361b213e793b) Merge branch 'master' into composite-actions - [`a9900d4`](https://github.com/nektos/act/commit/a9900d41329661bca7f3171c2852c3e5419664e5) Fix to make more complex composite actions work - [`0a71ead`](https://github.com/nektos/act/commit/0a71ead4a81ecce5dfb7f770fa575346bc08d769) Merge pull request #1 from nektos/master - [`63c4fba`](https://github.com/nektos/act/commit/63c4fbab2b0cad6f151f5c6a690def32b6e12472) Merge branch 'master' into PLOPS-427_fix_act_composite_actions - [`fd3e08b`](https://github.com/nektos/act/commit/fd3e08be29f642a83e95b6ddfb011915887da709) Fix to make more complex composite actions work - [`2d183a3`](https://github.com/nektos/act/commit/2d183a33a07ff45bb7bccdea6762adebdd018405) Let's validate the steps in the composite steps to fail on uses and run's without shell, like the real world - [`bc0012f`](https://github.com/nektos/act/commit/bc0012fecaddfcd78ff7997701e4da1eb78d5d79) Add support for composite actions - [`2652416`](https://github.com/nektos/act/commit/2652416f146af86dd321fce5c137261b17a87796) Add workflow to test composite actions - [`383b3b4`](https://github.com/nektos/act/commit/383b3b41243600afa7cf36edaf448ec04668d8c8) Log instead of panicing when output is mismatched ### 📊 Changes **11 files changed** (+236 additions, -16 deletions) <details> <summary>View changed files</summary> ➕ `.github/actions/composite/action.yml` (+22 -0) ➕ `.github/actions/composite/script.sh` (+1 -0) ➕ `.github/workflows/test-composite.yml` (+25 -0) 📝 `pkg/model/action.go` (+6 -1) 📝 `pkg/model/workflow.go` (+9 -0) 📝 `pkg/runner/command.go` (+15 -2) 📝 `pkg/runner/run_context.go` (+28 -13) 📝 `pkg/runner/runner_test.go` (+2 -0) 📝 `pkg/runner/step_context.go` (+62 -0) ➕ `pkg/runner/testdata/uses-composite/composite_action/action.yml` (+48 -0) ➕ `pkg/runner/testdata/uses-composite/push.yml` (+18 -0) </details> ### 📄 Description This is my first attempt at implementing #339. It supports most features I've tested (using [this repo](https://github.com/mdelillo/act-test)) including using inputs and outputs. One missing feature is using the `Default` value of an input that is not provided. Before going too far I wanted to get feedback on how to implement some functionality. For convenience I put most of the logic into the `runAction` method, but I'm sure there are better ways to organize this code. The first problem I ran into is that `${{ github.action_path }}` was getting interpolated to an empty string. The quick fix was just to do `strings.ReplaceAll` on the `Run` field. The next problem was that outputs from the action were not available due to them being associated with the wrong step. Considering [this example](https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action), the action declares an output called `random-number`. But the value must be retrieved from the `random-id` output of the `random-number-generator` step. The hacky way I solved this was to add `OutputMappings` to the `RunContext` which is used to map outputs from action steps to outputs of the action itself. The `CurrentStep` of the `RunContext` also needed to be updated to the ID of the step within the action to know whether the value needs to be mapped. When the action is run, all of the outputs are parsed into this map which is later used by `setOutput`. Using the above example, the random number will be stored in `rc.StepResults[foo].Outputs[random-number]` instead of `rc.StepResults[foo].Outputs[random-id]`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-01 21:51:21 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#1480
No description provided.