Skip to content

feat: add working-directory input to change script execution directory#720

Open
mturac wants to merge 2 commits into
actions:mainfrom
mturac:feature/working-directory-input
Open

feat: add working-directory input to change script execution directory#720
mturac wants to merge 2 commits into
actions:mainfrom
mturac:feature/working-directory-input

Conversation

@mturac
Copy link
Copy Markdown

@mturac mturac commented May 11, 2026

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

- Add working-directory input to action.yml
- Implement process.chdir() in main.ts before script execution
- Users can now specify working directory without modifying scripts

Closes actions#426
@mturac mturac requested a review from a team as a code owner May 11, 2026 14:38
- Add src/working-directory.ts with validateWorkingDirectory()
- Add __test__/working-directory.test.ts with 4 test cases
- Update main.ts to use validation function
- Throw clear error for non-existent or non-directory paths
- Rebuild dist/index.js

Addresses review feedback on actions#426
@mturac mturac force-pushed the feature/working-directory-input branch from 2cc5e9b to 7b9b30a Compare May 12, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow changing the directory where the script runs

1 participant