CI/CD workflow to merge and upload consolidated test reports #96
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
name: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
permissions: | |
issues: write | |
contents: read | |
jobs: | |
setup: | |
name: Setup | |
runs-on: ubuntu-latest | |
outputs: | |
cache-hit: ${{ steps.node-with-cache.outputs.cache-hit }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js with node_modules cache | |
id: node-with-cache | |
uses: actions/cache@v4 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install npm packages | |
run: npm ci | |
linting: | |
name: Linting | |
runs-on: ubuntu-latest | |
needs: setup | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18.x | |
- name: Use cached node_modules | |
run: npm ci --cache ~/.npm | |
- name: Run ESLint and generate report | |
run: npm run lint | |
- name: Annotate Code Linting Results | |
uses: ataylorme/eslint-annotate-action@v3 | |
with: | |
report-json: 'lint_report.json' | |
- name: Upload ESLint report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: lint_report.json | |
path: lint_report.json | |
retention-days: 5 | |
e2e-testing: | |
name: E2E Testing | |
runs-on: ubuntu-latest | |
needs: linting | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18.x | |
- name: Use cached node_modules | |
run: npm ci --cache ~/.npm | |
- name: Build application | |
run: npm run build | |
- name: Start server | |
run: npm run start & | |
- name: Wait for server to start | |
run: npx wait-on http://localhost:3000 | |
- name: Run tests | |
run: npx cypress run --reporter junit --reporter-options mochaFile=reports/TEST-[hash].xml | |
# - name: Generate testing report | |
# run: | | |
# npx mochawesome-merge "cypress/reports/*.json" > report.json | |
# npx marge report.json --reportFilename "e2e_testing_report" --reportTitle "E2E Testing Report" --reportPageTitle "E2E Testing Report" | |
# - name: Upload testing report | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: e2e_testing_report | |
# path: mochawesome-report | |
# retention-days: 5 | |
- name: Python setup | |
if: always() | |
uses: actions/setup-python@v3 | |
with: | |
python-version: '3.x' | |
- name: Upload testing results to TestRail | |
if: always() | |
run: | | |
pip install trcli | |
junitparser merge --glob "reports/TEST-*" "reports/junit-report.xml" | |
trcli -y \ | |
-h https://lukamlinaric.testrail.io/ \ | |
--project "TestOps PoC" \ | |
-u "${{ secrets.TESTRAIL_EMAIL }}" \ | |
-p "${{ secrets.TESTRAIL_PASS }}" \ | |
parse_junit \ | |
--title "E2E Tests from CI/CD Pipeline" \ | |
--run-description ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} \ | |
-f "reports/junit-report.xml" | |
security-testing: | |
name: Security Testing | |
runs-on: ubuntu-latest | |
outputs: | |
full_scan_result: ${{ steps.store_full_scan_result.outputs.full_scan_result }} | |
needs: e2e-testing | |
services: | |
app: | |
image: quiirex/nowted-app:latest | |
ports: | |
- 3000:3000 | |
steps: | |
- name: ZAP Full Scan | |
id: full_scan | |
uses: zaproxy/action-full-scan@v0.10.0 | |
with: | |
target: 'http://app:3000' | |
- name: Store Full Scan Result | |
id: store_full_scan_result | |
run: | | |
mkdir -p full_scan_results | |
mv *.html full_scan_results/ || true | |
FULL_RESULT_FILE=$(find full_scan_results -name "*.html" -type f) | |
echo "::set-output name=full_scan_result::$FULL_RESULT_FILE" | |
- name: Upload Full Scan Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: security_testing_report | |
path: ${{ steps.store_full_scan_result.outputs.full_scan_result }} | |
retention-days: 5 | |
# performance-testing: | |
# name: Performance Testing | |
# runs-on: ubuntu-latest | |
# needs: security-testing | |
# steps: | |
# - name: Checkout repository | |
# uses: actions/checkout@v4 | |
# - name: Setup Node.js | |
# uses: actions/setup-node@v4 | |
# with: | |
# node-version: 18.x | |
# - name: Use cached node_modules | |
# run: npm ci --cache ~/.npm | |
# - name: Build application | |
# run: npm run build | |
# - name: Start server | |
# run: npm run start & | |
# - name: Wait for server to start | |
# run: npx wait-on http://localhost:3000 | |
# - name: Run k6 tests | |
# run: npm run performance | |
# - name: Upload k6 performance reports | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: performance-testing-reports | |
# path: performance-testing-reports | |
# notifications: | |
# name: Notifications | |
# runs-on: ubuntu-latest | |
# needs: [setup, linting, e2e-testing, security-testing, performance-testing] | |
# steps: | |
# - name: Notify Slack | |
# uses: 8398a7/action-slack@v3 | |
# with: | |
# status: ${{ job.status }} | |
# author_name: GitHub Actions | |
# fields: repo,message,commit,author,action,eventName,ref,workflow,job,took | |
# env: | |
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
# - name: Notify Email | |
# uses: dawidd6/action-send-mail@v2 | |
# with: | |
# server_address: smtp.gmail.com | |
# server_port: 465 | |
# username: ${{ secrets.EMAIL_USERNAME }} | |
# password: ${{ secrets.EMAIL_PASSWORD }} | |
# subject: 'CI/CD Pipeline Notification' | |
# body: 'The CI/CD pipeline has completed successfully.' | |
# to: ${{ secrets.EMAIL_TO }} | |
# from: ${{ secrets.EMAIL_FROM }} | |
# attachments: 'lint_report.json, mochawesome-report, full_scan_results, performance-testing-reports' |