mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-11 10:09:03 +08:00
Fix branch checkout for PRs with GitHub workflow
This commit is contained in:
parent
ab6effb712
commit
f5a64704bd
1
.github/workflows/cicd.yml
vendored
1
.github/workflows/cicd.yml
vendored
@ -6,6 +6,7 @@ on:
|
|||||||
- master
|
- master
|
||||||
- 'WIP**'
|
- 'WIP**'
|
||||||
- '4.*'
|
- '4.*'
|
||||||
|
- 'CURA-*'
|
||||||
pull_request:
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
@ -17,24 +17,40 @@ cd "${PROJECT_DIR}"
|
|||||||
# Clone Uranium and set PYTHONPATH first
|
# Clone Uranium and set PYTHONPATH first
|
||||||
#
|
#
|
||||||
|
|
||||||
# Check the branch to use:
|
# Check the branch to use for Uranium.
|
||||||
# 1. Use the Uranium branch with the branch same if it exists.
|
# It tries the following branch names and uses the first one that's available.
|
||||||
# 2. Otherwise, use the default branch name "master"
|
# - GITHUB_HEAD_REF: the branch name of a PR. If it's not a PR, it will be empty.
|
||||||
|
# - GITHUB_BASE_REF: the branch a PR is based on. If it's not a PR, it will be empty.
|
||||||
|
# - GITHUB_REF: the branch name if it's a branch on the repository;
|
||||||
|
# refs/pull/123/merge if it's a pull_request.
|
||||||
|
# - master: the master branch. It should always exist.
|
||||||
|
|
||||||
|
# For debugging.
|
||||||
echo "GITHUB_REF: ${GITHUB_REF}"
|
echo "GITHUB_REF: ${GITHUB_REF}"
|
||||||
|
echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
|
||||||
echo "GITHUB_BASE_REF: ${GITHUB_BASE_REF}"
|
echo "GITHUB_BASE_REF: ${GITHUB_BASE_REF}"
|
||||||
|
|
||||||
GIT_REF_NAME="${GITHUB_REF}"
|
GIT_REF_NAME_LIST=( "${GITHUB_HEAD_REF}" "${GITHUB_BASE_REF}" "${GITHUB_REF}" "master" )
|
||||||
if [ -n "${GITHUB_BASE_REF}" ]; then
|
for git_ref_name in "${GIT_REF_NAME_LIST[@]}"
|
||||||
GIT_REF_NAME="${GITHUB_BASE_REF}"
|
do
|
||||||
fi
|
if [ -z "${git_ref_name}" ]; then
|
||||||
GIT_REF_NAME="$(basename "${GIT_REF_NAME}")"
|
continue
|
||||||
|
fi
|
||||||
URANIUM_BRANCH="${GIT_REF_NAME:-master}"
|
git_ref_name="$(basename "${git_ref_name}")"
|
||||||
output="$(git ls-remote --heads https://github.com/Ultimaker/Uranium.git "${URANIUM_BRANCH}")"
|
# Skip refs/pull/1234/merge as pull requests use it as GITHUB_REF
|
||||||
if [ -z "${output}" ]; then
|
if [[ "${git_ref_name}" == "merge" ]]; then
|
||||||
echo "Could not find Uranium banch ${URANIUM_BRANCH}, fallback to use master."
|
echo "Skip [${git_ref_name}]"
|
||||||
URANIUM_BRANCH="master"
|
continue
|
||||||
fi
|
fi
|
||||||
|
URANIUM_BRANCH="${git_ref_name}"
|
||||||
|
output="$(git ls-remote --heads https://github.com/Ultimaker/Uranium.git "${URANIUM_BRANCH}")"
|
||||||
|
if [ -n "${output}" ]; then
|
||||||
|
echo "Found Uranium branch [${URANIUM_BRANCH}]."
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "Could not find Uranium banch [${URANIUM_BRANCH}], try next."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
echo "Using Uranium branch ${URANIUM_BRANCH} ..."
|
echo "Using Uranium branch ${URANIUM_BRANCH} ..."
|
||||||
git clone --depth=1 -b "${URANIUM_BRANCH}" https://github.com/Ultimaker/Uranium.git "${PROJECT_DIR}"/Uranium
|
git clone --depth=1 -b "${URANIUM_BRANCH}" https://github.com/Ultimaker/Uranium.git "${PROJECT_DIR}"/Uranium
|
||||||
|
Loading…
x
Reference in New Issue
Block a user