Skip to content

| Production | Regression Pack | #303

| Production | Regression Pack |

| Production | Regression Pack | #303

name: "| Production | Regression Pack |"
on:
schedule:
- cron: "00 00 * * *"
workflow_dispatch:
jobs:
cypress-run:
environment: trade-tariff
env:
CYPRESS_BASE_URL: "https://www.trade-tariff.service.gov.uk"
CYPRESS_SPACE: "PRODUCTION"
CYPRESS_grepTags: "-devOnly+-smokeTest+-notProduction+-adminOnly"
name: "🚦 Regression Tests - UK and XI"
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 test-reports-0
uses: actions/download-artifact@v4
with:
name: test-reports-0
path: reports/0
- name: Download test-reports-1
uses: actions/download-artifact@v4
with:
name: test-reports-1
path: reports/1
- name: Download test-reports-2
uses: actions/download-artifact@v4
with:
name: test-reports-2
path: reports/2
- name: Download test-reports-3
uses: actions/download-artifact@v4
with:
name: test-reports-3
path: reports/3
- name: Move all reports into one directory
run: |
mkdir -p mochawesome-report
i=0
for file in $(find reports -type f -name mochawesome\*.json); do
filename=$(basename "$file" .json)-"$i".json
mv "$file" mochawesome-report/"$filename"
ls mochawesome-report
i=$((i + 1))
done
- name: Merge and generate reports
run: |
mkdir report
npx mochawesome-merge > 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/production/$DATE ] && rm -rf docs/production/$DATE
cp -a ../report/ docs/production/$DATE
pushd docs/production/$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 "Production 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: "Production 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/production/${{ needs.gen-report.outputs.date-output }}/