From 8627e152d3d6939dc87aeeff01763d69aa1cec27 Mon Sep 17 00:00:00 2001 From: Leandro Belli Date: Thu, 9 May 2024 16:18:16 +0100 Subject: [PATCH] ci/status-report: Add status reporting when an external MR is triggered This patch adds a status report when an external MR is triggered, this allows to have a corresponding feedback message with the pipeline output result, and the MR is approved/unapproved accordingly. It is also fixed the style on `FETCH_PUBLIC_MR` variable definition. Signed-off-by: Leandro Belli Change-Id: Ia91e510357befeed85d95ff1cec0f87bf730cc27 --- .gitlab/.gitlab-ci.yml | 2 +- .gitlab/pipelines/deployment-pipeline.yml | 13 ++++++ .gitlab/templates/status-report.yml | 51 +++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .gitlab/templates/status-report.yml diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 2b23f9645..62e5c5f05 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -15,7 +15,7 @@ variables: description: "The CI pipeline to run" FETCH_PUBLIC_MR: - value : "false" + value: "false" options: - "false" - "true" diff --git a/.gitlab/pipelines/deployment-pipeline.yml b/.gitlab/pipelines/deployment-pipeline.yml index 2fb032df3..5e661580f 100644 --- a/.gitlab/pipelines/deployment-pipeline.yml +++ b/.gitlab/pipelines/deployment-pipeline.yml @@ -15,6 +15,7 @@ stages: include: - local: .gitlab/templates/setup-workspace.yml + - local: .gitlab/templates/status-report.yml - local: .gitlab/templates/linting.yml - local: .gitlab/templates/static-analysis.yml - local: .gitlab/templates/unit-test.yml @@ -27,6 +28,18 @@ pull-mr: stage: .pre extends: .pull-mr +report-pipeline-start: + stage: .pre + extends: .report-pipeline-start + +report-pipeline-success: + stage: .post + extends: .report-pipeline-success + +report-pipeline-failure: + stage: .post + extends: .report-pipeline-failure + check-lint: extends: - .check-lint diff --git a/.gitlab/templates/status-report.yml b/.gitlab/templates/status-report.yml new file mode 100644 index 000000000..8b402ae1c --- /dev/null +++ b/.gitlab/templates/status-report.yml @@ -0,0 +1,51 @@ +# +# Arm SCP/MCP Software +# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +.report-status: + image: ${CI_REGISTRY_IMAGE}/ci-base:latest + script: + - | + curl --fail --location --request POST \ + "${PUBLIC_REPO_API_URL}/merge_requests/${FETCH_PUBLIC_MR_NUMBER}/notes" \ + --header "PRIVATE-TOKEN:${PUBLIC_REPO_API_KEY}" \ + --header "Content-Type:application/json" \ + --data-raw "{\"body\":\"CI Testing - Pipeline ${CI_PIPELINE_ID} - ${PIPELINE_STATUS_MSG}\"}" + +.report-pipeline-start: + extends: .report-status + variables: + PIPELINE_STATUS_MSG: "STARTED" + rules: + - if: $FETCH_PUBLIC_MR == "true" + +.report-pipeline-failure: + extends: .report-status + variables: + PIPELINE_STATUS_MSG: "FAILED" + after_script: + - | + echo "Status: FAILURE - Resseting approvals" + curl --fail --location --request PUT \ + --header "PRIVATE-TOKEN:${PUBLIC_REPO_API_KEY}" \ + "${PUBLIC_REPO_API_URL}/merge_requests/${FETCH_PUBLIC_MR_NUMBER}/reset_approvals" + when: on_failure + rules: + - if: $FETCH_PUBLIC_MR == "true" + +.report-pipeline-success: + extends: .report-status + variables: + PIPELINE_STATUS_MSG: "SUCCESS" + after_script: + - | + echo "Status: SUCCESS - MR Approved" + curl --fail --location --request POST \ + --header "PRIVATE-TOKEN:${PUBLIC_REPO_API_KEY}" \ + "${PUBLIC_REPO_API_URL}/merge_requests/${FETCH_PUBLIC_MR_NUMBER}/approve" + when: on_success + rules: + - if: $FETCH_PUBLIC_MR == "true" -- GitLab