How do I run a Bash Script located in public folder using GitHub actions?
April 11, 2024 2024-04-11 7:55How do I run a Bash Script located in public folder using GitHub actions?
How do I run a Bash Script located in public folder using GitHub actions?
To run a Bash script located in the public folder of a GitHub repository using GitHub Actions, you need to create a workflow file that specifies the steps to execute the script. Additionally, you may need to ensure that the script has executable permissions set.
Lets see how to do this along with an example:
1.Set up the Bash script:
Ensure that your Bash script is in the public folder of your GitHub repository. You’ll also need to set the executable permission for the script. You can do this locally or through GitHub.
Locally:
chmod +x /path/to/script.sh
In GitHub:
git update-index --chmod=+x path/to/script.sh
2.Create a GitHub Actions workflow file:
Create a YAML file (e.g., workflow.yml) in the .github/workflows directory of your repository. This file defines the workflow that GitHub Actions will follow.
name: Run Bash Script
on:
push:
branches:
- main # Change this to your branch name
jobs:
run-script:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Run Bash script
run: bash public/script.sh
This workflow will run whenever there’s a push to the specified branch (main in this example). It checks out the repository and then runs the Bash script located in the public folder.
Example:
Suppose your Bash script is named myscript.sh and it’s located in the public folder of your repository.
Your directory structure might look like this:
your-repo/
├── .github/
│ └── workflows/
│ └── workflow.yml
└── public/
└── myscript.sh
And your workflow.yml file content would be:
name: Run Bash Script
on:
push:
branches:
- main
jobs:
run-script:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Run Bash script
run: bash public/myscript.sh
Notes:
Ensure that the path to your Bash script in the workflow file matches the actual path in your repository.
Make sure the script’s permissions are set correctly to allow execution.
Customize the workflow file according to your repository structure and requirements.
Ensure your workflow file is valid YAML syntax.
Once you push this workflow file to your repository, GitHub Actions will automatically execute the Bash script whenever there’s a push to the specified branch.