3.1 KiB
ADR 361: Wrapper Action
Date: 2020-03-06
Status: Pending
Context
In addition to action's regular execution, action author may wants their action has a chance to participate in:
- Job initialize
My Action will collect machine resource usage (CPU/RAM/Disk) during a workflow job execution, we need to start perf recorder at the begin of the job. - Job cleanup
My Action will dirty local workspace or machine environment during execution, we need to cleanup these changes at the end of the job.
Ex:actions/checkout@v2will writegithub.tokeninto local.git/configduring execution, it has post job cleanup defined to undo the changes.
Decision
Add pre and post execution to action
Node Action Example:
name: 'My action with pre'
description: 'My action with pre'
runs:
using: 'node12'
pre: 'setup.js'
pre-if: 'success()' // Optional
main: 'index.js'
post: 'cleanup.js'
post-if: 'success()' // Optional
Container Action Example:
name: 'My action with pre'
description: 'My action with pre'
runs:
using: 'docker'
image: 'mycontainer:latest'
pre-entrypoint: 'setup.sh'
pre-if: 'success()' // Optional
entrypoint: 'entrypoint.sh'
post-entrypoint: 'cleanup.sh'
post-if: 'success()' // Optional
Both pre and post will has default pre-if/post-if sets to always().
Setting pre to always() will make sure no matter what condition evaluate result the main gets at runtime, the pre has always run already.
pre executes in order of how the steps are defined.
pre will always be added to job steps list during job setup.
Action referenced from local repository (
./my-action) won't getpresetup correctly since the repository haven't checkout during job initialize.
We can't use GitHub api to download the repository since there is a about 3 mins delay betweengit pushand the new commit available to download using GitHub api.
post will be pushed into a poststeps stack lazily when the action's pre or main execution passed if condition check and about to run, you can't have an action that only contains a post, we will pop and run each post after all pre and main finished.
Currently
postworks for both repository action (org/repo@v1) and local action (./my-action)
Valid action:
- only has
main - has
preandmain - has
mainandpost - has
pre,mainandpost
Invalid action:
- only has
pre - only has
post - has
preandpost
Potential downside of introducing pre:
- Extra magic wrt step order. Users should control the step order. Especially when we introduce templates.
- Eliminates the possibility to lazily download the action tarball, since
prealways run by default, we have to download the tarball to check whether action defined apre predoesn't work with local action, we suggested customer use local action for testing their action changes, ex CI for their action, to avoid delay betweengit pushand GitHub repo tarball download api.- Condition on the
precan't be controlled using dynamic step outputs.preexecutes too early.