GitHub 操作:致命:无法读取 'https://github.com' 的用户名:设备未配置

GitHub Action: fatal: could not read Username for 'https://github.com': Device not configured

我试图在私有存储库上使用 Github 操作进行 git clone,但我不确定应该如何配置它以使用 SSH 连接到 GitHub。顺便说一句,它是一个 macOS 运行器。

此刻,actions/checkout 工作正常,但当我直接调用 git clone 时,会抛出此错误。

下面提供了 .yml 文件:

name: Release IOS
on: 
  push:
    branches:
      - github-action
jobs:
  build:
    name: Build IPA and upload to TestFlight
    runs-on: macos-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}
      - name: Check Github User
        run: |
          git --version
          git config user.name 'MyUsername'
          git config user.email 'MyEmail'
          git config user.name
          git config user.email
        env:
          NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 14.17.0
        env:
          NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
      - name: Set up SSH
        uses: pioug/la-cle@v1.1.0
        with:
          GH_SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
      - name: Try copy a private repo
        run: git clone https://github.com/MyUsername/MyRepo.git

正如@torek 指出的那样,错误是尝试从您的终端读取凭据,因为它用尽了其他选项(配置等)

由于您在上一步中设置了 ssh,因此您的意图似乎是使用 ssh,因此您应该将 url 更改为 ssh。

run: git clone git@github.com:MyUsername/MyRepo.git

请注意,还有其他选项。您仍然可以使用 https,但使用 git extraheader cli 选项和 PAT。对于常见情况,这实际上是 what we do in actions/checkout

https://www.codegrepper.com/code-examples/shell/How+do+I+clone+a+git+repository+with+extraHeader

为了完整起见,来自该网站:

PAT="mypat123"
REPO_URL=https://myorg@dev.azure.com/myorg/myrepo/_git/myrepo"
AUTH=$(echo -n ":$PAT" | openssl base64 | tr -d '\n')
git -c http.$REPO_URL.extraheader="Authorization: Basic $AUTH" clone $REPO_URL --no-checkout --branch master

基本上你让它通过你的 PAT 作为 base64 编码header。