Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
5821f294
Commit
5821f294
authored
Oct 26, 2023
by
Tushar Shah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move value match and check logic to script
parent
e65c2122
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
40 deletions
+59
-40
config.yml
.circleci/config.yml
+2
-40
ci-match-values-between-files.sh
ops/scripts/ci-match-values-between-files.sh
+57
-0
No files found.
.circleci/config.yml
View file @
5821f294
...
...
@@ -1241,47 +1241,9 @@ jobs:
steps
:
-
checkout
-
run
:
name
:
Filter comments and match only 1 script
name
:
Verify Values Match
command
:
|
SCRIPT='BEGIN { in_comment = 0; matches = 0; } /^ *\/\*/ { in_comment = 1; } in_comment && /\*\// { in_comment = 0; next; } !in_comment && !/^ *\/\// && $0 ~ PATTERN { matches++; matched_line = $0; } END { if (matches == 1) { print matched_line; } else if (matches > 1) { print "Multiple matches found. Exiting."; exit 1; } else { print "No matches found. Exiting."; exit 1; } }'
echo "export SCRIPT='$SCRIPT'" >> $BASH_ENV
-
run
:
name
:
Extract value from file1
command
:
|
VALUE1_MATCH=$(echo "$SCRIPT" | awk -v PATTERN='<< parameters.pattern_file1 >>' -f- "<< parameters.file1_path >>")
if [ $? -ne 0 ]; then
exit 1
fi
VALUE1=$(echo "$VALUE1_MATCH" | awk -F'=' '{print $2}' | tr -d ' ;')
echo "Value:"
echo "$VALUE1"
echo "export VALUE1=$VALUE1" >> $BASH_ENV
-
run
:
name
:
Extract value from file2
command
:
|
VALUE2_MATCH=$(echo "$SCRIPT" | awk -v PATTERN='<< parameters.pattern_file2 >>' -f- "<< parameters.file2_path >>")
if [ $? -ne 0 ]; then
exit 1
fi
VALUE2=$(echo "$VALUE2_MATCH" | awk -F'=' '{print $2}' | tr -d ' ;')
echo "Value:"
echo "$VALUE2"
echo "export VALUE2=$VALUE2" >> $BASH_ENV
-
run
:
name
:
Compare values
command
:
|
if [ "$VALUE1" != "$VALUE2" ]; then
echo "Error: Values from file1 ($VALUE1) and file2 ($VALUE2) don't match."
exit 1
else
echo "Values match!"
fi
./ops/scripts/ci-match-values-between-files.sh "<< parameters.file1_path >>" "<< parameters.pattern_file1 >>" "<< parameters.file2_path >>" "<< parameters.pattern_file2 >>"
workflows
:
main
:
when
:
...
...
ops/scripts/ci-match-values-between-files.sh
0 → 100755
View file @
5821f294
#!/usr/bin/env bash
set
-euo
pipefail
FILE1
=
$1
PATTERN1
=
$2
FILE2
=
$3
PATTERN2
=
$4
# shellcheck disable=SC2016
SCRIPT
=
'
BEGIN {
in_comment = 0;
matches = 0;
}
/^ *\/\*/ {
in_comment = 1;
}
in_comment && /\*\// {
in_comment = 0;
next;
}
!in_comment && !/^ *\/\// && $0 ~ PATTERN {
matches++;
matched_line = $0;
}
END {
if (matches == 1) {
print matched_line;
} else if (matches > 1) {
print "Multiple matches found. Exiting.";
exit 1;
} else {
print "No matches found. Exiting.";
exit 1;
}
}'
VALUE1_MATCH
=
$(
echo
"
$SCRIPT
"
|
awk
-v
PATTERN
=
"
$PATTERN1
"
-f-
"
$FILE1
"
)
VALUE1
=
$(
echo
"
$VALUE1_MATCH
"
|
awk
-F
'='
'{print $2}'
|
tr
-d
' ;'
)
echo
"Value from File 1:
$VALUE1
"
VALUE2_MATCH
=
$(
echo
"
$SCRIPT
"
|
awk
-v
PATTERN
=
"
$PATTERN2
"
-f-
"
$FILE2
"
)
VALUE2
=
$(
echo
"
$VALUE2_MATCH
"
|
awk
-F
'='
'{print $2}'
|
tr
-d
' ;'
)
echo
"Value from File 2:
$VALUE2
"
if
[
"
$VALUE1
"
!=
"
$VALUE2
"
]
;
then
echo
"Error: Values from file1 (
$VALUE1
) and file2 (
$VALUE2
) don't match."
exit
1
fi
echo
"Values match!"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment