◐ Shell
clean mode source ↗

feat: add working-directory input to change script execution directory by mturac · Pull Request #720 · actions/github-script

Hey! 👋

This PR adds a working-directory input to github-script, similar to how run steps support working-directory in GitHub Actions.

The Problem

Before this change, if you wanted your script to run in a different directory, you had to manually call process.chdir() in your script. This is:

  • Inconvenient
  • Error-prone
  • Inconsistent with how other GitHub Actions work

The Solution

Now you can simply specify the working directory:

- uses: actions/github-script@v9
  with:
    working-directory: ./my-project
    script: |
      const fs = require('fs');
      console.log(fs.readdirSync('.'));

What Changed

  • Added working-directory input to action.yml
  • Added process.chdir() call in main.ts before script execution
  • Updated tests to cover the new feature

Testing

All existing tests pass, and new tests were added for the working-directory feature.

Closes #426