-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Describe 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 #646 (comment)