Support pre and post steps in Composite Actions
See original GitHub issueDescribe the enhancement
Currently, three Action types are supported: Docker, JavaScript and Composite (see https://docs.github.com/en/actions/creating-actions/about-custom-actions#types-of-actions). However, features pre
, pref-if
, post
and post-if
are only is supported in JavaScript Actions only (see https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions). Therefore, users writing workflows/actions using some scripting language such as Python are forced to wrap the steps in JavaScript in order to register pre and post steps. See, for example, https://github.com/pyTooling/Actions/tree/main/with-post-step:
name: With post step
description: 'Generic JS Action to execute a main command and set a command in a post step.'
inputs:
main:
description: 'Main command/script.'
required: true
post:
description: 'Post command/script.'
required: true
key:
description: 'Name of the state variable used to detect the post step.'
required: false
default: POST
runs:
using: 'node12'
main: 'main.js'
post: 'main.js'
const { exec } = require('child_process');
function run(cmd) {
exec(cmd, (error, stdout, stderr) => {
if ( stdout.length != 0 ) { console.log(`${stdout}`); }
if ( stderr.length != 0 ) { console.error(`${stderr}`); }
if (error) {
process.exitCode = error.code;
console.error(`${error}`);
}
});
}
const key = process.env.INPUT_KEY.toUpperCase();
if ( process.env[`STATE_${key}`] != undefined ) { // Are we in the 'post' step?
run(process.env.INPUT_POST);
} else { // Otherwise, this is the main step
console.log(`::save-state name=${key}::true`);
run(process.env.INPUT_MAIN);
}
The complexity might be simplified if Python or Bash or PowerShell were supported similarly to JavaScript:
name: 'Login to container registries and set a post step'
runs:
using: 'python'
main: 'precmd.py'
post: 'postcmd.py'
Additional information
Alternatively, since regular steps support Python as a built-in shell already, the same capability might be achieved if Composite Actions supported fields pre
and post
as a complement to steps
. For instance:
name: 'Login to container registries and set a post step'
inputs:
precmd:
description: 'Pre command'
required: true
postcmd:
description: 'Pre command'
required: true
runs:
using: 'composite'
pre:
- shell: python
run: ${{ inputs.precmd }}
post:
- shell: python
run: ${{ inputs.postcmd }}
steps:
- ...
/cc @thboop, per https://github.com/actions/runner/issues/646#issuecomment-901336347
Issue Analytics
- State:
- Created 2 years ago
- Reactions:146
- Comments:24 (1 by maintainers)
Top GitHub Comments
Supporting
pre
andpost
in composite actions seems like a usable addition. We don’t have this on our roadmap at the moment, but I’ll add it to the list for future work. Thanks for the suggestion!Just writing in support - would have a lot of value in the context of “write secret --> $action --> remove secret” tasks