Github 操作:运行 一个 Bash 脚本

Github Actions: Running a Bash Script

我正在尝试 运行 来自 Github 操作的脚本,它一直说:找不到文件或目录。

这是 github 操作:

name: Build And Deploy
on:
  push:
#     branches:
#       - master`

jobs:
  generate-build-number-deploy:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v3
      # https://github.com/marketplace/actions/build-number-generator
      - name: Generate build number
        uses: einaregilsson/build-number@v3
        with:
          token: ${{secrets.github_token}}

      - name: Print new build number
        run: echo "Build number is $BUILD_NUMBER"
  
      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-2

      - name: Print GITHUB_WORKSPACE
        run: echo ${GITHUB_WORKSPACE}

      - name: Build Docker
        run: |
             chmod +x "${GITHUB_WORKSPACE}/../docker/build-docker.sh"
             ${GITHUB_WORKSPACE}/../docker/build-docker.sh
      - name: Push Docker
        run: |
             chmod +x "${GITHUB_WORKSPACE}/../docker/push-docker.sh"
             ${GITHUB_WORKSPACE}/../docker/push-docker.sh

出于某种原因,GITHUB_WORKSPACE 有奇怪的路径,这就是为什么我必须做 ${GITHUB_WORKSPACE}/../docker/push-docker.sh,在路径中添加 ../。有没有办法列出文件或获取当前工作目录以查看文件实际所在的位置?

我试过 echo ${cwd}echo ${pwd} 但没有任何反应。

我为 运行ning bash 脚本引用了以下 link: https://github.community/t/running-a-bash-script/141584

最佳做法是 运行 使用 working-directory: 命令执行这些步骤,使它们在特定目录中执行 - 相对于您的根文件夹。

问题是目录结构。一旦我列出目录中的文件并找到文件的路径,操作 运行 成功。这是最终的 yml 脚本。

on:
  push:
     branches:
       - master

jobs:
  generate-build-number-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      # required for accessing files in repository.

      # https://github.com/marketplace/actions/build-number-generator
      - name: Generate build number
        uses: einaregilsson/build-number@v3
        with:
          token: ${{secrets.github_token}}

      - name: Print new build number
        run: echo "Build number is $BUILD_NUMBER"

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-2

      - name: Build Docker
        run: ${PWD}/docker/build-docker
      - name: Push Docker
        run: ${PWD}/docker/push-docker