This article explains how to execute shell scripts in GitHub Actions workflows while maintaining a clean and maintainable setup.
Running a series of shell commands directly in a workflow can quickly become messy. By placing your commands in a standalone script file and invoking it in one step, you maintain a clean, maintainable workflow.
A minimal workflow that invokes the script directly will fail because the checked-out file isn’t executable by default:
Copy
Ask AI
name: Run ASCII Scripton: push: branches: [ main ]jobs: ascii_job: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 - name: List Files Before Run run: ls -ltra - name: Run Script run: ./ascii-script.sh
When this runs, you’ll see:
Copy
Ask AI
/home/runner/work/_temp/abcdef.sh: line 1: ./ascii-script.sh: Permission deniedError: Process completed with exit code 126
Without executable permissions, the runner cannot invoke your script. Always ensure your scripts are marked as executable before running.
Update the workflow to add a chmod +x step before executing:
Copy
Ask AI
name: Run ASCII Scripton: push: branches: [ main ]jobs: ascii_job: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 - name: List Files Before Run run: ls -ltra - name: Make Script Executable and Run run: | chmod +x ascii-script.sh ./ascii-script.sh
Commit and push these changes to trigger a new run.