Skip to content

Commit

Permalink
Add python tool to check for matching CI branches (#583)
Browse files Browse the repository at this point in the history
Use in windows CI to try matching gazebodistro branch.

Fixes #579.
Part of #564.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Dec 4, 2021
1 parent c6f34de commit be8a55a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion jenkins-scripts/docker/lib/docker_generate_dockerfile.bash
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export APT_PARAMS=

GZDEV_DIR=${WORKSPACE}/gzdev
GZDEV_BRANCH=${GZDEV_BRANCH:-master}
if [[ "$ghprbSourceBranch" =~ ci_matching_branch\/ ]]; then
if python3 ${SCRIPT_DIR}/../tools/detect_ci_matching_branch.py "${ghprbSourceBranch}"; then
GZDEV_TRY_BRANCH=$ghprbSourceBranch
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ brew tap osrf/simulation
echo '# END SECTION'

if [[ -n "${ghprbSourceBranch}" ]] && \
[[ "${ghprbSourceBranch}" =~ ci_matching_branch\/ ]]
python3 ${SCRIPT_DIR}/tools/detect_ci_matching_branch.py "${ghprbSourceBranch}"
then
echo "# BEGIN SECTION: trying to checkout branch ${ghprbSourceBranch} from osrf/simulation"
pushd $(brew --repo osrf/simulation)
Expand Down
14 changes: 14 additions & 0 deletions jenkins-scripts/lib/windows_library.bat
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,26 @@ goto :EOF
::
:: arg1: Name of the yaml file in the gazebodistro repro
:: arg2: directory destination (default .)
setlocal EnableDelayedExpansion
set gzdistro_dir=gazebodistro

if "%GAZEBODISTRO_BRANCH%" == "" (set GAZEBODISTRO_BRANCH=master)

if exist %gzdistro_dir% (rmdir /s /q %gzdistro_dir%)
git clone https://github.com/ignition-tooling/gazebodistro %gzdistro_dir% -b %GAZEBODISTRO_BRANCH%
:: Check if ci_matching_branch name is used
if "%ghprbSourceBranch%" == "" (echo ghprbSourceBranch is unset) else (
python "%SCRIPT_DIR%\tools\detect_ci_matching_branch.py" "%ghprbSourceBranch%"
if "%ERRORLEVEL%" == "0" (
echo trying to checkout branch %ghprbSourceBranch% from gazebodistro
git -C %gzdistro_dir% fetch origin %ghprbSourceBranch% || rem
git -C %gzdistro_dir% checkout %ghprbSourceBranch% || rem
) else (
echo branch name %ghprbSourceBranch% is not a match
)
:: print branch for informational purposes
git -C %gzdistro_dir% branch
)
vcs import --retry 5 --force < "%gzdistro_dir%\%1" "%2" || goto :error
vcs pull || goto :error
goto :EOF
Expand Down
16 changes: 16 additions & 0 deletions jenkins-scripts/tools/detect_ci_matching_branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
from __future__ import print_function
import re
import sys

if len(sys.argv) != 2:
print('need to branch name', file=sys.stderr)
exit()
branchName = sys.argv[1]

pattern = 'ci_matching_branch/'
match = re.search(pattern, branchName)
if match:
print(f"{branchName} matches {pattern}")
else:
sys.exit(f"{branchName} does not match {pattern}")

0 comments on commit be8a55a

Please sign in to comment.