SQSCANGHA-3 Permission cleanup doesn't run if the scanner exits with a non-0 code (#33)

This commit is contained in:
Benjamin Svobodny 2022-07-05 09:15:01 -04:00 committed by GitHub
parent bdba66714e
commit fd8151470c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 5 deletions

View File

@ -1,6 +1,6 @@
name: QA
on: push
on: [push, pull_request]
jobs:
run_qa:

View File

@ -12,4 +12,6 @@ LABEL version="1.1.0" \
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
COPY cleanup.sh /cleanup.sh
RUN chmod +x /cleanup.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -7,6 +7,8 @@ branding:
runs:
using: docker
image: Dockerfile
entrypoint: "/entrypoint.sh"
post-entrypoint: "/cleanup.sh"
inputs:
args:
description: Additional arguments to the sonar-scanner

8
cleanup.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
set -e
_tmp_file=$(ls "${INPUT_PROJECTBASEDIR}/" | head -1)
PERM=$(stat -c "%u:%g" "${INPUT_PROJECTBASEDIR}/$_tmp_file")
chown -R $PERM "${INPUT_PROJECTBASEDIR}/"

View File

@ -27,7 +27,3 @@ unset JAVA_HOME
sonar-scanner -Dsonar.projectBaseDir=${INPUT_PROJECTBASEDIR} ${INPUT_ARGS}
_tmp_file=$(ls "${INPUT_PROJECTBASEDIR}/" | head -1)
PERM=$(stat -c "%u:%g" "${INPUT_PROJECTBASEDIR}/$_tmp_file")
chown -R $PERM "${INPUT_PROJECTBASEDIR}/"

View File

@ -91,6 +91,7 @@ success "Correctly failed fast."
info "Analyze project..."
cd test/example-project/
docker run -v `pwd`:/github/workspace/ --workdir /github/workspace --network $network --env INPUT_PROJECTBASEDIR=/github/workspace --env SONAR_TOKEN=$token --env SONAR_HOST_URL='http://sonarqube:9000' sonarsource/sonarqube-scan-action
docker run -v `pwd`:/github/workspace/ --workdir /github/workspace --network $network --env INPUT_PROJECTBASEDIR=/github/workspace --entrypoint /cleanup.sh sonarsource/sonarqube-scan-action
if [[ ! $? -eq 0 ]]; then
error "Couldn't run the analysis."
exit 1