Running a bash script

Hi there,
What is the simplest way to create a workflow that runs a bash script?
I understand I can create a separate action which runs the script and use it in my workflow. I have done that for action shared among multiple repositories.

However, now I need to run a custom script in a single repo and, I feel a separate action is too much.

I’d like to be able to do run a bash script saved at ROOT/.github/script.sh but I can’t figure out how to specify the path in the run step of the workflow below.

name: run-script
on: push

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: script
run: PATH/script.sh
shell: bash
with:
password: ${{ secrets.ACCESS_TOKEN }}

Thanks.

With that setup the path to the script is relative to the root of your repository, so if your script is .github/script.sh that’s all that’s needed in the run step. Remember that the file must be marked as executable, or you need to explicitly call bash with the script as parameter.

To be more explicit, you can write ./.github/script.sh.

If you want to know the full path where the working copy resides in the runner, then you can do run: pwd which will print the working directory.

The absolute path should be /home/runner/work/{repo-name}/{repo-name}/.github/script.sh, so this should also work:

- run: |
    # make file runnable, might not be necessary
    chmod +x "${GITHUB_WORKSPACE}/.github/script.sh"

    # run script
    "${GITHUB_WORKSPACE}/.github/script.sh"
    # or
    "${{ format('{0}/.github/script.sh', github.workspace) }}"
1 Like

Thanks for the reply.

1 Like

Thanks for your help.