今天,当我运行github操作时,显示了这样的错误:
Error: fatal: --local can only be used inside a git repository
这是关于操作日志的完整日志:
Run actions/checkout@v3
Syncing repository: RedDwarfTech/cv_render
Getting Git version info
Temporarily overriding HOME='/home/runner/work/_temp/2abd7da7-7754-4217-b5db-2984399b003e' 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/cv_render/cv_render
/usr/bin/git config --local --get remote.origin.url
Error: fatal: --local can only be used inside a git repository
Deleting the contents of '/home/runner/work/cv_render/cv_render'
Initializing the repository
Disabling automatic garbage collection
Setting up auth
Fetching the repository
Determining the checkout info
Checking out the ref
/usr/bin/git log -1 --format='%H'
'28106b95ce29effd8f28340d7e6cbba265a04e71'
这是我的github动作定义:
- name: Checkout source
uses: actions/checkout@v3
with:
lfs: false
为什么会出现这个问题呢?我该怎么做才能解决这个问题?这是完整的github动作看起来像:
name: cv-render-k8s-pro
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Cache
uses: actions/cache@v3
with:
key: lfs-cache
path: .git/lfs
restore-keys: |
- lfs-cache
- name: Checkout source
uses: actions/checkout@v3
with:
lfs: false
- name: Install git-lfs
run: |
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
- name: Set Git LFS default remote URL
run: |
git remote set-url origin https://${{ secrets.LFS_USER_NAME }}:${{ secrets.LFS_PASSWORD }}@codeup.aliyun.com/6299c42d487c500c27f5f963/cv_render.git
git config --global credential.helper store
git config --global user.email "[email protected]"
git config --global user.name "jiangchaoquan123456"
- name: Initialize Git LFS
run: |
git lfs install
- name: Pull LFS files
run: |
git lfs pull
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}
username: ${{ secrets.ALIYUN_DOCKER_REPO_USER_NAME }}
password: ${{ secrets.ALIYUN_DOCKER_REPO_USER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
push: true
tags: ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}/reddwarf-pro/cv-render:${{ github.sha }}
- name: deploy to cluster
uses: steebchen/[email protected]
with:
config: ${{ secrets.KUBE_CONFIG_DATA }}
command: set image --record deployment/cv-render-service cv-render-service=${{ secrets.ALI_DOCKER_HUB_REGISTRY }}/reddwarf-pro/cv-render:${{ github.sha }} -n reddwarf-pro
- name: verify deployment
uses: steebchen/[email protected]
with:
config: ${{ secrets.KUBE_CONFIG_DATA }}
version: v1.21.0
command: rollout status deployment/cv-render-service -n reddwarf-pro
2条答案
按热度按时间pxyaymoc1#
你没有在大多数默认设置中使用
actions/checkout
任务。看起来你试图使用来自不同存储提供商的LFS存储,而不是GitHub。😉如果
actions/cache
成功,将在runners工作目录中创建一个.git/lfs
文件夹。.git
文件夹不是一个正确的git仓库,它缺少各种各样的东西,但它会触发运行器中的许多不同例程,因为它需要检查仓库是否可用于此工作流运行或需要清理。代码失败。我猜您可以通过将
actions/checkout
步骤放在action/cache
步骤之前来解决这个问题。这样就没有.git
文件夹,actions/checkout
步骤将在托管的runner上正常运行。然后,actions/cache
步骤可以恢复.git
文件夹中的LFS缓存,之后,您可以更改LFS配置以在需要时同步其余文件。knsnq2tg2#
这个错误告诉你你想在一个不是git仓库的本地目录中做一些事情。您需要找出执行此命令的目录。可能性:
cd /the/path/to/the/correct/directory
的内容,或者传递要执行git命令的位置,如git -C /the/path/to/the/correct/directory <somecommand>
git init
来初始化,或者查看其他步骤,看看它们是否执行了类似删除.git
文件夹的操作你的问题的症状是
如果没有在正确的位置执行或在指定正确的位置时执行,则会以您提到的方式出错,例如