Skip to content

Commit b7410ba

Browse files
authored
Fix circle checkout for tags (apache-spark-on-k8s#352)
1 parent 1264fb5 commit b7410ba

File tree

1 file changed

+68
-9
lines changed

1 file changed

+68
-9
lines changed

.circleci/config.yml

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,65 @@ step_templates:
5959
if [[ -d "$BUILD_SBT_CACHE" ]]; then
6060
rsync --info=stats2,misc1,flist0 -a --link-dest="$BUILD_SBT_CACHE" "$BUILD_SBT_CACHE/" .
6161
fi
62+
checkout-code: &checkout-code
63+
run:
64+
name: Checkout code
65+
command: |
66+
# Copy of circle's checkout command with fix for fetching tags from
67+
# https://discuss.circleci.com/t/fetching-circle-tag-doesnt-seem-to-work/19014/2
68+
69+
# Workaround old docker images with incorrect $HOME
70+
# check https://github.com/docker/docker/issues/2968 for details
71+
if [ "${HOME}" = "/" ]
72+
then
73+
export HOME=$(getent passwd $(id -un) | cut -d: -f6)
74+
fi
75+
76+
mkdir -p ~/.ssh
77+
78+
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
79+
bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==
80+
' >> ~/.ssh/known_hosts
81+
82+
(umask 077; touch ~/.ssh/id_rsa)
83+
chmod 0600 ~/.ssh/id_rsa
84+
(cat <<EOF > ~/.ssh/id_rsa
85+
$CHECKOUT_KEY
86+
EOF
87+
)
88+
89+
# use git+ssh instead of https
90+
git config --global url."ssh://[email protected]".insteadOf "https://github.com" || true
91+
92+
if [ -e /home/circleci/project/.git ]
93+
then
94+
cd /home/circleci/project
95+
git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true
96+
else
97+
mkdir -p /home/circleci/project
98+
cd /home/circleci/project
99+
git clone "$CIRCLE_REPOSITORY_URL" .
100+
fi
101+
102+
if [ -n "$CIRCLE_TAG" ]
103+
then
104+
git fetch origin "+refs/tags/${CIRCLE_TAG}:refs/tags/${CIRCLE_TAG}"
105+
else
106+
git fetch origin "+${CIRCLE_BRANCH}:remotes/origin/${CIRCLE_BRANCH}"
107+
fi
108+
109+
110+
if [ -n "$CIRCLE_TAG" ]
111+
then
112+
git reset --hard "$CIRCLE_SHA1"
113+
git checkout -q "$CIRCLE_TAG"
114+
elif [ -n "$CIRCLE_BRANCH" ]
115+
then
116+
git reset --hard "$CIRCLE_SHA1"
117+
git checkout -q -B "$CIRCLE_BRANCH"
118+
fi
119+
120+
git reset --hard "$CIRCLE_SHA1"
62121
63122
jobs:
64123
build-maven:
@@ -73,7 +132,7 @@ jobs:
73132
- build-maven-{{ .Branch }}-{{ .BuildNum }}
74133
- build-maven-{{ .Branch }}-
75134
- build-maven-master-
76-
- checkout
135+
- *checkout-code
77136
- restore_cache:
78137
keys:
79138
- maven-dependency-cache-{{ checksum "pom.xml" }}
@@ -110,7 +169,7 @@ jobs:
110169
<<: *test-defaults
111170
resource_class: small
112171
steps:
113-
- checkout
172+
- *checkout-code
114173
# Need maven dependency cache, otherwise checkstyle tests fail as such:
115174
# Failed to execute goal on project spark-assembly_2.11: Could not resolve dependencies for project org.apache.spark:spark-assembly_2.11:pom:2.4.0-SNAPSHOT
116175
- restore_cache:
@@ -126,7 +185,7 @@ jobs:
126185
<<: *test-defaults
127186
resource_class: small
128187
steps:
129-
- checkout
188+
- *checkout-code
130189
- restore_cache:
131190
key: build-maven-{{ .Branch }}-{{ .BuildNum }}
132191
- restore_cache:
@@ -147,7 +206,7 @@ jobs:
147206
- v1-build-sbt-{{ .Branch }}-{{ .Revision }}
148207
- v1-build-sbt-{{ .Branch }}-
149208
- v1-build-sbt-master-
150-
- checkout
209+
- *checkout-code
151210
- run:
152211
name: Hard link cache contents into current build directory
153212
command: |
@@ -197,7 +256,7 @@ jobs:
197256
# depends on build-sbt
198257
<<: *defaults
199258
steps:
200-
- checkout
259+
- *checkout-code
201260
- attach_workspace:
202261
at: .
203262
- *restore-ivy-cache
@@ -217,7 +276,7 @@ jobs:
217276
- image: palantirtechnologies/circle-spark-python
218277
parallelism: 2
219278
steps:
220-
- checkout
279+
- *checkout-code
221280
# These two steps restore all the target directories except jars
222281
# Necessary because of SPARK_PREPEND_CLASSES being used in python tests, and some python tests
223282
# accessing classes from the core/test configuration.
@@ -241,7 +300,7 @@ jobs:
241300
docker:
242301
- image: palantirtechnologies/circle-spark-r
243302
steps:
244-
- checkout
303+
- *checkout-code
245304
- attach_workspace:
246305
at: .
247306
- run:
@@ -262,7 +321,7 @@ jobs:
262321
- run:
263322
name: Before running tests, ensure we created the CIRCLE_TEST_REPORTS directory
264323
command: mkdir -p $CIRCLE_TEST_REPORTS
265-
- checkout
324+
- *checkout-code
266325
- attach_workspace:
267326
at: .
268327
# These two steps restore all the target directories except jars
@@ -349,7 +408,7 @@ jobs:
349408
docker:
350409
- image: palantirtechnologies/circle-spark-r
351410
steps:
352-
- checkout
411+
- *checkout-code
353412
- restore_cache:
354413
key: maven-dependency-cache-{{ checksum "pom.xml" }}
355414
- *restore-build-binaries-cache

0 commit comments

Comments
 (0)