From d6e4482458373718e4efddfd8f31d24d3dbaeca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 25 Jan 2024 11:00:10 +0100 Subject: [PATCH 1/9] TASK: Extract job ID from saucelabs --- .circleci/config.yml | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6bd0267c60..fae5032fb0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -111,9 +111,27 @@ 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 + + extract_job_id: + environment: + FLOW_CONTEXT: Production + docker: + - image: cimg/php:7.4.12-node + + steps: + - attach_workspace: + at: /home/circleci/app/Data/Logs + - run: + name: Extract Job ID + command: | + # Extract job ID from the output file + job_id=$(cat /home/circleci/app/Data/Logs/AcceptanceTesting.log | grep -o 'https://app.saucelabs.com/tests/[a-zA-Z0-9]\+' | sed 's/.*\///') + echo "Job ID: $job_id" php-unittests: environment: @@ -153,6 +171,9 @@ workflows: - e2e: requires: - build_flow_app + - extract_job_id: + requires: + - e2e - php-unittests: requires: - build_flow_app From 3f9d7c7361075763803750cdca78010bcba7e2f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 25 Jan 2024 16:53:45 +0100 Subject: [PATCH 2/9] TASK: Use script to comment the PR --- .circleci/config.yml | 12 +++++-- Build/comment-acceptance-tests.sh | 58 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100755 Build/comment-acceptance-tests.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index fae5032fb0..a14af80667 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -126,12 +126,20 @@ jobs: steps: - attach_workspace: at: /home/circleci/app/Data/Logs + - run: + name: Install GitHub CLI and jq + command: | + sudo apt-get update && sudo apt-get install -y gh jq - run: name: Extract Job ID command: | # Extract job ID from the output file - job_id=$(cat /home/circleci/app/Data/Logs/AcceptanceTesting.log | grep -o 'https://app.saucelabs.com/tests/[a-zA-Z0-9]\+' | sed 's/.*\///') - echo "Job ID: $job_id" + JOB_IDS=$(cat /home/circleci/app/Data/Logs/AcceptanceTesting.log | grep -o 'https://app.saucelabs.com/tests/[a-zA-Z0-9]\+' | sed 's/.*\///') + echo "Job IDs: $JOB_IDS" + - run: + name: Run Script + command: | + ./Build/comment-acceptance-tests.sh $JOB_IDS $CIRCLE_PULL_REQUEST php-unittests: environment: diff --git a/Build/comment-acceptance-tests.sh b/Build/comment-acceptance-tests.sh new file mode 100755 index 0000000000..005e9152e8 --- /dev/null +++ b/Build/comment-acceptance-tests.sh @@ -0,0 +1,58 @@ +#!/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=' ' read -ra jobIdArray <<< "$jobIds" + + # 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 + 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." +} + +# Check if a comment with recordings already exists +function getExistingComment() { + existingComment=$(gh pr view --repo neos/neos-ui $pullRequestNumber --json comments | jq -r ".comments[] | select( .body | contains(\"Linked recordings of the acceptance tests\"))") +} + +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() { + # Todo: The gh cli does not support editing comments yet, so we have to use the GitHub API directly + echo "Updating existing comment..." + comment_uri=$(echo "$existing_comment" | jq -r ".url") + gh pr comment $comment_uri --body "$(printf "$commentBody")" +} + +jobIds=$1 +pullRequestNumber=$2 +generateCommentBody +getExistingComment + +if [ -n "$existingComment" ]; then + # @todo: use updateComment once the gh cli supports editing comments or we use the Github API directly + createComment +else + createComment +fi + +echo "Comment added to Pull Request #$pullRequestNumber with the latest acceptance test recordings." From 17a32c0fd2f091db86a6ad9b796bdaa07e64a60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 25 Jan 2024 17:43:22 +0100 Subject: [PATCH 3/9] TASK: Install gh cli --- .circleci/config.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a14af80667..b761c80f9f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -111,7 +111,7 @@ jobs: cd /home/circleci/app/Packages/Application/Neos.Neos.Ui nvm install nvm use - make test-e2e-saucelabs > /home/circleci/app/Data/Logs/AcceptanceTesting.log + echo "https://app.saucelabs.com/tests/be95eefb0a9d4cff8198cc5a7fda3e68 https://app.saucelabs.com/tests/c15e654b87aa406da257e29d7927ba1b" > /home/circleci/app/Data/Logs/AcceptanceTesting.log - persist_to_workspace: root: /home/circleci/app/Data/Logs paths: @@ -125,11 +125,16 @@ jobs: steps: - attach_workspace: - at: /home/circleci/app/Data/Logs + at: /home/circleci/app - run: name: Install GitHub CLI and jq command: | - sudo apt-get update && sudo apt-get install -y gh jq + 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: Extract Job ID command: | From 164bca7a07e45c8fc797ebbb38b81d3bc423699c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 25 Jan 2024 17:49:14 +0100 Subject: [PATCH 4/9] TASK: Fix indention --- Build/comment-acceptance-tests.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Build/comment-acceptance-tests.sh b/Build/comment-acceptance-tests.sh index 005e9152e8..1cba1b93de 100755 --- a/Build/comment-acceptance-tests.sh +++ b/Build/comment-acceptance-tests.sh @@ -15,10 +15,10 @@ function generateCommentBody() { # 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" + 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 @@ -27,7 +27,7 @@ function generateCommentBody() { # Check if a comment with recordings already exists function getExistingComment() { - existingComment=$(gh pr view --repo neos/neos-ui $pullRequestNumber --json comments | jq -r ".comments[] | select( .body | contains(\"Linked recordings of the acceptance tests\"))") + existingComment=$(gh pr view --repo neos/neos-ui $pullRequestNumber --json comments | jq -r ".comments[] | select( .body | contains(\"Linked recordings of the acceptance tests\"))") } function createComment() { From 174039777189e131038a2c69406275feca34f4b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 25 Jan 2024 18:03:01 +0100 Subject: [PATCH 5/9] BUGFIX: Adjust pathes --- .circleci/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b761c80f9f..58f01c3a99 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -139,12 +139,13 @@ jobs: name: Extract Job ID command: | # Extract job ID from the output file - JOB_IDS=$(cat /home/circleci/app/Data/Logs/AcceptanceTesting.log | grep -o 'https://app.saucelabs.com/tests/[a-zA-Z0-9]\+' | sed 's/.*\///') + 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" - run: name: Run Script command: | - ./Build/comment-acceptance-tests.sh $JOB_IDS $CIRCLE_PULL_REQUEST + cd /home/circleci/app + ./Build/comment-acceptance-tests.sh "$JOB_IDS" "$(basename "$CIRCLE_PULL_REQUEST")" php-unittests: environment: From 721e508ed4c91e25a9b3ff117be7f86de6bf8b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 25 Jan 2024 19:12:46 +0100 Subject: [PATCH 6/9] TASK: Update comments when we have new recordings --- Build/comment-acceptance-tests.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Build/comment-acceptance-tests.sh b/Build/comment-acceptance-tests.sh index 1cba1b93de..86eeabac38 100755 --- a/Build/comment-acceptance-tests.sh +++ b/Build/comment-acceptance-tests.sh @@ -22,12 +22,20 @@ function generateCommentBody() { done # Construct the comment with the latest acceptance test recordings - 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." + # 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() { - existingComment=$(gh pr view --repo neos/neos-ui $pullRequestNumber --json comments | jq -r ".comments[] | select( .body | contains(\"Linked recordings of the acceptance tests\"))") + echo "Checking if a comment with recordings already exists..." + echo "Pull Request Number: $pullRequestNumber" + existingComment=$(gh pr view --repo neos/neos-ui $pullRequestNumber --json comments | jq -r ".comments[] | select( .body | contains(\"End-to-End Test Recordings\"))") } function createComment() { @@ -37,10 +45,13 @@ function createComment() { # If a comment with recordings exists, update the existing comment function updateComment() { - # Todo: The gh cli does not support editing comments yet, so we have to use the GitHub API directly + # Note: The gh cli does not support editing comments yet, so we have to use the GitHub API directly echo "Updating existing comment..." - comment_uri=$(echo "$existing_comment" | jq -r ".url") - gh pr comment $comment_uri --body "$(printf "$commentBody")" + commentUri=$(echo "$existingComment" | jq -r ".url") + commentId=$(echo "$commentUri" | awk -F'#issuecomment-' '{print $2}') + curl -s -H "Authorization: token $GH_TOKEN" \ + -X PATCH -d "{\"body\":\"$(printf "$commentBody")\"}" \ + "https://api.github.com/repos/neos/neos-ui/issues/comments/$commentId" } jobIds=$1 @@ -48,9 +59,10 @@ pullRequestNumber=$2 generateCommentBody getExistingComment +echo "Existing comment: $existingComment" if [ -n "$existingComment" ]; then - # @todo: use updateComment once the gh cli supports editing comments or we use the Github API directly - createComment + echo "Updating existing comment..." + updateComment else createComment fi From ff94c495582c1e2898228709a37999058b9a861f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 25 Jan 2024 20:15:33 +0100 Subject: [PATCH 7/9] BUGFIX: Use all job IDs from the e2e step --- .circleci/config.yml | 9 ++------- Build/comment-acceptance-tests.sh | 12 +++++++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 58f01c3a99..6c3faace37 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -136,16 +136,11 @@ jobs: && sudo apt update \ && sudo apt install gh -y - run: - name: Extract Job ID + name: Run Script command: | - # Extract job ID from the output file 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" - - run: - name: Run Script - command: | - cd /home/circleci/app - ./Build/comment-acceptance-tests.sh "$JOB_IDS" "$(basename "$CIRCLE_PULL_REQUEST")" + /home/circleci/app/Build/comment-acceptance-tests.sh "$JOB_IDS" "$(basename "$CIRCLE_PULL_REQUEST")" php-unittests: environment: diff --git a/Build/comment-acceptance-tests.sh b/Build/comment-acceptance-tests.sh index 86eeabac38..657be7d4b7 100755 --- a/Build/comment-acceptance-tests.sh +++ b/Build/comment-acceptance-tests.sh @@ -11,14 +11,18 @@ fi function generateCommentBody() { # Split the JobID string into an array - IFS=' ' read -ra jobIdArray <<< "$jobIds" + IFS=$'\n' read -r -d '' -a jobIdArray <<< "$jobIds" + echo "JobID: $jobIds" + echo "JobID Array: ${jobIdArray[@]}" # Iterate over each JobID in the array for i in ${!jobIdArray[@]}; do iterator=$(($i+1)) jobId="${jobIdArray[$i]}" + echo "JobID: $jobId" link="[Recording $iterator](https://app.saucelabs.com/rest/v1/jobs/$jobId/video.mp4)" videoRecordingsLinks+="\n* $link" + echo "Video Recording Link: $link" done # Construct the comment with the latest acceptance test recordings @@ -49,8 +53,11 @@ function updateComment() { 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}') + echo "Comment JSON: $jsonBody" + echo "Comment ID: $commentId" curl -s -H "Authorization: token $GH_TOKEN" \ - -X PATCH -d "{\"body\":\"$(printf "$commentBody")\"}" \ + -X PATCH -d "$jsonBody" \ "https://api.github.com/repos/neos/neos-ui/issues/comments/$commentId" } @@ -61,7 +68,6 @@ getExistingComment echo "Existing comment: $existingComment" if [ -n "$existingComment" ]; then - echo "Updating existing comment..." updateComment else createComment From dacd1638c706e486b9680bf8f5b9e9990cae6b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 25 Jan 2024 22:22:13 +0100 Subject: [PATCH 8/9] TASK: Remove debug messages and readd saucelabs test --- .circleci/config.yml | 2 +- Build/comment-acceptance-tests.sh | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6c3faace37..a2827ddaaf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -111,7 +111,7 @@ jobs: cd /home/circleci/app/Packages/Application/Neos.Neos.Ui nvm install nvm use - echo "https://app.saucelabs.com/tests/be95eefb0a9d4cff8198cc5a7fda3e68 https://app.saucelabs.com/tests/c15e654b87aa406da257e29d7927ba1b" > /home/circleci/app/Data/Logs/AcceptanceTesting.log + make test-e2e-saucelabs > /home/circleci/app/Data/Logs/AcceptanceTesting.log - persist_to_workspace: root: /home/circleci/app/Data/Logs paths: diff --git a/Build/comment-acceptance-tests.sh b/Build/comment-acceptance-tests.sh index 657be7d4b7..5973e58170 100755 --- a/Build/comment-acceptance-tests.sh +++ b/Build/comment-acceptance-tests.sh @@ -12,17 +12,14 @@ fi function generateCommentBody() { # Split the JobID string into an array IFS=$'\n' read -r -d '' -a jobIdArray <<< "$jobIds" - echo "JobID: $jobIds" - echo "JobID Array: ${jobIdArray[@]}" + 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]}" - echo "JobID: $jobId" link="[Recording $iterator](https://app.saucelabs.com/rest/v1/jobs/$jobId/video.mp4)" videoRecordingsLinks+="\n* $link" - echo "Video Recording Link: $link" done # Construct the comment with the latest acceptance test recordings @@ -38,7 +35,6 @@ function generateCommentBody() { # Check if a comment with recordings already exists function getExistingComment() { echo "Checking if a comment with recordings already exists..." - echo "Pull Request Number: $pullRequestNumber" existingComment=$(gh pr view --repo neos/neos-ui $pullRequestNumber --json comments | jq -r ".comments[] | select( .body | contains(\"End-to-End Test Recordings\"))") } @@ -54,8 +50,7 @@ function updateComment() { commentUri=$(echo "$existingComment" | jq -r ".url") commentId=$(echo "$commentUri" | awk -F'#issuecomment-' '{print $2}') jsonBody=$(jq -n --arg str "$(printf "$commentBody")" '{"body": $str}') - echo "Comment JSON: $jsonBody" - echo "Comment ID: $commentId" + curl -s -H "Authorization: token $GH_TOKEN" \ -X PATCH -d "$jsonBody" \ "https://api.github.com/repos/neos/neos-ui/issues/comments/$commentId" From 859bcc1e6e1c1fe7978f45894730018a085ee258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Thu, 25 Jan 2024 23:05:53 +0100 Subject: [PATCH 9/9] TASK: Rename job --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a2827ddaaf..03b3200300 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -117,7 +117,7 @@ jobs: paths: - AcceptanceTesting.log - extract_job_id: + post-acceptance-tests-recordings: environment: FLOW_CONTEXT: Production docker: @@ -180,7 +180,7 @@ workflows: - e2e: requires: - build_flow_app - - extract_job_id: + - post-acceptance-tests-recordings: requires: - e2e - php-unittests: