我正在尝试从GitHub操作推送到origin
远程。我的操作逻辑如下:
- 处理
pull_request_review
事件并按评论消息进行过滤 - 检出到主分支,合并PR分支,运行一些检查,并将其推送到
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"]
首次操作(检出和合并)是正常的,但由于错误,操作未能将合并推送到origin
:
+ git push origin master
fatal: could not read Username for 'https://github.com': No such device or address
看起来GitHub-action Docker容器未配置用于向GitHub推送。如何进行配置?是否可以使用GitHub提供的一些环境变量或者一些挂载文件(例如/github/*
路径)?
git config http.https://github.com/.extraheader
中。 - Mingwei Samuelgit status
- Andres Mitre