英文:
github actions not getting the current git fetch value
问题
I manage my automatic release and deployment processes with Github actions.
在我的Github actions中,我管理自动发布和部署流程。
In my yml file, things increase by npm version and according to the label in the pull request, respectively. Make a new commit and do the deployment process and complete the actions.
在我的YML文件中,根据npm版本和拉取请求中的标签,事物分别增加。创建一个新的提交,执行部署流程并完成操作。
My problem here is my version number in the development branch, for example, I am updating the 1.2.3 patch version. It becomes 1.2.4 and reflects on the development branch, but when deploying, it sends version 1.2.3. How can i solve this problem.
我的问题是在开发分支中的版本号,例如,我正在更新1.2.3的修补版本。它变成了1.2.4并反映在开发分支上,但在部署时,它发送的是版本1.2.3。我该如何解决这个问题。
An example from my yml file
来自我的YML文件的一个示例:
英文:
I manage my automatic release and deployment processes with Github actions.
In my yml file, things increase by npm version and according to the label in the pull request, respectively. Make a new commit and do the deployment process and complete the actions.
My problem here is my version number in the development branch, for example, I am updating the 1.2.3 patch version. It becomes 1.2.4 and reflects on the development branch, but when deploying, it sends version 1.2.3. How can i solve this problem.
An example from my yml file
name: development deploy
on:
pull_request:
types:
- closed
branches:
- development
push:
branches:
- development
jobs:
automatic-version-update:
name: Automatic version update
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Check Out Repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16.15'
- name: Update Version
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
PR_LABELS=$(jq --raw-output '.pull_request.labels[].name' $GITHUB_EVENT_PATH)
if [[ $PR_LABELS == *"minor version"* ]]; then
npm version minor -m "Updated to minor version %s"
elif [[ $PR_LABELS == *"major version"* ]]; then
npm version major -m "Updated to major version %s"
elif [[ $PR_LABELS == *"patch version"* ]]; then
npm version patch -m "Updated to patch version %s"
fi
- name: Push Changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.event.pull_request.base.ref }}
build-deploy:
needs: automatic-version-update
name: Deployment jobs
runs-on: ubuntu-latest
steps:
- name: Check Out Repository
uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: '16.15'
- name: Install packages
run: yarn install
- name: React build
run: yarn run build:dev
- name: Deploy to Server
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY }}
SOURCE: '.'
REMOTE_HOST: ${{ secrets.SERVER_HOST }}
REMOTE_USER: ${{ secrets.SERVER_USERNAME }}
TARGET: ${{ secrets.SERVER_ROOT_FOLDER }}
答案1
得分: 1
TLDR; 检查正确的分支。
Microsoft Github Actions 只是在 git(1)
周围添加了一些抽象层。当发生意外情况时,先确保真正的 git(1)
工作流程是清晰的(例如,在本地工作正常),然后逐步验证 Microsoft Github Action 工作流程是否使用了正确的操作和正确的配置。
谢谢您分享您的问题,您提出了以下问题:
在部署时,它发送版本 1.2.3。我该如何解决这个问题?
解决方案可能不直接可见,所以让我们首先了解这里发生了什么。
您正在创建的提交位于 git 仓库中的 HEAD
,根据 uses: actions/checkout@v3
的命令(参见 GitHub - jobs : what is : use actions/checkout)。在 pull_request
事件中,这是一个合并引用,就像已经合并了一样 (refs/pull/...
);这不是一个分支引用 (refs/heads/...
)。
现在,当您使用以下指令命令 Microsoft Github Actions 推送时:
- name: Push Changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.event.pull_request.base.ref }}
您明确指示不要推送任何已提交的更改,而是推送(未更改的)拉取请求目标分支 ${{ github.event.pull_request.base.ref }}
。
现在修复很容易,您可能已经这样想:使用 ref
属性检出正确的分支,具体操作如下:使用 ref
属性检出正确的分支:
steps:
- name: Check Out Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}
TLDR; 检查正确的分支。
Microsoft Github Actions 只是在 git(1)
周围添加了一些抽象层。当发生意外情况时,先确保真正的 git(1)
工作流程是清晰的(例如,像您的本地测试一样),然后逐步验证 Microsoft Github Action 工作流程是否使用了正确的操作和正确的配置。
参考:如何在 Github Actions 中获取当前分支?
英文:
> TLDR; Checkout the correct branch.
>
> Microsoft Github Actions just adds a couple layers of abstractions around git(1)
. When something unexpected happens, double-check the real git(1)
workflow is clear (e.g. works locally), then verify the Microsoft Github Action Workflow uses the correct actions with the correct configuration step by step.
Thank you for sharing your question, you asked:
> When deploying, it sends version 1.2.3. How can i [sic!] solve this problem. [sic!]
The solution may not be directly visible, so let's uncover what happens here first.
The commit you're creating is in the git repository at the HEAD
commanded per uses: actions/checkout@v3
(Cf. GitHub - jobs : what is : use actions/checkout. IIRC in a pull_request
event, this is a merge reference, like as-if already merged (refs/pull/...
¹); this is not a branch reference (refs/heads/...
).
Now when you command Microsoft Github Actions to push with the following instructions:
- name: Push Changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.event.pull_request.base.ref }}
You're specifically instructing to not push any committed changes, but the (unchanged) pull request target branch ${{ github.event.pull_request.base.ref }}
.
Now the fix is easy, you may already think so: checkout the correct branch with
the ref
property:
steps:
- name: Check Out Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}
TLDR; Checkout the correct branch.
Microsoft Github Actions just adds a couple layers of abstractions around git(1)
. When something unexpected happens, double-check the real git(1)
workflow is clear (e.g. like your local testing), then verify the Microsoft Github Action Workflow uses the correct actions with the correct configuration step by step.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论