- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试从 GitHub 操作远程推送到 origin
。我的行动逻辑是:
pull_request_review
事件并按评论消息过滤origin
脚本是:
if [[ "${GITHUB_EVENT_NAME}" != "pull_request_review" ]]; then
echo "unsupported event: ${GITHUB_EVENT_NAME}"
exit 1
fi
user=$(jq -r .review.user.login ${GITHUB_EVENT_PATH})
cmd=$(jq -r .review.body ${GITHUB_EVENT_PATH})
echo "reviewer is ${user}, command is ${cmd}"
if [[ "${cmd}" == "merge" ]]; then
head=$(jq -r .pull_request.head.ref ${GITHUB_EVENT_PATH})
git config user.email test@test.com
git config user.name test
git checkout -B _tmp origin/${head}
git checkout -B master origin/master
git merge --no-ff _tmp
git push origin master
fi
我正在从 alpine:3.10
Docker 容器运行这个脚本:
FROM alpine:3.10
LABEL "com.github.actions.name"="Hello world action"
LABEL "com.github.actions.icon"="shield"
LABEL "com.github.actions.color"="green"
WORKDIR /app
COPY action.sh action.sh
RUN apk --update add bash git jq
CMD ["bash", "/app/action.sh"]
第一步工作正常( checkout 和 merge ),但由于错误,操作未能将 merge 推送到 origin
:
+ git push origin master
fatal: could not read Username for 'https://github.com': No such device or address
看起来 GitHub-action Docker 容器未配置为推送到 GitHub。我该如何配置它?是否可以使用一些 env variables由 GitHub 提供或可能是一些挂载文件(如 /github/*
路径)?
最佳答案
actions/checkout@v2
checkout 的第 2 版解决了分离的 HEAD 状态问题并简化了对源的推送。
name: Push commit
on: push
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Create report file
run: date +%s > report.txt
- name: Commit report
run: |
git config --global user.name 'Your Name'
git config --global user.email 'your-username@users.noreply.github.com'
git commit -am "Automated report"
git push
如果您需要推送事件来触发其他工作流,请使用范围为 Personal Access Token 的 repo
.
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT }}
actions/checkout@v1(原始答案)
为@rmunn 的出色回答添加更多细节。问题在于 actions/checkout@v1
操作使 git 存储库处于分离的 HEAD 状态。有关更多详细信息,请参阅此问题:https://github.com/actions/checkout/issues/6
这里有一个完整的例子来演示如何将 checkout 的仓库变为可用状态并推送到远程。
name: Push commit
on: push
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Create report file
run: date +%s > report.txt
- name: Commit report
run: |
git config --global user.name 'Your Name'
git config --global user.email 'your-username@users.noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git checkout "${GITHUB_REF:11}"
git commit -am "Automated report"
git push
要包含未跟踪的(新)文件,请更改工作流程以使用以下内容。
git add -A
git commit -m "Automated report"
上述工作流应该适用于大多数事件。对于 on: pull_request
工作流,应该 check out merge 分支 (GITHUB_HEAD_REF
) 以替换默认的 merge 提交。
重要:如果除了以下工作流程之外还有其他 pull 请求检查,则必须使用 Personal Access Token而不是默认的 GITHUB_TOKEN
。这是由于 GitHub Actions 故意施加的限制,即工作流引发的事件(例如 push
)无法触发进一步的工作流运行。这是为了防止意外的“无限循环”情况,并作为一种反滥用措施。使用范围为 Personal Access Token 的 repo
是批准的解决方法。参见 this GitHub issue有关解决方法的更多详细信息。
name: Push commit on pull request
on: pull_request
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
ref: ${{ github.head_ref }}
- name: Create report file
run: date +%s > report.txt
- name: Commit report
run: |
git config --global user.name 'Your Name'
git config --global user.email 'your-username@users.noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git commit -am "Automated report"
git push
有关在 on: pull_request
工作流程中推送到源的更多示例,请参阅此博客文章,GitHub Actions: How to Automate Code Formatting in Pull Requests .
关于git - 从 GitHub 操作推送到源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57921401/
你好 StackOverflow。 我在 Github 上遇到了一个奇怪的错误。 存储库 Link 我在 4 个月前创建了一个存储库。并且只向该存储库添加了 2 个贡献者。 • 我没有再添加贡献者但是
我已经配置了 Jenkins Github 拉取请求构建器插件来构建我机构成员提出的每个拉取请求。它就像一个魅力。 但是,构建并没有像在这个不错的 post 中显示的那样将构建状态报告回 github
我只是想知道在任何 GitHub 源代码查看页面上可以查看多少个字符而不会溢出(水平滚动)。 最佳答案 在 OS X v10.9 (小牛队): 谷歌浏览器:125 火狐:122 Safari :121
我一直在寻找可以进入 .github 的事物的零碎示例。 GitHub 存储库上的目录。 我可以看到它用于 GitHub 操作和工作流以及拉取请求和问题模板,但我看不到一个页面,其中概述了您可以在理想
尝试运行 --is-bare-repository 命令,但意识到在我的克隆副本上运行它是不正确的。有没有办法在实际的 GitHub 存储库上使用相同的命令?存储库也没有显示 .git 文件。请原谅我
我正在使用 github 页面和 jekyll 创建一个博客。我想知道是否有一种方法可以将 github 文件(即存储库中的文件)中的代码片段嵌入到博客文章中。我可以在此页面上找到有关嵌入要点的解决方
我在 GitHub 存储库中有一个文件,需要通过运行命令偶尔更新。 作为 GitHub Workflows 的一部分,我想让一个机器人运行一个命令,并查看它是否在 repo 上创建了一个差异,如果是,
尝试从 Github 桌面应用程序发布到 github.com 时出现以下错误。 GitHub Desktop was unable to store the account token in the
类似于Desktop notifications from GitHub (从 10 年前开始)但提出了一个稍微不同的问题 - GitHub 是否支持 web notifications ?我想知道关
我想使用 semantic-release 在 Github 版本上发布整个目录(构建目录),但不幸的是它将每个构建文件作为单个 Assets 发布。 用于复制: 我正在使用 Vue CLI 生成一个
这让我发疯,我知道这听起来像是一个愚蠢的问题,但我已经为此苦苦挣扎了 2 天。我刚刚完成了 Visual Code 的编码,我想将它推送到 github 上。所以我创建了一个名为 mern-maps
在 GitHub 上,一个用户可以属于多个组织。一个存储库是否也可以成为多个组织的一部分? 最佳答案 根据 this blog post by GitHub , 一个仓库只能属于一个组织。 Creat
在 GitHub 操作中,我使用脚本创建了一个文件。然后我可以使用 git 创建一个分支,添加文件,提交文件并将分支推送到 repo。全部使用 git。 然后我想从我的操作中创建一个 PR,所以我使用
在 GitHub 中,当我转到:[Insights] - [Networks] 时,我看到我的分支有不同的颜色。有些在 blue , 其他人在 green .我找不到解释。 有谁知道不同颜色是什么意思
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我只是在尝试 GitHub。 为什么有些提交显示为“一天前在 GitHub 上提交”而其他提交显示为“一天前提交”? 例如这里: https://github.com/apple/swift/comm
有没有办法更改 Github 上的配色方案以进行语法高亮显示?我已经进行了基本搜索,但找不到答案。 最佳答案 目前没有办法改变服务器端的配色方案。 github.com 的几个用户已经要求 自定义语法
Github 上关闭的拉取请求是否意味着拉取请求未合并? 如果没有,有没有办法确定已关闭的拉取请求是否已合并? 谢谢。 最佳答案 If no, is there a way I can determi
不确定这是否与主题无关,但我真的很好奇这种类型的图表是否有名称以及如何创建。 像这样:https://help.github.com/articles/viewing-contributions-on
GitHub 中合作者和贡献者的拉取请求有什么区别?我没有发现合作者有任何特殊特权。 最佳答案 合作者对贡献者的一项特权是......他们(合作者)可以直接推送到您的存储库(因为您拥有 added t
我是一名优秀的程序员,十分优秀!