How to Run a Shell Script From the Repo in GitHub Actions
Check out the repo, ensure the script is executable, then call it from a run step so the logic stays in Git, not the YAML.
Add actions/checkout so the file is present, mark it executable (or invoke it via bash script.sh), then run it. Keeping logic in a script makes it testable and reusable outside CI.
Steps
- Add
actions/checkout@v4so the script exists on disk. - Commit the script with the executable bit, or run it with
bash path/to/script.sh. - Invoke it from a
run:step.
Workflow
.github/workflows/ci.yml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: chmod +x scripts/build.sh
- run: ./scripts/build.shGotchas
- Without
checkout, the script is not on the runner and you get "No such file or directory". - If the executable bit is not committed, call it as
bash scripts/build.shinstead of./scripts/build.sh.
Related guides
How to Run a Multi-Line Inline Script in GitHub ActionsWrite a multi-line inline script in a GitHub Actions run step with a YAML block scalar, so several shell comm…
How to Run a Script in a Container in GitHub ActionsRun a GitHub Actions script inside a Docker container with the job container key, so it executes against a pi…