-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'e2e-tests' into 'master'
Add e2e Playwright tests to gitlab CI See merge request kchat/webapp!783
- Loading branch information
Showing
94 changed files
with
10,191 additions
and
4,926 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require 'net/http' | ||
require 'uri' | ||
require 'json' | ||
|
||
CI_ACCESS_TOKEN = ENV['GITLAB_API_TOKEN'] | ||
CI_API_BASE = ENV['CI_API_V4_URL'] | ||
CI_MERGE_REQUEST_IID = ENV['CI_MERGE_REQUEST_IID'] | ||
CI_PAGES_PREFIX = ENV['PAGES_PREFIX'] | ||
CI_PAGES_URL = ENV['CI_PAGES_URL'] | ||
CI_PROJECT_ID = ENV['CI_PROJECT_ID'] | ||
GUILD_WEBHOOK_URL = ENV['GUILD_WEBHOOK_URL'] | ||
|
||
# Function to send a message to kChat | ||
def send_to_kchat(msg) | ||
uri = URI(GUILD_WEBHOOK_URL) | ||
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') | ||
|
||
message = <<-MESSAGE | ||
#{msg} | ||
MESSAGE | ||
req.body = { text: message }.to_json | ||
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| | ||
http.request(req) | ||
end | ||
|
||
unless res.is_a?(Net::HTTPSuccess) | ||
raise "HTTP Request to kChat failed: #{res.body}" | ||
end | ||
end | ||
|
||
# Assert if an e2e report note has already been sent by the dev-bot | ||
def has_e2e_report_note() | ||
uri = URI("#{CI_API_BASE}/projects/#{CI_PROJECT_ID}/merge_requests/#{CI_MERGE_REQUEST_IID}/notes?per_page=1000") | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = (uri.scheme == 'https') | ||
|
||
request = Net::HTTP::Get.new(uri.request_uri, 'PRIVATE-TOKEN' => CI_ACCESS_TOKEN) | ||
response = http.request(request) | ||
|
||
unless response.is_a?(Net::HTTPSuccess) | ||
raise "Failed to get notes from Merge Request IID #{merge_request_iid}: #{response.body}" | ||
end | ||
|
||
# Parse the notes | ||
notes = JSON.parse(response.body) | ||
|
||
# Find the note with the staging URL posted by dev_bot | ||
report_note = notes.find do |note| | ||
note['author']['username'] == 'dev_bot' && note['body'].include?("E2E report is now available at") | ||
end | ||
|
||
# Cast to boolean | ||
return report_note ? true : false | ||
end | ||
|
||
# Notify about the new available pages url | ||
def create_e2e_report_note(message) | ||
uri = URI.parse("#{CI_API_BASE}/projects/#{CI_PROJECT_ID}/merge_requests/#{CI_MERGE_REQUEST_IID}/notes") | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = (uri.scheme == 'https') | ||
|
||
request = Net::HTTP::Post.new(uri.path, { 'PRIVATE-TOKEN' => CI_ACCESS_TOKEN }) | ||
request.set_form_data({ 'body' => message }) | ||
|
||
response = http.request(request) | ||
|
||
unless response.is_a?(Net::HTTPSuccess) | ||
raise "Failed to create note for Merge Request IID #{CI_MERGE_REQUEST_IID}: #{response.body}" | ||
end | ||
end | ||
|
||
# Main execution flow | ||
if !has_e2e_report_note() | ||
message = "E2E report is now available at #{CI_PAGES_URL}/#{CI_PAGES_PREFIX}" | ||
create_e2e_report_note(message) | ||
send_to_kchat(message) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'net/http' | ||
require 'uri' | ||
require 'json' | ||
|
||
CI_API_BASE = ENV['CI_API_V4_URL'] | ||
CI_PROJECT_ID = ENV['CI_PROJECT_ID'] | ||
CI_ACCESS_TOKEN = ENV['GITLAB_API_TOKEN'] | ||
CI_MERGE_REQUEST_IID = ENV['CI_MERGE_REQUEST_IID'] | ||
|
||
# Function to parse the staging URL from the comments | ||
def get_staging_url() | ||
uri = URI("#{CI_API_BASE}/projects/#{CI_PROJECT_ID}/merge_requests/#{CI_MERGE_REQUEST_IID}/notes?per_page=1000") | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = (uri.scheme == 'https') | ||
|
||
request = Net::HTTP::Get.new(uri.request_uri, 'PRIVATE-TOKEN' => CI_ACCESS_TOKEN) | ||
response = http.request(request) | ||
|
||
unless response.is_a?(Net::HTTPSuccess) | ||
raise "Failed to get notes from Merge Request IID #{CI_MERGE_REQUEST_IID}: #{response.body}" | ||
end | ||
|
||
# Parse the notes | ||
notes = JSON.parse(response.body) | ||
|
||
# Find the note with the staging URL posted by dev_bot | ||
staging_note = notes.find do |note| | ||
note['author']['username'] == 'dev_bot' && note['body'].include?("Staging is now available at") | ||
end | ||
|
||
# Extract the URL if the note is found, or return 'none' | ||
if staging_note | ||
match = staging_note['body'].match(/Staging is now available at (\S+)/) | ||
match[1] if match | ||
else | ||
'none' | ||
end | ||
end | ||
|
||
# Main execution flow | ||
puts get_staging_url() |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
# SC2034: <variable> appears unused. | ||
# https://www.shellcheck.net/wiki/SC2034 | ||
# shellcheck disable=SC2034 | ||
|
||
set -e -u -o pipefail | ||
cd "$(dirname "$0")" | ||
. .e2erc | ||
|
||
# Default required variables, assert that they are set, and document optional variables | ||
: ${FULL_REPORT:=false} # Valid values: true, false | ||
: ${TYPE:=NONE} # Valid values: PR, RELEASE, MASTER, MASTER_UNSTABLE, CLOUD, CLOUD_UNSTABLE, NONE (which is the same as omitting it) | ||
: ${WEBHOOK_URL:-} # Optional. Mattermost webhook to post the report back to | ||
: ${RELEASE_DATE:-} # Optional. If set, its value will be included in the report as the release date of the tested artifact | ||
|
||
# Env vars used during the test. Their values will be included in the report | ||
: ${BRANCH:?} | ||
: ${BUILD_ID:?} | ||
: ${MM_ENV:-} | ||
|
||
# Populate intermediate variables | ||
export BUILD_TAG="${SERVER_IMAGE##*/}" | ||
export MM_DOCKER_IMAGE="${BUILD_TAG%%:*}" # NB: the 'mattermostdevelopment/' prefix is assumed | ||
export MM_DOCKER_TAG="${BUILD_TAG##*:}" | ||
export SERVER_TYPE="${SERVER}" | ||
# NB: assume that BRANCH follows the convention 'server-pr-${PR_NUMBER}'. If multiple PRs match, the last one is used to generate the link | ||
# Only needed if TYPE=PR | ||
export PULL_REQUEST="https://github.com/mattermost/mattermost/pull/${BRANCH##*-}" | ||
|
||
if [ -n "${TM4J_API_KEY:-}" ]; then | ||
export TM4J_ENABLE=true | ||
export JIRA_PROJECT_KEY=MM | ||
export TM4J_ENVIRONMENT_NAME="${TEST}/${BROWSER}/${SERVER}" | ||
case "${SERVER}" in | ||
cloud) | ||
export TM4J_FOLDER_ID="2014474" ;; | ||
*) | ||
export TM4J_FOLDER_ID="2014475" ;; | ||
esac | ||
: ${TEST_CYCLE_LINK_PREFIX:?} | ||
: ${TM4J_CYCLE_KEY:-} | ||
: ${TM4J_CYCLE_NAME:-} | ||
mme2e_log "TMJ4 integration enabled." | ||
fi | ||
|
||
if [ -n "${DIAGNOSTIC_WEBHOOK_URL:-}" ]; then | ||
: ${DIAGNOSTIC_USER_ID:?} | ||
: ${DIAGNOSTIC_TEAM_ID:?} | ||
mme2e_log "Diagnostic report upload enabled." | ||
fi | ||
|
||
if [ -n "${AWS_S3_BUCKET:-}" ]; then | ||
: ${AWS_ACCESS_KEY_ID:?} | ||
: ${AWS_SECRET_ACCESS_KEY:?} | ||
mme2e_log "S3 report upload enabled." | ||
fi | ||
|
||
cd ../cypress/ | ||
if [ ! -d "results/" ]; then | ||
mme2e_log "Error: 'results/' directory does not exist. Aborting report generation." >&2 | ||
exit 1 | ||
fi | ||
|
||
npm i | ||
node save_report.js |
Oops, something went wrong.