Skip to content

Commit 706e538

Browse files
committed
Split CI test logic into multiple functions
ci-test.sh is long and includes all CI providers together. Split them into multiple functions for increased readability Signed-off-by: Tomáš Nevrlka <[email protected]>
1 parent f578488 commit 706e538

File tree

1 file changed

+101
-78
lines changed

1 file changed

+101
-78
lines changed

ci-test.sh

Lines changed: 101 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -86,47 +86,6 @@ function updateBuild() {
8686
cat "$SETUP_ENV"
8787
}
8888

89-
# create latest images for dev github and gitlab
90-
make build-push-image
91-
# update the jenkins library in the dev branch
92-
bash hack/update-jenkins-library
93-
94-
# Repos on github and gitlab, github and jenkins
95-
# source repos are updated with the name of the corresponding GITOPS REPO for update-deployment
96-
updateBuild "$BUILD" "$TEST_GITOPS_REPO"
97-
updateBuild "$GITOPS"
98-
updateBuild "$GITLAB_BUILD" "$TEST_GITOPS_GITLAB_REPO"
99-
updateBuild "$GITLAB_GITOPS"
100-
updateBuild "$JENKINS_BUILD" "$TEST_GITOPS_JENKINS_REPO"
101-
updateBuild "$JENKINS_GITOPS"
102-
103-
# source repos for copying the generated manifests
104-
GEN_SRC=generated/source-repo
105-
GEN_GITOPS=generated/gitops-template
106-
107-
#Jenkins
108-
echo "Update Jenkins file in $JENKINS_BUILD and $JENKINS_GITOPS"
109-
echo "NEW - JENKINS USES A SEPARATE REPO FROM GITHUB ACTIONS"
110-
cp $GEN_SRC/jenkins/Jenkinsfile "$JENKINS_BUILD"/Jenkinsfile
111-
cp $GEN_GITOPS/jenkins/Jenkinsfile "$JENKINS_GITOPS"/Jenkinsfile
112-
updateGitAndQuayRefs "$JENKINS_BUILD"/Jenkinsfile
113-
updateGitAndQuayRefs "$JENKINS_GITOPS"/Jenkinsfile
114-
115-
# Gitlab CI
116-
echo "Update .gitlab-ci.yml file in $GITLAB_BUILD and $GITLAB_GITOPS"
117-
cp $GEN_SRC/gitlabci/.gitlab-ci.yml "$GITLAB_BUILD"/.gitlab-ci.yml
118-
cp $GEN_GITOPS/gitlabci/.gitlab-ci.yml "$GITLAB_GITOPS"/.gitlab-ci.yml
119-
updateGitAndQuayRefs "$GITLAB_BUILD"/.gitlab-ci.yml
120-
updateGitAndQuayRefs "$GITLAB_GITOPS"/.gitlab-ci.yml
121-
122-
# Github Actions
123-
echo "Update .github workflows in $BUILD and $GITOPS"
124-
cp -r $GEN_SRC/githubactions/.github "$BUILD"
125-
cp -r $GEN_GITOPS/githubactions/.github "$GITOPS"
126-
for wf in "$BUILD"/.github/workflows/* "$GITOPS"/.github/workflows/*; do
127-
updateGitAndQuayRefs "$wf"
128-
done
129-
13089
function updateRepos() {
13190
REPO=$1
13291
echo
@@ -138,43 +97,107 @@ function updateRepos() {
13897
popd
13998
}
14099

141-
# set secrets and then push to repos to ensure pipeline runs are
142-
# with correct values
143-
# github
144-
if [ "$SKIP_SECRETS" == "false" ]; then
145-
bash hack/ghub-set-vars "$TEST_BUILD_REPO"
146-
bash hack/ghub-set-vars "$TEST_GITOPS_REPO"
147-
fi
100+
function test_jenkins() {
101+
echo "Testing Jenkins..."
102+
echo
148103

149-
updateRepos "$BUILD"
150-
updateRepos "$GITOPS"
104+
# update the jenkins library in the dev branch
105+
bash hack/update-jenkins-library
151106

152-
# gitlab
153-
if [ "$SKIP_SECRETS" == "false" ]; then
154-
bash hack/glab-set-vars "$(basename "$TEST_BUILD_GITLAB_REPO")"
155-
bash hack/glab-set-vars "$(basename "$TEST_GITOPS_GITLAB_REPO")"
156-
fi
157-
updateRepos "$GITLAB_BUILD"
158-
updateRepos "$GITLAB_GITOPS"
107+
# source repos are updated with the name of the corresponding GITOPS REPO for update-deployment
108+
updateBuild "$JENKINS_BUILD" "$TEST_GITOPS_JENKINS_REPO"
109+
updateBuild "$JENKINS_GITOPS"
159110

160-
# Jenkins
161-
# note, jenkins secrets are global so set once"
162-
if [ "$SKIP_SECRETS" == "false" ]; then
163-
bash hack/jenkins-set-secrets
164-
fi
165-
updateRepos "$JENKINS_BUILD"
166-
updateRepos "$JENKINS_GITOPS"
167-
bash hack/jenkins-run-pipeline "$(basename "$TEST_BUILD_JENKINS_REPO")"
168-
169-
echo
170-
echo "Github Build and Gitops Repos"
171-
echo "Build: $TEST_BUILD_REPO"
172-
echo "Gitops: $TEST_GITOPS_REPO"
173-
echo
174-
echo "Gitlab Build and Gitops Repos"
175-
echo "Build: $TEST_BUILD_GITLAB_REPO"
176-
echo "Gitops: $TEST_GITOPS_GITLAB_REPO"
177-
echo
178-
echo "Jenkins Build and Gitops Repos"
179-
echo "Build: $TEST_BUILD_JENKINS_REPO"
180-
echo "Gitops: $TEST_GITOPS_JENKINS_REPO"
111+
echo "Update Jenkins file in $JENKINS_BUILD and $JENKINS_GITOPS"
112+
echo "NEW - JENKINS USES A SEPARATE REPO FROM GITHUB ACTIONS"
113+
cp $GEN_SRC/jenkins/Jenkinsfile "$JENKINS_BUILD"/Jenkinsfile
114+
cp $GEN_GITOPS/jenkins/Jenkinsfile "$JENKINS_GITOPS"/Jenkinsfile
115+
updateGitAndQuayRefs "$JENKINS_BUILD"/Jenkinsfile
116+
updateGitAndQuayRefs "$JENKINS_GITOPS"/Jenkinsfile
117+
118+
# note, jenkins secrets are global so set once
119+
if [ "$SKIP_SECRETS" == "false" ]; then
120+
bash hack/jenkins-set-secrets
121+
fi
122+
updateRepos "$JENKINS_BUILD"
123+
updateRepos "$JENKINS_GITOPS"
124+
125+
bash hack/jenkins-run-pipeline "$(basename "$TEST_BUILD_JENKINS_REPO")"
126+
127+
echo
128+
echo "Jenkins Build and Gitops Repos"
129+
echo "Build: $TEST_BUILD_JENKINS_REPO"
130+
echo "Gitops: $TEST_GITOPS_JENKINS_REPO"
131+
}
132+
133+
function test_gh_actions() {
134+
echo "Testing GitHub Actions..."
135+
echo
136+
137+
# source repos are updated with the name of the corresponding GITOPS REPO for update-deployment
138+
updateBuild "$BUILD" "$TEST_GITOPS_REPO"
139+
updateBuild "$GITOPS"
140+
141+
echo "Update .github workflows in $BUILD and $GITOPS"
142+
cp -r $GEN_SRC/githubactions/.github "$BUILD"
143+
cp -r $GEN_GITOPS/githubactions/.github "$GITOPS"
144+
for wf in "$BUILD"/.github/workflows/* "$GITOPS"/.github/workflows/*; do
145+
updateGitAndQuayRefs "$wf"
146+
done
147+
148+
# set secrets and then push to repos to ensure pipeline runs are
149+
# with correct values
150+
# github
151+
if [ "$SKIP_SECRETS" == "false" ]; then
152+
bash hack/ghub-set-vars "$TEST_BUILD_REPO"
153+
bash hack/ghub-set-vars "$TEST_GITOPS_REPO"
154+
fi
155+
156+
updateRepos "$BUILD"
157+
updateRepos "$GITOPS"
158+
159+
echo
160+
echo "Github Build and Gitops Repos"
161+
echo "Build: $TEST_BUILD_REPO"
162+
echo "Gitops: $TEST_GITOPS_REPO"
163+
}
164+
165+
function test_gitlab_ci() {
166+
echo "Testing GitLab CI..."
167+
echo
168+
169+
# source repos are updated with the name of the corresponding GITOPS REPO for update-deployment
170+
updateBuild "$GITLAB_BUILD" "$TEST_GITOPS_GITLAB_REPO"
171+
updateBuild "$GITLAB_GITOPS"
172+
173+
# Gitlab CI
174+
echo "Update .gitlab-ci.yml file in $GITLAB_BUILD and $GITLAB_GITOPS"
175+
cp $GEN_SRC/gitlabci/.gitlab-ci.yml "$GITLAB_BUILD"/.gitlab-ci.yml
176+
cp $GEN_GITOPS/gitlabci/.gitlab-ci.yml "$GITLAB_GITOPS"/.gitlab-ci.yml
177+
updateGitAndQuayRefs "$GITLAB_BUILD"/.gitlab-ci.yml
178+
updateGitAndQuayRefs "$GITLAB_GITOPS"/.gitlab-ci.yml
179+
180+
# gitlab
181+
if [ "$SKIP_SECRETS" == "false" ]; then
182+
bash hack/glab-set-vars "$(basename "$TEST_BUILD_GITLAB_REPO")"
183+
bash hack/glab-set-vars "$(basename "$TEST_GITOPS_GITLAB_REPO")"
184+
fi
185+
updateRepos "$GITLAB_BUILD"
186+
updateRepos "$GITLAB_GITOPS"
187+
188+
echo ""
189+
echo "Gitlab Build and Gitops Repos"
190+
echo "Build: $TEST_BUILD_GITLAB_REPO"
191+
echo "Gitops: $TEST_GITOPS_GITLAB_REPO"
192+
}
193+
194+
# create latest images for dev github and gitlab
195+
make build-push-image
196+
197+
# source repos for copying the generated manifests
198+
GEN_SRC=generated/source-repo
199+
GEN_GITOPS=generated/gitops-template
200+
201+
test_gh_actions
202+
test_gitlab_ci
203+
test_jenkins

0 commit comments

Comments
 (0)