使用另一个私有存储库中的 Github Actions 在第二步中失败

问题描述 投票:0回答:1

我有 2 个存储库。一种具有 API 代码,另一种具有基础设施代码。基础代码还有一些我想重复使用的 GH 操作。 我创建了一个个人令牌,用于访问存储库。我也提供了访问权限。

这些来自“设置”>“操作”>“常规”

Allow all actions and reusable workflows
Accessible from repositories owned by the user 'org'

这是 API 中的工作流程

name: Deploy to AWS ECS
on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Checkout Infra Repository
        uses: actions/checkout@v4
        with:
          repository: myapp/myapp-infra
          token: ${{ secrets.GH_TOKEN }}
          path: myapp-infra 
          ref: main 

      - name: List Infra Actions1
        run: ls -la myapp-infra/.github/actions/ #This lists all actions

      - name: Show Current Directory
        run: pwd # /home/runner/work/myapp-api/myapp-api

      - name: Setup Node.js
        uses: ./myapp-infra/.github/actions/setup-node #runs fine

      - name: Show Current Directory
        run: pwd # /home/runner/work/myapp-api/myapp-api

      - name: List Infra Actions2
        run: ls -la myapp-infra/.github/actions/ # fails

      - name: Install NPM Dependencies
        uses: ./myapp-infra/.github/actions/npm-install #fails

操作

setup-node
运行良好,而
npm-install
失败。

Error: Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/myapp-api/myapp-api/myapp-infra/.github/actions/npm-install'. Did you forget to run actions/checkout before running your local action?

基础存储库文件结构。 The infra repo file structure

如有任何帮助,我们将不胜感激。如果需要,可以提供更多信息。 从我最初的调查中,我发现在运行该存储库中的任何操作后,由结帐创建的

myapp-infra
会被删除。我最初认为某个特定操作是罪魁祸首,但我已经排除了这一可能性,因为执行任何操作后,存储库文件夹都会丢失。但执行前后的目录保持不变。 所以百万美元的问题是:

  1. 每次操作后我们都应该结账吗?
  2. 我们可以签出到特定路径,这样它们就不会被删除吗?
  3. 除了结账还有其他方式吗? (这两个存储库都是同一组织下的私有存储库。)

以下是 GH 操作的一些日志。

Download action repository 'actions/setup-node@v4' (SHA:60edb5dd545a775178f52524783378180af0d1f8)
Run ./myapp-infra/.github/actions/setup-node
Run actions/checkout@v4
Syncing repository: myapp/myapp-api
Getting Git version info
Temporarily overriding HOME='/home/runner/work/_temp/3790bc2a-42db-4f29-81ac-acaafa9303b0' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
/usr/bin/git config --global --add safe.directory /home/runner/work/myapp-api/myapp-api
/usr/bin/git config --local --get remote.origin.url
https://github.com/myapp/myapp-api
Removing previously created refs, to avoid conflicts
/usr/bin/git submodule status
Cleaning the repository
Disabling automatic garbage collection
Setting up auth
Fetching the repository
Determining the checkout info
/usr/bin/git sparse-checkout disable
/usr/bin/git config --local --unset-all extensions.worktreeConfig
Checking out the ref
/usr/bin/git log -1 --format='%H'
'e95d322d898d11920cdeb2e384cb323f567deac7'
Run NODE_VERSION=$(cat .nvmrc)
Run actions/setup-node@v4
Found in cache @ /opt/hostedtoolcache/node/20.12.2/x64
Environment details
  node: v20.12.2
  npm: 10.5.0
  yarn: 1.22.22
Error: Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/myapp-api/myapp-api/myapp-infra/.github/actions/npm-install'. Did you forget to run actions/checkout before running your local action?
github github-actions
1个回答
0
投票

正如您添加到问题的工作流程日志中所共享的,您的

./myapp-infra/.github/actions/setup-node
本地操作正在内部使用
actions/checkout

运行 actions/checkout@v4

同步存储库:myapp/myapp-api

此操作将覆盖之前使用

myapp/myapp-infra
在工作流程中设置的
actions/checkout@v4
文件夹。

在这种情况下,您需要调整工作流程或本地操作以符合您的预期行为。

我建议您从

actions/checkout
本地操作中删除此
setup-node
用法,因为您在您的上下文中似乎不需要它。

© www.soinside.com 2019 - 2024. All rights reserved.