question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support pre and post steps in Composite Actions

See original GitHub issue

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 https://github.com/actions/runner/issues/646#issuecomment-901336347

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:146
  • Comments:24 (1 by maintainers)

github_iconTop GitHub Comments

52reactions
ethomsoncommented, Dec 17, 2021

Supporting pre and post 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!

26reactions
noahsbwilliamscommented, May 30, 2022

Just writing in support - would have a lot of value in the context of “write secret --> $action --> remove secret” tasks

Read more comments on GitHub >

github_iconTop Results From Across the Web

GitHub Composite Actions - STOP wasting your time and ...
A composite run steps action allows you to combine multiple workflow run steps within one action. For example, you can use this feature...
Read more >
GitHub Composite Actions - STOP wasting your ... - DevPress
A composite run steps action allows you to combine multiple workflow run steps within one action. For example, you can use this feature...
Read more >
Creating a GitHub Composite Action
The first step is to create a new public repo – as each reusable actions should be in their own repo. It is...
Read more >
GitHub Actions - Composite Run Steps FIRST LOOK - YouTube
Post in comments section of this video! SUBSCRIBE to CoderDave here: https://www.youtube.com/CoderDave?sub_confirmation=1
Read more >
GitHub Composite Actions are fast way to templatize ...
Want to templatize some steps in your workflows? Check out GitHub composite Action run steps!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found