| 1 | #!/bin/sh |
| 2 | |
| 3 | set -eu |
| 4 | |
| 5 | usage() { |
| 6 | echo "Usage: $0 WTOKEN ANALYSIS_OUTPUT_DIR" >&2 |
| 7 | exit 2 |
| 8 | } |
| 9 | |
| 10 | [ $# -eq 2 ] || usage |
| 11 | |
| 12 | wtoken=$1 |
| 13 | analysisOutputDir=$2 |
| 14 | |
| 15 | # Load settings and helpers |
| 16 | . "$(dirname "$0")/action.helpers" |
| 17 | . "$(dirname "$0")/action.settings" |
| 18 | |
| 19 | case "${event}" in |
| 20 | push) |
| 21 | curl -sS "${eclairReportUrlPrefix}/ext/update_push" \ |
| 22 | -F "wtoken=${wtoken}" \ |
| 23 | -F "artifactsDir=${artifactsDir}" \ |
| 24 | -F "subDir=${subDir}" \ |
| 25 | -F "jobId=${jobId}" \ |
| 26 | -F "jobHeadline=${jobHeadline}" \ |
| 27 | -F "commitId=${headCommitId}" \ |
| 28 | -F "badgeLabel=${badgeLabel}" \ |
| 29 | -F "keepOldAnalyses=${keepOldAnalyses}" \ |
| 30 | -F "db=@${analysisOutputDir}/PROJECT.ecd" \ |
| 31 | >"${updateLog}" |
| 32 | ;; |
| 33 | auto_pull_request) |
| 34 | curl -sS "${eclairReportUrlPrefix}/ext/update_pull_request" \ |
| 35 | -F "wtoken=${wtoken}" \ |
| 36 | -F "artifactsDir=${artifactsDir}" \ |
| 37 | -F "subDir=${subDir}" \ |
| 38 | -F "jobId=${jobId}" \ |
| 39 | -F "jobHeadline=${jobHeadline}" \ |
| 40 | -F "baseCommitId=${baseCommitId}" \ |
| 41 | -F "keepOldAnalyses=${keepOldAnalyses}" \ |
| 42 | -F "db=@${analysisOutputDir}/PROJECT.ecd" \ |
| 43 | >"${updateLog}" |
| 44 | ;; |
| 45 | *) |
| 46 | echo "Unexpected event ${event}" >&2 |
| 47 | exit 1 |
| 48 | ;; |
| 49 | esac |
| 50 | |
| 51 | ex=0 |
| 52 | grep -Fq "unfixedReports: " "${updateLog}" || ex=$? |
| 53 | maybe_log_file_exit PUBLISH_RESULT "Publishing results" "${updateLog}" "${ex}" |
| 54 | |
| 55 | summary |
| 56 | |
| 57 | if is_enabled "${ENABLE_ECLAIR_BOT:-}"; then |
| 58 | case ${ci} in |
| 59 | github) |
| 60 | ex=0 |
| 61 | gh api \ |
| 62 | --method POST \ |
| 63 | "/repos/${repository}/commits/${headCommitId}/comments" \ |
| 64 | -F "body=@${summaryTxt}" \ |
| 65 | --silent >"${commentLog}" 2>&1 || ex=$? |
| 66 | maybe_log_file_exit ADD_COMMENT "Adding comment" "${commentLog}" "${ex}" |
| 67 | ;; |
| 68 | gitlab) |
| 69 | curl -sS --request POST \ |
| 70 | "${gitlabApiUrl}/projects/${CI_PROJECT_ID}/repository/commits/${CI_COMMIT_SHA}/comments" \ |
| 71 | -H "PRIVATE-TOKEN: ${gitlabBotToken}" \ |
| 72 | -F "note=<${summaryTxt}" >"${commentLog}" |
| 73 | ex=0 |
| 74 | grep -Fq "Unfixed reports: " "${commentLog}" || ex=$? |
| 75 | maybe_log_file_exit ADD_COMMENT "Adding comment" "${commentLog}" "${ex}" |
| 76 | ;; |
| 77 | jenkins) |
| 78 | ex=0 |
| 79 | curl \ |
| 80 | --user "${jenkinsBotUsername}:${jenkinsBotToken}" \ |
| 81 | --data-urlencode "description=$(cat "${summaryTxt}")" \ |
| 82 | --data-urlencode "Submit=Submit" \ |
| 83 | "${jenkinsApiUrl}job/${project}/${jobId}/submitDescription" \ |
| 84 | >"${commentLog}" 2>&1 || ex=$? |
| 85 | curl \ |
| 86 | --user "${jenkinsBotUsername}:${jenkinsBotToken}" \ |
| 87 | --data-urlencode "description=$(cat "${summaryTxt}")" \ |
| 88 | --data-urlencode "Submit=Submit" \ |
| 89 | "${jenkinsApiUrl}job/${project}/submitDescription" \ |
| 90 | >"${commentLog}" 2>&1 || ex=$? |
| 91 | maybe_log_file_exit ADD_COMMENT "Adding comment" "${commentLog}" "${ex}" |
| 92 | ;; |
| 93 | *) ;; |
| 94 | esac |
| 95 | fi |