Skip to content

Commit

Permalink
debug workflow file
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Oct 23, 2024
1 parent 9537a2a commit d4be641
Showing 1 changed file with 83 additions and 27 deletions.
110 changes: 83 additions & 27 deletions .github/workflows/tests_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@ name: RAVS TESTS - DEV
on:
push:
branches:
- '**'
- '**' # Triggers on push to any branch
pull_request:
branches:
- '**'
- '**' # Triggers on PR to any branch
schedule:
- cron: "30 7 * * *"
- cron: "30 7 * * *"
workflow_dispatch:
inputs:
environment:
description: 'Environment (e.g., dev, qa)'
required: true
type: choice
options:
- dev
- qa

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -37,18 +30,14 @@ jobs:
- name: Build the Docker image
run: docker build -t playwright-tests -f Docker/tests.dockerfile .

- name: Print environment variable for debugging
run: |
echo "Running tests in environment: ${{ github.event.inputs.environment }}"
- name: Run Docker container
id: run-container
run: |
docker run -d --name playwright-tests \
--memory 8g \
-e RAVS_PASSWORD="${{ secrets.RAVS_PASSWORD }}" \
-e HEADLESS_MODE="true" \
-e TEST_ENVIRONMENT="${{ github.event.inputs.environment }}" \
-e TEST_ENVIRONMENT="dev" \
-e BROWSER="chrome" \
-e MARKER="" \
-e AGENTS=3 \
Expand All @@ -64,39 +53,89 @@ jobs:
fi
done
- name: Start Docker container
run: |
docker start playwright-tests
sleep 5
- name: Find and upload Allure report directory
run: |
container_id=$(docker ps -qf "name=playwright-tests")
echo "Container ID: $container_id"
allure_directory=$(docker exec $container_id find / -path /proc -prune -o -type d -name "allure-report" -print -quit)
echo "Allure Directory: $allure_directory"
if [[ -n "$allure_directory" ]]; then
echo "ALLURE_DIRECTORY=$allure_directory" >> $GITHUB_ENV
# Create a temporary directory to store the contents
temp_dir="$(mktemp -d)"
echo "Temporary Directory: $temp_dir"
# Copy the contents of allure_directory to the temporary directory
docker cp "$container_id":"$allure_directory"/. "$temp_dir"
(cd "$(dirname "$temp_dir")" && tar -czf allure-report-${{ github.event.inputs.environment }}.tar.gz -C "$(basename "$temp_dir")" .)
echo "::set-output name=allure_report_archive::$(realpath "$(dirname "$temp_dir")/allure-report-${{ github.event.inputs.environment }}.tar.gz")"
echo "ALLURE_REPORT_ARCHIVE=$(realpath "$(dirname "$temp_dir")/allure-report-${{ github.event.inputs.environment }}.tar.gz")" >> $GITHUB_ENV
# Archive the contents of the temporary directory
(cd "$(dirname "$temp_dir")" && tar -czf allure-report.tar.gz -C "$(basename "$temp_dir")" .)
# Set the path of Allure report archive as output
echo "::set-output name=allure_report_archive::$(realpath "$(dirname "$temp_dir")/allure-report.tar.gz")"
# Set the environment variable for the archive path
export ALLURE_REPORT_ARCHIVE=$(realpath "$(dirname "$temp_dir")/allure-report.tar.gz")
echo "ALLURE_REPORT_ARCHIVE=$ALLURE_REPORT_ARCHIVE" >> $GITHUB_ENV
# Check if tar was generated successfully
if [ $? -eq 0 ]; then
echo "Tar archive generated successfully."
# Echo the path of the tar file
echo "Path of the tar file: $ALLURE_REPORT_ARCHIVE"
# List the contents of the tar file
tar -tf "$ALLURE_REPORT_ARCHIVE"
else
echo "Failed to generate tar archive."
fi
else
echo "Allure directory not found or is empty."
fi
- name: Upload Allure report archive
uses: actions/upload-artifact@v4
with:
name: allure-report-${{ github.event.inputs.environment }}
name: allure-report
path: ${{ env.ALLURE_REPORT_ARCHIVE }}

- name: Retrieve and extract Allure report artifact
uses: actions/download-artifact@v4
with:
name: allure-report-${{ github.event.inputs.environment }}
path: allure-report-${{ github.event.inputs.environment }}
name: allure-report
path: allure-report

- name: List contents of the downloaded artifact
run: |
ls -l allure-report
- name: Unzip the tar file
run: |
tar -xzvf allure-report-${{ github.event.inputs.environment }}/allure-report-${{ github.event.inputs.environment }}.tar.gz -C allure-report-${{ github.event.inputs.environment }}
tar -xzvf allure-report/allure-report.tar.gz -C allure-report
- name: List contents after unzipping
run: |
ls -l allure-report
# Move the Allure report files to the root of the gh-pages directory
- name: Move Allure report files
run: |
mv allure-report-${{ github.event.inputs.environment }}/* .
mv allure-report/* .
- name: Upload Attachments
uses: actions/upload-artifact@v3
with:
name: screenshots
path: data/attachments/**
if-no-files-found: warn
include-hidden-files: false

- name: Get branch name
id: get_branch_name
Expand All @@ -111,14 +150,31 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: .
destination_branch: gh-pages-${{ github.event.inputs.environment }}
destination_branch: gh-pages-dev

- name: Check contents of gh-pages
run: ls -la

- name: Get GitHub Pages URL
id: pages-url
uses: actions/github-script@v7
with:
script: |
const repo = context.repo.repo;
const owner = context.repo.owner;
const branchName = context.ref.split('/').pop(); // Use the branch name you want to reference
const pagesUrl = `https://${owner}.github.io/${repo}/gh-pages-${branchName}`; // Use backticks for template literals
core.setOutput('pages_url', pagesUrl);
- name: Output GitHub Pages URL
run: |
echo "GitHub Pages URL: https://nhsdigital.github.io/ravs-tests/#"
echo "GitHub Pages URL: ${{ steps.pages-url.outputs.pages_url }}"
- name: Clean up
run: docker stop $(docker ps -q) || true

- name: Notify Slack on success
if: success()
run: |
BRANCH_NAME=$(echo $GITHUB_REF | sed 's|refs/heads/||')
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Ravs tests finished running for the ${{ github.event.inputs.environment }} environment on branch $BRANCH_NAME! Check the Allure report: https://nhsdigital.github.io/ravs-tests/gh-pages-${{ github.event.inputs.environment }}/\"}" ${{ secrets.SLACK_WEBHOOK_URL }}
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Ravs tests finished running for the DEV environment on branch $BRANCH_NAME! Check the Allure report: https://nhsdigital.github.io/ravs-tests/#\"}" ${{ secrets.SLACK_WEBHOOK_URL }}

0 comments on commit d4be641

Please sign in to comment.