Ever encountered this frustratingly vague "Permission denied" error when trying to run a bash script in an GitHub action workflow? 😡
"Permission denied" means that your script file does not have the "execute" permission set. On Mac and Linux you can use the
chmod command to make script files executable, but Windows does not support this.
Luckily, Git offers a command that works with Windows. Run:
git update-index --chmod=+x your_script.sh
locally to make the bash script executable. Once you commit and push the change to your GitHub repository the script will be allowed to run in your GitHub action. 🎉
NB: you will need to run this command then commit and push the change to GitHub for any bash script you create or rename on a Windows machine in order for it to run in a GitHub action.
That's great Aileen, but how do I even add a script to a GitHub action?
Here is an example action which runs a
your_script.sh script on commit to the
main branch of your repository.
# This is a basic workflow to help you get started with Actions
name: Run a shell script
# Controls when the workflow will run
# Triggers the workflow on push but only for the main branch
branches: [ main ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
# This workflow contains a single job called "build"
# The type of runner that the job will run on
# Steps represent a sequence of tasks that will be executed as part of the job
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a single command using the runners shell
- name: Run shell script
If you're new to GitHub actions, GitHub has an excellent quickstart guide.