Skip to content

Commit be50c33

Browse files
author
Trong Nhan Mai
authored
chore: improve token support in run_macaron.sh (#780)
Signed-off-by: Trong Nhan Mai <trong.nhan.mai@oracle.com>
1 parent a06ed41 commit be50c33

File tree

22 files changed

+126
-28
lines changed

22 files changed

+126
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,4 @@ tests/slsa_analyzer/ci_service/mock_repos/**
179179
docs/_build
180180
bin/
181181
requirements.txt
182+
.macaron_env_file

scripts/dev_scripts/integration_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ run_macaron_clean $ANALYZE -purl pkg:maven/io.github.behnazh-w.demo/example-mave
398398
check_or_update_expected_output $COMPARE_DEPS $DEP_RESULT $DEP_EXPECTED || log_fail
399399

400400
python ./tests/integration/run.py run \
401+
--exclude-tag docker-only \
401402
./tests/integration/cases/... || log_fail
402403

403404
# Important: This should be at the end of the file

scripts/dev_scripts/integration_tests_docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ rm -rf "$VIRTUAL_ENV_PATH"
6060

6161
python ./tests/integration/run.py run \
6262
--macaron scripts/release_scripts/run_macaron.sh \
63-
--include-tag docker \
63+
--include-tag shared-docker-python \
6464
./tests/integration/cases/... || log_fail
6565

6666
if [ $RESULT_CODE -ne 0 ];

scripts/release_scripts/run_macaron.sh

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,17 @@ function mount_file() {
259259
mounts+=("-v" "${file_on_host}:${file_in_container}:${mount_option}")
260260
}
261261

262-
# Handle tokens.
263-
set +u
264-
echo "" > ${TOKEN_FILE}
265-
{
266-
echo "GITHUB_TOKEN=${GITHUB_TOKEN}" >> ${TOKEN_FILE}
267-
echo "MCN_GITLAB_TOKEN=${MCN_GITLAB_TOKEN}" >> ${TOKEN_FILE}
268-
echo "MCN_SELF_HOSTED_GITLAB_TOKEN=${MCN_SELF_HOSTED_GITLAB_TOKEN}"
269-
} >> ${TOKEN_FILE}
270-
mount_file "macaron_env_file" ${TOKEN_FILE} ${MACARON_WORKSPACE}/${TOKEN_FILE} "rw,Z"
271-
set -u
262+
# Clean up the token file and EXIT this bash script with the given status code.
263+
#
264+
# Arguments:
265+
# $1: The eventual exit status code.
266+
# $2: The path to the token file.
267+
function clean_up_exit() {
268+
status_code=$1
269+
token_file_path=$2
270+
rm -f "$token_file_path"
271+
exit "$status_code"
272+
}
272273

273274
# Parse main arguments.
274275
while [[ $# -gt 0 ]]; do
@@ -598,6 +599,18 @@ else
598599
fi
599600
fi
600601

602+
# Make sure commands that need to be cleaned up exist within `set +e` so that when any of them returns a non-zero
603+
# status code, we don't exit right away and still run the token file cleaning up command.
604+
set +e
605+
606+
# Handle tokens.
607+
{
608+
echo "GITHUB_TOKEN=${GITHUB_TOKEN}"
609+
echo "MCN_GITLAB_TOKEN=${MCN_GITLAB_TOKEN}"
610+
echo "MCN_SELF_HOSTED_GITLAB_TOKEN=${MCN_SELF_HOSTED_GITLAB_TOKEN}"
611+
} > ${TOKEN_FILE}
612+
mount_file "macaron_env_file" ${TOKEN_FILE} ${MACARON_WORKSPACE}/${TOKEN_FILE} "rw,Z"
613+
601614
# Force docker to use linux/amd64 platform in order to make docker use emulation on ARM host platforms.
602615
docker run \
603616
--platform=linux/amd64 \
@@ -612,4 +625,4 @@ docker run \
612625
"${entrypoint[@]}" \
613626
"${macaron_args[@]}"
614627

615-
rm -f "$TOKEN_FILE"
628+
clean_up_exit "$?" "$TOKEN_FILE"

tests/integration/cases/apache_maven_local_repo/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: |
55
Analyzing with local paths using local_repos_dir without dependency resolution.
66
77
tags:
8-
- docker
8+
- shared-docker-python
99

1010
steps:
1111
- name: Prepare local repo directory

tests/integration/cases/apache_maven_purl_repo_path/test.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: |
55
Analyze with PURL, repository path, no dependency resolution.
66
77
tags:
8-
- docker
8+
- shared-docker-python
99

1010
steps:
1111
- name: Run macaron analyze
@@ -21,6 +21,12 @@ steps:
2121
- -d
2222
- 3fc399318edef0d5ba593723a24fff64291d6f9b
2323
- --skip-deps
24+
# This to check if run_macaron.sh cleans up the token file after the test case runs for the docker image.
25+
- name: Check the token file doesn't exist.
26+
kind: shell
27+
options:
28+
cmd: ls .macaron_env_file
29+
expect_fail: true
2430
- name: Run macaron verify-policy to verify passed/failed checks
2531
kind: verify
2632
options:

tests/integration/cases/apache_maven_sbom/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: |
55
Analyzing using a CycloneDx SBOM with target repo path
66
77
tags:
8-
- docker
8+
- shared-docker-python
99

1010
steps:
1111
- name: Run macaron analyze

tests/integration/cases/apache_maven_yaml_input_skip_deps/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: |
55
Check the e2e output JSON file with config and no dependency analyzing.
66
77
tags:
8-
- docker
8+
- shared-docker-python
99

1010
steps:
1111
- name: Run macaron analyze

tests/integration/cases/apache_maven_yaml_input_with_dep_resolution/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: |
55
Check the resolved dependency output with config for cyclonedx maven plugin
66
77
tags:
8-
- docker
8+
- shared-docker-python
99

1010
steps:
1111
- name: Run macaron analyze

tests/integration/cases/behnazh-w_example-maven-app/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: |
66
Policy CLI, and VSA generation.
77
88
tags:
9-
- docker
9+
- shared-docker-python
1010

1111
steps:
1212
- name: Clone the repository

0 commit comments

Comments
 (0)