Search code examples
githubgithub-actions

access script stored in .github directory in github action


I have a my_script.sh file in .github/my_script.sh in my repo.

Below is my YAML file:

jobs:
    main:
      runs-on: ubuntu-latest
      steps:
        - uses: actions/checkout@v3
          with:
            path: master
        - name: Set sync script in env
          run: |
            myscript=$(cat .github/my_script.sh) 
            echo "::set-env name=MY_SCRIPT::$myscript"

But I got this error:

cat: .github/my_script.sh: No such file

Any clue why?


Solution

  • According to https://github.com/actions/checkout, path is the "relative path under $GITHUB_WORKSPACE to place the repository". Note that does not change the working directory.

    This means that using path: master will put your repo in a folder named master. I suspect that you meant to check out the master branch instead. Checkout will automatically checkout the branch the workflow was ran on so most of the time, specifying it specifically is not required.

    You either want to remove the path argument or change your code to use the correct path: myscript=$(cat master/.github/my_script.sh)