Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 4, 2022 06:40 pm GMT

GitHub Actions: Fixing the 'Permission Denied' error for shell scripts

Ever encountered this frustratingly vague "Permission denied" error when trying to run a bash script in an GitHub action workflow?

Screenshot from GitHub's 'Actions' tab showing a build error: 'Permission denied' when trying to run a shell script

"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.

How to fix it

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.

How to run a bash script 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.

# https://gist.github.com/aileen-r/f74e680fb47ebc8b29a9f1cc452a5da9# This is a basic workflow to help you get started with Actionsname: Run a shell script# Controls when the workflow will runon:  # Triggers the workflow on push but only for the main branch  push:    branches: [ main ]# A workflow run is made up of one or more jobs that can run sequentially or in paralleljobs:  # This workflow contains a single job called "build"  build:    # The type of runner that the job will run on    runs-on: ubuntu-latest    # Steps represent a sequence of tasks that will be executed as part of the job    steps:      # 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        run: ./your_script.sh

If you're new to GitHub actions, GitHub has an excellent quickstart guide.


Original Link: https://dev.to/aileenr/github-actions-fixing-the-permission-denied-error-for-shell-scripts-4gbl

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To