-
Notifications
You must be signed in to change notification settings - Fork 1
120 lines (96 loc) · 3.58 KB
/
run-tests-on-gh.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Run Performance Tests
on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
changes:
runs-on: ubuntu-latest
outputs:
test-changes: ${{ steps.changes.outputs.test-sources }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Check if any source code has changed
id: changes
uses: dorny/paths-filter@v3
with:
filters: |
test-sources:
- 'src/**/*'
- '.github/workflows/run-tests-on-gh.yml'
- 'pom.xml'
- 'commit-report.sh'
build-and-test:
needs: changes
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || needs.changes.outputs.test-changes == 'true' }}
runs-on: ubuntu-latest
env:
SIMULATION_PRESET: standard
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Update the load configuration for PRS
if: github.event_name == 'pull_request'
run: |
echo "SIMULATION_PRESET=pull_request" >> $GITHUB_ENV
- name: Update the load configuration for commits
if: github.event_name == 'push'
run: |
echo "SIMULATION_PRESET=commit" >> $GITHUB_ENV
- name: Start an OpenMRS instance
run: docker compose -f src/test/resources/docker-compose.yml up -d
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '15'
- name: Install dependencies
run: ./mvnw install -DskipTests
- name: Wait for the OpenMRS instance to start
run: while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost/openmrs/login.htm)" != "200" ]]; do sleep 10; done
- name: Get System Information
run: |
# Get RAM information
total_ram=$(free -h | grep Mem | awk '{print $2}')
# Get number of CPUs
num_cpus=$(nproc)
# Get disk space information
total_disk=$(df -h / | grep / | awk '{print $2}')
# Format the description
description="Executed on a GitHub Actions runner with ${total_ram} RAM, ${num_cpus}CPUs, and ${total_disk} disk space."
# Set the description as an environment variable
echo "GATLING_RUN_DESCRIPTION=${description}" >> $GITHUB_ENV
- name: Run performance tests
run: ./mvnw gatling:test -Dgatling.runDescription="${{ env.GATLING_RUN_DESCRIPTION }}"
- name: Stop the OpenMRS instance
if: '!cancelled()'
run: docker stop $(docker ps -a -q)
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: report
path: target/gatling
retention-days: 30
# Publish the report to GH pages
- name: Set up Git
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit the report to the report branch
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
run: |
chmod +x commit-report.sh
./commit-report.sh
- name: Push changes
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
run: |
git push origin main:report -f