我正在尝试学习部署在GitHub行动。在GitHub存储库中的.github/workflows/demo.yml
文件中,我通过从https://github.com/marketplace/actions/deploy-to-heroku:
Deploy-to-Heroku:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# install Heroku: https://github.com/marketplace/actions/deploy-to-heroku
- uses: akhileshns/heroku-deploy@v3.12.12 # This is the action
with:
# first in Heroku online account: account -> Account Settings -> API Key. copy it.
# then in your project's repository on GitHub, Settings -> Secrets -> actions -> New repository secret: Then enter HEROKU_API_KEY as the name and paste the copied API Key as the value.
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "test-github-action-123abc" #Must be unique in Heroku. letters must be lower case, not upper case. c.f. error output
heroku_email: "xxxx@xxxx.com"
我想知道为什么部署失败:
Run akhileshns/heroku-deploy@v3.12.12
From https://github.com/xxx/testGithubAction
* [new branch] xxx-patch-1 -> origin/xxx-patch-1
Created and wrote to ~/.netrc
Successfully logged into heroku
› Warning: Our terms of service have changed:
Added git remote heroku
› https://dashboard.heroku.com/terms-of-service
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: !Push rejected to test-github-action-123abc.
remote:
To https://git.heroku.com/test-github-action-123abc.git
! [remote rejected] HEAD -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/test-github-action-123abc.git'
Unable to push branch because the branch is behind the deployed branch. Using --force to deploy branch.
(If you want to avoid this, set dontuseforce to 1 in with: of .github/workflows/action.yml.
Specifically, the error was: Error: Command failed: git push heroku HEAD:refs/heads/main
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: !Push rejected to test-github-action-123abc.
remote:
To https://git.heroku.com/test-github-action-123abc.git
! [remote rejected] HEAD -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/test-github-action-123abc.git'
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: 235b1971a13f659e7a3572c11caf9a1e4c2abce4
remote: !
remote: ! We have detected that you have triggered a build from source code with version 235b1971a13f659e7a3572c11caf9a1e4c2abce4
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: !Push rejected to test-github-action-123abc.
remote:
To https://git.heroku.com/test-github-action-123abc.git
! [remote rejected] HEAD -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/test-github-action-123abc.git'
Error: Error: Command failed: git push heroku HEAD:refs/heads/main --force
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: 235b1971a13f659e7a3572c11caf9a1e4c2abce4
remote: !
remote: ! We have detected that you have triggered a build from source code with version 235b1971a13f659e7a3572c11caf9a1e4c2abce4
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: !Push rejected to test-github-action-123abc.
remote:
To https://git.heroku.com/test-github-action-123abc.git
! [remote rejected] HEAD -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/test-github-action-123abc.git'
不确定是否相关,根据https://github.com/marketplace/actions/deploy-to-heroku:
要开始使用该操作,只需确保在您的项目中有Procfile或Dockerfile
我不懂Procfile,所以没有做任何事情。特别是,我不知道如何为Python编写Procfile。我的存储库中的代码是一个简单的Python脚本,带有一个测试函数:
#! /usr/env/bin python
# content of test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 4
谢谢。
这不是Git的问题,也不是GitHub的问题。这是一个Heroku问题。
当你使用Git启动Heroku部署时,Heroku接收你想要部署的提交,并检查它的正确性。Git和/或GitHub在这里所做的就是将提交交付给Heroku。此时,
Heroku可以生成信息和/或错误。当它这样做时,它通过 Git发送,它在每个信息或错误行前面添加单词remote:
:
remote: <something Heroku said to me>
在你的例子中你看到的是:
remote: -----> Building on the Heroku-20 stack remote: -----> Determining which buildpack to use for this app remote: ! No default language could be detected for this app. remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically. remote: See https://devcenter.heroku.com/articles/buildpacks
(为了便于阅读,我在这里分了一行)
注意Heroku是怎样的:
- 告诉你它将使用哪个Heroku堆栈;
- 告诉你Heroku-20堆栈的步骤现在是"确定buildpack";
- 告诉你这里有错误:
! No default language could be detected for this app.
这个错误后面是通知。阅读建议请访问https://devcenter.heroku.com/articles/buildpacks并阅读那里的内容,它会告诉您下一步该做什么。
随后的错误主要是由于这个错误,虽然最终Heroku抱怨说,你一直在尝试同样的事情,不断失败,它只是要继续失败,直到你尝试不同的东西:GitHub自己负责这个重试几次。在这里阅读GitHub输出:
error: failed to push some refs to 'https://git.heroku.com/test-github-action-123abc.git' Unable to push branch because the branch is behind the deployed branch. Using --force to deploy branch. (If you want to avoid this, set dontuseforce to 1 in with: of .github/workflows/action.yml. Specifically, the error was: Error: Command failed: git push heroku HEAD:refs/heads/main
并决定是否要相应地修改您的GitHub操作。