diff --git a/.circleci/config.yml b/.circleci/config.yml index 6bd0267c60..03b3200300 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -111,9 +111,36 @@ jobs: cd /home/circleci/app/Packages/Application/Neos.Neos.Ui nvm install nvm use - make test-e2e-saucelabs - - store_artifacts: - path: /home/circleci/app/Data/Logs + make test-e2e-saucelabs > /home/circleci/app/Data/Logs/AcceptanceTesting.log + - persist_to_workspace: + root: /home/circleci/app/Data/Logs + paths: + - AcceptanceTesting.log + + post-acceptance-tests-recordings: + environment: + FLOW_CONTEXT: Production + docker: + - image: cimg/php:7.4.12-node + + steps: + - attach_workspace: + at: /home/circleci/app + - run: + name: Install GitHub CLI and jq + command: | + type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y) + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ + && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ + && sudo apt update \ + && sudo apt install gh -y + - run: + name: Run Script + command: | + JOB_IDS=$(cat /home/circleci/app/AcceptanceTesting.log | grep -o 'https://app.saucelabs.com/tests/[a-zA-Z0-9]\+' | sed 's/.*\///') + echo "Job IDs: $JOB_IDS" + /home/circleci/app/Build/comment-acceptance-tests.sh "$JOB_IDS" "$(basename "$CIRCLE_PULL_REQUEST")" php-unittests: environment: @@ -153,6 +180,9 @@ workflows: - e2e: requires: - build_flow_app + - post-acceptance-tests-recordings: + requires: + - e2e - php-unittests: requires: - build_flow_app diff --git a/Build/comment-acceptance-tests.sh b/Build/comment-acceptance-tests.sh new file mode 100755 index 0000000000..5973e58170 --- /dev/null +++ b/Build/comment-acceptance-tests.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# Check if the required parameters are provided +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +# If no comment with recordings exists, create a new comment +# create a function names createNewComment with the comment body as parameter + +function generateCommentBody() { + # Split the JobID string into an array + IFS=$'\n' read -r -d '' -a jobIdArray <<< "$jobIds" + echo "Generate comment message for following JobIDs: ${jobIdArray[@]}" + + # Iterate over each JobID in the array + for i in ${!jobIdArray[@]}; do + iterator=$(($i+1)) + jobId="${jobIdArray[$i]}" + link="[Recording $iterator](https://app.saucelabs.com/rest/v1/jobs/$jobId/video.mp4)" + videoRecordingsLinks+="\n* $link" + done + + # Construct the comment with the latest acceptance test recordings + # Construct the comment with the latest acceptance test recordings + if [ -n "$videoRecordingsLinks" ]; then + commentBody="🎥 **End-to-End Test Recordings**\n\n$videoRecordingsLinks\n\nThese videos demonstrate the end-to-end tests for the changes in this pull request." + else + # empty comment body to prevent a comment without recordings + commentBody="" + fi +} + +# Check if a comment with recordings already exists +function getExistingComment() { + echo "Checking if a comment with recordings already exists..." + existingComment=$(gh pr view --repo neos/neos-ui $pullRequestNumber --json comments | jq -r ".comments[] | select( .body | contains(\"End-to-End Test Recordings\"))") +} + +function createComment() { + echo "Creating new comment..." + gh pr comment --repo neos/neos-ui $pullRequestNumber --body "$(printf "$commentBody")" +} + +# If a comment with recordings exists, update the existing comment +function updateComment() { + # Note: The gh cli does not support editing comments yet, so we have to use the GitHub API directly + echo "Updating existing comment..." + commentUri=$(echo "$existingComment" | jq -r ".url") + commentId=$(echo "$commentUri" | awk -F'#issuecomment-' '{print $2}') + jsonBody=$(jq -n --arg str "$(printf "$commentBody")" '{"body": $str}') + + curl -s -H "Authorization: token $GH_TOKEN" \ + -X PATCH -d "$jsonBody" \ + "https://api.github.com/repos/neos/neos-ui/issues/comments/$commentId" +} + +jobIds=$1 +pullRequestNumber=$2 +generateCommentBody +getExistingComment + +echo "Existing comment: $existingComment" +if [ -n "$existingComment" ]; then + updateComment +else + createComment +fi + +echo "Comment added to Pull Request #$pullRequestNumber with the latest acceptance test recordings."