Skip to content

| Staging | Regression Pack | #1298

| Staging | Regression Pack |

| Staging | Regression Pack | #1298

name: "| Staging | Regression Pack |"
on:
schedule:
- cron: "00 00 * * *"
workflow_dispatch:
jobs:
cypress-run:
environment: trade-tariff
env:
CYPRESS_BASE_URL: "https://staging.trade-tariff.service.gov.uk"
CYPRESS_ADMIN_OTP_SECRET: ${{ secrets.ADMIN_OTP_SECRET }}
CYPRESS_ADMIN_PASSWORD: ${{ secrets.CYPRESS_ADMIN_PASSWORD }}
CYPRESS_ADMIN_USERNAME: ${{ secrets.CYPRESS_ADMIN_USERNAME }}
CYPRESS_STAGING_ADMIN_SUFFIX: "staging"
CYPRESS_SPACE: "STAGING"
CYPRESS_STAGING_BASIC_AUTH: ${{ secrets.CYPRESS_STAGING_BASIC_AUTH }}
CYPRESS_STAGING_BASIC_PASSWORD: ${{ secrets.CYPRESS_STAGING_BASIC_PASSWORD }}
CYPRESS_STAGING_BASIC_USERNAME: ${{ secrets.CYPRESS_STAGING_BASIC_USERNAME }}
CYPRESS_grepTags: "-smokeTest+-notStaging"
name: "RegressionTests - Staging"
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
containers: [0, 1, 2, 3]
outputs:
output0: ${{ steps.cypress-outcome.outputs.test-status-0 }}
output1: ${{ steps.cypress-outcome.outputs.test-status-1 }}
output2: ${{ steps.cypress-outcome.outputs.test-status-2 }}
output3: ${{ steps.cypress-outcome.outputs.test-status-3 }}
steps:
- run: date
- name: Checkout repository code
uses: actions/checkout@v4
- name: Generate lists of specs
id: speclist
run: |
find cypress/e2e -type f -name '*.cy.js' > all_specs.txt
split -n l/4 -d -a 1 all_specs.txt spec_group_
echo "specfiles=$(paste -d, -s spec_group_${{ matrix.containers }})" >> $GITHUB_OUTPUT
- name: Run cypress tests with chrome
id: cypress
uses: cypress-io/github-action@v6
continue-on-error: true
with:
spec: ${{ steps.speclist.outputs.specfiles }}
quiet: true
browser: chrome
- name: Cypress test outcome
id: cypress-outcome
run: |
echo "test-status-${{ matrix.containers }}=${{ steps.cypress.outcome }}" >> $GITHUB_OUTPUT
- name: Upload E2E test reports
uses: actions/upload-artifact@v4
with:
name: test-reports-${{ matrix.containers }}
path: ./cypress/reports/
gen-report:
name: Generate test report
needs: cypress-run
if: always()
runs-on: ubuntu-22.04
outputs:
date-output: ${{ steps.date.outputs.date }}
steps:
- name: Get current date
id: date
run: echo "date=$(date +'%d-%m-%Y')" >> $GITHUB_OUTPUT
- name: Install dependencies
run: npm install --save-dev mochawesome mochawesome-merge mochawesome-report-generator
- name: Create reports directory
run: mkdir reports
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: test-reports-0
path: reports/0
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: test-reports-1
path: reports/1
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: test-reports-2
path: reports/2
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: test-reports-3
path: reports/3
- name: Move reports to mochawesome-report directory
run: |
mkdir -p mochawesome-report
for container in {0..3}; do
download_path=reports/$container
for file in $(find $download_path -type f -name 'mochawesome*.json'); do
mv "$file" mochawesome-report/$(basename "$file" .json)-"$container".json
done
done
- name: Merge and generate reports
run: |
mkdir report
npx mochawesome-merge mochawesome-report/*.json > report/index.json
npx marge --inline report/index.json -o report/
- name: Upload report
uses: actions/upload-artifact@v4
with:
name: E2E Test Reports
path: report/
- name: Checkout reports repo
uses: actions/checkout@v4
with:
ref: reports
path: reports_repo
- name: Copy report into reports repo
run: |
cd reports_repo
DATE=$(date +%d-%m-%Y)
[ -e docs/staging/$DATE ] && rm -rf docs/staging/$DATE
cp -a ../report/ docs/staging/$DATE
pushd docs/staging/$DATE
rm -rf assets
rm -rf screenshots
ln -s ../../assets/
popd
git add docs .
- name: Commit todays report to reports branch
run: |
cd reports_repo
git config --local user.email "tradetarrif+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "Staging report for $(date +%d-%m-%Y)" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: reports
directory: reports_repo
notify-slack:
name: Send slack notification based on test results
needs: [cypress-run, gen-report]
if: always()
runs-on: ubuntu-22.04
steps:
- name: Determine test outcome
id: determine-outcome
run: |
if [[ "${{ needs.cypress-run.outputs.output0 }}" == "success" && "${{ needs.cypress-run.outputs.output1 }}" == "success" && "${{ needs.cypress-run.outputs.output2 }}" == "success" && "${{ needs.cypress-run.outputs.output3 }}" == "success" ]]; then
echo "result=success" >> $GITHUB_OUTPUT
else
echo "result=failure" >> $GITHUB_OUTPUT
fi
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: "tariffs-regression"
SLACK_USERNAME: "Staging Regression"
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_ICON_EMOJI: ":alphabet-yellow-s:"
SLACK_COLOR: ${{ steps.determine-outcome.outputs.result }}
SLACK_TITLE: Cypress finished with - ${{ steps.determine-outcome.outputs.result }}
SLACK_MESSAGE: https://trade-tariff.github.io/trade-tariff-testing/staging/${{ needs.gen-report.outputs.date-output }}/