diff --git a/.github/workflows/deploy-pm4.yml b/.github/workflows/deploy-pm4.yml index f21da3e3fb..f75e161801 100644 --- a/.github/workflows/deploy-pm4.yml +++ b/.github/workflows/deploy-pm4.yml @@ -278,8 +278,27 @@ jobs: else exit 1 fi' - kubectl exec -n $namespace $pod -- /bin/sh -c "pr_body='${pr_body}';${code}" && break || true + kubectl exec -n $namespace $pod -- /bin/sh -c "pr_body='${pr_body}';${code}" | tee /tmp/comment.md && break || true done + # Send the content of /tmp/comment.md as a PR comment + MESSAGE=$(cat /tmp/comment.md) + GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY=${{ github.repository }} + PR_NUMBER=$(jq -r .number < "$GITHUB_EVENT_PATH") + + if [ -z "$PR_NUMBER" ]; then + echo "The PR number is not available. Make sure this script is executed in a context of Pull Request." + exit 1 + fi + + URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" + json_payload=$(jq -n --arg message "$MESSAGE" '{"body": $message}') + + curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d "$json_payload" \ + "${URL}" deleteEKS: name: Delete Instance if: github.event.action == 'closed' diff --git a/.github/workflows/scripts/post_comment_to_pr.sh b/.github/workflows/scripts/post_comment_to_pr.sh new file mode 100755 index 0000000000..271e95d1cf --- /dev/null +++ b/.github/workflows/scripts/post_comment_to_pr.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Abort if any error occurs +set -e + +MESSAGE=$1 + +GITHUB_TOKEN=${GITHUB_TOKEN} +GITHUB_REPOSITORY=${GITHUB_REPOSITORY} +PR_NUMBER=${GITHUB_EVENT_PULL_REQUEST_NUMBER} + +# Check there is a PR number available +if [ -z "$PR_NUMBER" ]; then + echo "The PR number is not available. Make sure this script is executed in a context of Pull Request." + exit 1 +fi + +URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" +json_payload=$(jq -n --arg message "$MESSAGE" '{"body": $message}') + +# Send the message {body: MESSAGE} in json encoded +curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d "$json_payload" \ + "${URL}" \ No newline at end of file