Skip to content

Commit

Permalink
TASK: Extract job ID from saucelabs (#3698)
Browse files Browse the repository at this point in the history
* TASK: Extract job ID from saucelabs

* TASK: Use script to comment the PR

* TASK: Install gh cli

* TASK: Fix indention

* BUGFIX: Adjust pathes

* TASK: Update comments when we have new recordings

* BUGFIX: Use all job IDs from the e2e step

* TASK: Remove debug messages and readd saucelabs test

* TASK: Rename job
  • Loading branch information
markusguenther authored Jan 30, 2024
1 parent b34d35b commit 7031363
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 3 deletions.
36 changes: 33 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -153,6 +180,9 @@ workflows:
- e2e:
requires:
- build_flow_app
- post-acceptance-tests-recordings:
requires:
- e2e
- php-unittests:
requires:
- build_flow_app
71 changes: 71 additions & 0 deletions Build/comment-acceptance-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

# Check if the required parameters are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <JobID> <PullRequestNumber>"
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."

0 comments on commit 7031363

Please sign in to comment.