英文:
I am trying to deploy my Nest JS app to a digitalocean droplet using Github Actions. The job I run keeps failing at the "git pull" command
问题
我的GitHub操作任务在“git pull”脚本处不断失败,出现以下错误:
err: fatal: could not read Username for 'https://github.com': No such device or address.
以下是我的yaml文件内容:
name: 部署到DigitalOcean
on:
# 在推送到develop存储库分支时运行
push:
branches: [develop]
# 在拉取请求期间运行
pull_request:
branches: [develop]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.GH_SSH_KEY }}
fetch-depth: 0
ref: develop
- name: 设置Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: 安装依赖项
run: yarn install
- name: 构建应用程序
run: yarn build
- name: 设置Git
env:
GIT_AUTH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
git config --global user.email "${{ secrets.GH_USER_EMAIL }}"
git config --global user.name "${{ secrets.GH_USERNAME }}"
- name: 部署应用程序到DigitalOcean
uses: appleboy/ssh-action@v0.1.8
with:
host: ${{ secrets.STAGING_SSH_HOST }}
username: ${{ secrets.STAGING_SSH_USERNAME }}
key: ${{ secrets.STAGING_SSH_KEY }}
script: |
cd my-app
git switch develop
git pull
echo "${{ secrets.STAGING_ENV_FILE }}" > .env
npm run reload
我不确定如何解决这个问题,已经花了好几个小时了。
我尝试在"Checkout code"步骤中添加存储库的SSH URL,但也没有起作用:
- name: 检出代码
uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.GH_SSH_KEY }}
fetch-depth: 0
repository: git@github.com:My-CoPilot/my_copilot_backend.git
ref: develop
但那也没有起作用
英文:
My GitbHub action job keeps failing at the "git pull" script with the following error:
err: fatal: could not read Username for 'https://github.com': No such device or address.
Here's what my yaml file looks like
name: Deploy to DigitalOcean
on:
# run it on push to the develop repository branch
push:
branches: [develop]
# run it during pull request
pull_request:
branches: [develop]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.GH_SSH_KEY }}
fetch-depth: 0
ref: develop
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: yarn install
- name: Build application
run: yarn build
- name: Set up Git
env:
GIT_AUTH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
git config --global user.email "${{ secrets.GH_USER_EMAIL }}"
git config --global user.name "${{ secrets.GH_USERNAME }}"
- name: Deploy application to DigitalOcean
uses: appleboy/ssh-action@v0.1.8
with:
host: ${{ secrets.STAGING_SSH_HOST }}
username: ${{ secrets.STAGING_SSH_USERNAME }}
key: ${{ secrets.STAGING_SSH_KEY }}
script: |
cd my-app
git switch develop
git pull
echo "${{ secrets.STAGING_ENV_FILE }}" > .env
npm run reload
I am not sure how to solve this, been at this for hours now.
I tried adding the ssh url for the repository to Checkout code step
- name: Checkout code
uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.GH_SSH_KEY }}
fetch-depth: 0
repository: git@github.com:My-CoPilot/my_copilot_backend.git
ref: develop
But that didn't work either
答案1
得分: 2
感谢VonC提供的答案。
原来当我登录到我的Droplet控制台并运行了"git pull"命令时,它提示我进行GitHub用户身份验证。在完成验证后,随后运行"git pull"时就不再需要身份验证了。
所以这就是我需要做的一切。
当我重新运行失败的任务时,这次运行"git pull"命令没有抛出错误,而是成功运行。
英文:
Thanks VonC for your answer.
It turned out that when I logged into my droplet console and ran the "git pull" command, it prompted me to authenticate the github user. After doing that, running "git pull" subsequently went without a hitch or need for authentication.
So that's all I had to do really.
When I re-ran the failed job, the "git pull" command this time around did not throw an error, but ran successfully.
答案2
得分: 0
The 'could not read Username for 'https://github.com':
means:
- 这意味着无法读取用户名以用于 'https://github.com' 的远程服务器:
- 远程服务器,您已经通过 SSH 连接到,正在使用 HTTPS URL,因此任何 SSH 密钥都将不相关且不会被使用。
- 远程服务器没有您的凭据(GitHub 用户帐户/令牌)。
In other words:
- 换句话说:
- 您添加的
actions/checkout@v2
(使用 SSH URL)将在 GitHub runner 上执行,这是 Microsoft/GitHub 一侧的 Azure 服务器。 appleboy/ssh-action@v0.1.8
将连接到远程服务器(不再是 GitHub runner),并在那里执行git pull
。
The local repository in '~remoteUser/my-app
' on that remote server is configured to use HTTPS.
该远程服务器上的 'remoteUser/my-app' 目录中的本地存储库已配置为使用 HTTPS。
You could at least add in your script:
commands:
您至少可以在您的 'script:' 命令中添加:
英文:
The 'could not read Username for 'https://github.com':
means:
- The remote server where you have ssh'd to is using an HTTPS URL: any SSH key will be irrelevant, and not used at all.
- The remote server does not have your credentials (GitHub user account/token)
In other words:
- the
actions/checkout@v2
(using an SSH URL) that you have added is executed on a GitHub runner, a Azure server on Microsoft/GitHub side - the
appleboy/ssh-action@v0.1.8
will connect to a remote server (no longer a GitHub runner) and execute yourgit pull
there.
The local repository in '~remoteUser/my-app
' on that remote server is configured to use HTTPS.
You could at least add in your script:
commands:
git remote set-url origin git@github.com:My-CoPilot/my_copilot_backend.git
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论