Flutter:在具有私有依赖项的 github 操作中运行 flutter pub get

M20*_*M20 2 continuous-integration github continuous-deployment flutter github-actions

我正在使用在 Github 上私有托管并具有 ssh 访问权限的插件。在 Github 操作中运行时,flutter pub get此命令会失败。我按照使用部署密钥的教程进行操作,并尝试了以下操作:

jobs:
    build:
        runs-on: ubuntu-18.04
        steps:
            -   uses: actions/checkout@v1

            -   name: Setup SSH Keys and known_hosts
                env:
                    SSH_AUTH_SOCK: /tmp/ssh_agent.sock
                run: |
                    mkdir -p ~/.ssh
                    ssh-keyscan github.com >> ~/.ssh/known_hosts
                    ssh-agent -a $SSH_AUTH_SOCK > /dev/null
                    ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"

            -   name: Some task that fetches dependencies
                env:
                    SSH_AUTH_SOCK: /tmp/ssh_agent.sock
                run: flutter pub get
Run Code Online (Sandbox Code Playgroud)

还尝试过:

  - uses: webfactory/ssh-agent@v0.4.0
    with:
      ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
  - name: Fetch flutter dependencies
    run: flutter pub get
Run Code Online (Sandbox Code Playgroud)

但命令仍然失败。我做错了什么,还有其他方法可以让这个命令获取私钥吗?

小智 6

您可以使用此操作添加 ssh 密钥。

https://github.com/marketplace/actions/install-ssh-key

将私钥和已知主机插入存储库的机密中。

注意:OPENSSH 格式(密钥以 -----BEGIN OPENSSH PRIVATE KEY----- 开头)可能因虚拟机上的 OpenSSH 版本而不起作用。请改用 PEM 格式(以 -----BEGIN RSA PRIVATE KEY----- 开头)。为了将内联密钥转换为 PEM 格式,只需使用 ssh-keygen -p -m PEM -f ~/.ssh/id_rsa。

您可以使用以下方式获取已知主机:

ssh-keyscan github.com
Run Code Online (Sandbox Code Playgroud)

之后在您的工作流程中添加 ssh:

- uses: shimataro/ssh-key-action@v2
    with:
      key: ${{ secrets.SSH }}
      name: id_rsa
      known_hosts: ${{ secrets.KNOWN_HOSTS }}
Run Code Online (Sandbox Code Playgroud)

我希望这可以帮助你