Skip to content

Commit

Permalink
Refactor GitHub Actions workflow for Cypress E2E tests
Browse files Browse the repository at this point in the history
- Removed redundant log process termination.
- Reordered step to create a GitHub issue if failures are detected.
- Updated the SonarCloud scan action to use the latest SonarQube GitHub action.
  • Loading branch information
rustyjux committed Jan 6, 2025
1 parent e8a4060 commit 0f1d356
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions .github/workflows/aps-cypress-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ jobs:
while true; do
if [ "$(docker ps -aq -f status=exited -f name=cypress-e2e)" ]; then
echo "Cypress tests completed."
# Kill the log following process
kill $LOG_PID
# cleanup
docker compose down
break
Expand Down Expand Up @@ -90,9 +88,31 @@ jobs:
with:
name: astra-scan-results
path: ${{ github.workspace }}/e2e/cypress/fixtures/state/scanResult.json

- name: Check for failed tests and create Issue
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
FAILURE_COUNT=$(cat ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json | jq '.stats.failures')
if [[ "$FAILURE_COUNT" -gt 0 ]]; then
FAILED_TESTS=$(jq -r '
.results[] |
(.file | split("/") | .[2:] | join("/")) as $file |
.. |
.tests? // empty |
.[] |
select(.fail == true) |
"- " + $file + " - " + .title
' ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json)
STATS=$(cat ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json | jq -r '.stats | to_entries | map("\(.key)\t\(.value)") | .[]' | column -t)
echo -e "Stats: $STATS\n\nFailed Tests:\n$FAILED_TESTS\n\nRun Link: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" > msg
export MSG=$(cat msg)
gh issue create --title "FAILED: Automated Tests($FAILURE_COUNT)" --body "$MSG" --label "automation" --assignee "${{ env.GIT_COMMIT_AUTHOR }}"
exit 1
fi
- name: Instrument the code for coverage analysis
if: always()
run: |
# Rewrite the paths as the coverage starts with '../app'!
sed -e 's/..\/app/./g' ./e2e/coverage/lcov.info > lcov.info
Expand All @@ -102,8 +122,7 @@ jobs:
#npx nyc instrument --compact=false . --in-place
- name: SonarCloud Scan
if: always()
uses: sonarsource/sonarcloud-github-action@master
uses: sonarsource/sonarqube-scan-action@master
with:
args: >
-Dsonar.organization=bcgov-oss
Expand All @@ -117,29 +136,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: Check for failed tests and create Issue
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
FAILURE_COUNT=$(cat ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json | jq '.stats.failures')
if [[ "$FAILURE_COUNT" -gt 0 ]]; then
FAILED_TESTS=$(jq -r '
.results[] |
(.file | split("/") | .[2:] | join("/")) as $file |
.. |
.tests? // empty |
.[] |
select(.fail == true) |
"- " + $file + " - " + .title
' ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json)
STATS=$(cat ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json | jq -r '.stats | to_entries | map("\(.key)\t\(.value)") | .[]' | column -t)
echo -e "Stats: $STATS\n\nFailed Tests:\n$FAILED_TESTS\n\nRun Link: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" > msg
export MSG=$(cat msg)
gh issue create --title "FAILED: Automated Tests($FAILURE_COUNT)" --body "$MSG" --label "automation" --assignee "${{ env.GIT_COMMIT_AUTHOR }}"
exit 1
fi
- name: Set up Python 3.9
if: failure()
uses: actions/setup-python@v2
Expand Down

0 comments on commit 0f1d356

Please sign in to comment.