我在我的iOS项目中使用Xcode Cloud。有一些基于分支和标记的工作流。通常情况下,其中之一就是在“试飞”上发表应用程序。
我的目标是在每次推动的时候在develop分支上运行一个自动化。当脚本在提交消息中找到#promote标记时,就会出现这种自动化。
我的第一种方法是在Xcode Cloud中使用post构建脚本,如下所示:
#!/bin/sh
# ci_post_xcodebuild.sh
# BeforeDaily
#
# Created by Piotrek on 28/08/2022.
#
cd "$CI_WORKSPACE"
MESSAGE=$(git log -1 --oneline --format=%s | sed 's/^.*: //')
if [[ "$MESSAGE" == *"#promote"* ]]; then
echo "Merging develop into stage"
git fetch --all
git checkout --track -b stage origin/stage
git merge develop
git push origin stage
git checkout develop
echo "Done"
else
echo "There is nothing to do here..."
fi这种方法是很有希望的,但是Xcode Cloud没有对Github项目的写权限,因此不可能对它进行更改。脚本的结果如下:
2022-08-28T21:37:40.713643324Z Merging develop into stage
2022-08-28T21:37:42.747978838Z From http://github.com/<username>/<project_name>
2022-08-28T21:37:42.748494378Z * [new branch] develop -> origin/develop
2022-08-28T21:37:42.749001513Z * [new branch] main -> origin/main
2022-08-28T21:37:42.749224260Z * [new branch] stage -> origin/stage
2022-08-28T21:37:42.749514956Z Switched to a new branch 'stage'
2022-08-28T21:37:42.749752757Z branch 'stage' set up to track 'origin/stage'.
2022-08-28T21:37:42.750006530Z fatal: refusing to merge unrelated histories
2022-08-28T21:37:42.852059197Z remote: Write access to repository not granted.
2022-08-28T21:37:42.852480361Z fatal: unable to access 'http://github.com/piotrekjeremicz/beforedaily-swiftui-app.git/': The requested URL returned error: 403
2022-08-28T21:37:42.852854256Z Switched to branch 'develop'
2022-08-28T21:37:42.853020173Z Done所以问题是:有什么方法可以为我提供基于提交消息内容的自动合并吗?
发布于 2022-08-31 17:06:14
除了创建一个干净的clone并开发新的git存储库之外,我找不到任何其他解决方案。所有工作都是在Xcode Cloud中完成的,这里是最后一个ci_post_xcbuild.sh,如果develop上的某些消息包含#promote字符串,它将合并到#promote。
#!/bin/sh
cd "$CI_WORKSPACE"
MESSAGE=$(git log -1 --oneline --format=%s | sed 's/^.*: //')
if [[ "$CI_BRANCH" == develop && "$MESSAGE" == *"#promote"* ]]; then
echo "Automerge develop branch into stage"
mkdir tempclone
cd tempclone
git clone https://x-access-token:$GITHUB_TOKEN@github.com/github_account/github_repo_name.git
cd beforedaily-swiftui-app
git config --global user.email "xcodecloud@jeremicz.com"
git config --global user.name "Xcode Cloud"
git checkout --track -b stage origin/stage
git merge origin/develop
git push origin stage
cd ../../
rm -r tempclone
else
echo "There is nothing to do here..."
fi此脚本将Github令牌用作可以在工作流设置中设置的环境值。
https://stackoverflow.com/questions/73524507
复制相似问题