Github Actions 失败

23

昨天之前Github Actions在我的存储库中能够正常工作。我没有在.github/workflows/dev.yml文件或DockerFile中进行任何更改。

但是,在最近的推送中,我的Github Actions失败并显示以下错误:

Setup, Build, Publish, and Deploy

Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under
'/home/runner/work/_actions/GoogleCloudPlatform/github-actions/master/setup-gcloud'.
Did you forget to run actions/checkout before running your local
action?

请问如何解决这个问题?

这是我使用的示例 .yml 文件。

name: Release to Development

on:
  push:
    branches:
      - 'master'
jobs:
  setup-build-publish-deploy:
    name: Setup, Build, Publish, and Deploy
    runs-on: ubuntu-latest
    steps:

    - name: Checkout
      uses: actions/checkout@v2

    # Setup gcloud CLI
    - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
      with:
        version: '270.0.0'
        service_account_email: ${{ secrets.GCLOUD_EMAIL_DEV }}
        service_account_key: ${{ secrets.GCLOUD_AUTH_DEV }}

    # Configure docker to use the gcloud command-line tool as a credential helper
    - run: |
        # Set up docker to authenticate
        # via gcloud command-line tool.
        gcloud auth configure-docker

    # Build the Docker image
    - name: Build
      run: |
        docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE":"$GITHUB_SHA" \
          --build-arg GITHUB_SHA="$GITHUB_SHA" \
          --build-arg GITHUB_REF="$GITHUB_REF" .

    # Push the Docker image to Google Container Registry
    - name: Publish
      run: |
        docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:$GITHUB_SHA

    # Set up kustomize
    - name: Set up Kustomize
      run: |
        curl -o kustomize --location https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
        chmod u+x ./kustomize

    # Deploy the Docker image to the GKE cluster
    - name: Deploy
      run: |

这是错误片段的代码。 enter image description here

似乎每个人都发生了这种情况。 - STEEL
4个回答

29

我通过将uses的值更改为

  • uses: google-github-actions/setup-gcloud@v0
来解决了这个问题。

不错!我刚刚碰到这个问题。似乎文档已经过时了:https://cloud.google.com/community/tutorials/cicd-cloud-run-github-actions - GoForth
2
我会编辑这个答案,在末尾加上“@v0”,因为Google将在今年某个时候将他们的基本分支重命名为“main”,所有使用“@master”的工作流程都会出现问题。来源:https://github.com/google-github-actions/setup-gcloud#-notice - mmlo95

8

我曾遇到类似错误。当我试图在步骤级别调用本地Workflow时,似乎GitHub Actions只支持从jobs级别调用本地workflow,我无法从内部的steps层级调用。

name: Build and Deploy

on:
  push:
    branches: [dev]

permissions:
  id-token: write
  contents: read

jobs:
  build-and-publish:
    steps:

    - name: Checkout
      uses: actions/checkout@v2

    - name: test local call from steps # this do not work
      if: github.ref_name == 'dev'       
      uses: ./.github/workflows/deploy.yml # this is from steps level
        with:
          devops-bucket: bucket-name
          role: iam role for the job

  dev: # this worked well
    if: github.ref_name == 'dev'
    uses: ./.github/workflows/deploy.yml # this is jobs level
    with:
      devops-bucket: bucket-name
      role: iam role for the job

1
此回答与调用不同于操作的可重用工作流相关,因此属于题外话。 - jschmitter
6
这个答案很有用。虽然我也遇到了类似的问题,但看到这个答案让我明白了可重用工作流和操作之间的区别,并告诉我调用可重用工作流的正确方式(作为自己的工作,而不是像调用操作一样)。 - George Griffin

6

3

针对任何想知道为什么此操作不再起作用的人,请查看此通知:https://github.com/google-github-actions/setup-gcloud#-notice

现在每个操作都有自己的仓库,因此您必须更改在yaml文件中引用Google Cloud Platform操作的方式:

steps:
 - id: gcloud
-  uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
+  uses: google-github-actions/setup-gcloud@master

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接