Skip to content

Commit 012e208

Browse files
aspeakeGitHub Action
and
GitHub Action
authored
Integration testing (#295)
* Upload "U.S. building energy efficiency and flexibility as an electric grid resource" Res and Com savings shapes (v2.1) * Add GH Actions workflow to run integration testing on self-hosted AWS EC2 runner * Ensure consistent sorting and precision in ecm_results file * Run integration test only if PR base branch is master * Upload results files from CI build --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 2a587ff commit 012e208

File tree

65 files changed

+2984877
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2984877
-7
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: integration-tests
2+
on: [workflow_call]
3+
jobs:
4+
start-runner:
5+
name: Start self-hosted EC2 runner
6+
runs-on: ubuntu-latest
7+
outputs:
8+
label: ${{ steps.start-ec2-runner.outputs.label }}
9+
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
10+
steps:
11+
- name: Configure AWS credentials
12+
uses: aws-actions/configure-aws-credentials@v2
13+
with:
14+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
15+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
16+
aws-region: ${{ secrets.AWS_REGION }}
17+
- name: Start EC2 runner
18+
id: start-ec2-runner
19+
uses: machulav/ec2-github-runner@v2
20+
with:
21+
mode: start
22+
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
23+
ec2-image-id: ami-0f57c48465f6361a6
24+
ec2-instance-type: r5a.4xlarge
25+
subnet-id: subnet-a4b769c3
26+
security-group-id: sg-06a2ae324a6e68d4d
27+
aws-resource-tags: >
28+
[
29+
{"Key": "Name", "Value": "scout-github-runner"},
30+
{"Key": "billingId", "Value": "210109"},
31+
{"Key": "org", "Value": "scout"}
32+
]
33+
34+
run-test:
35+
name: Integration Testing
36+
needs: start-runner
37+
runs-on: ${{ needs.start-runner.outputs.label }}
38+
steps:
39+
- uses: actions/checkout@v3
40+
with:
41+
ref: ${{ github.head_ref }}
42+
- name: Set up Python 3.10
43+
uses: actions/setup-python@v4
44+
with:
45+
python-version: '3.10'
46+
- name: Install Python dependencies
47+
run: |
48+
python -m pip install --upgrade pip
49+
pip install numpy>=1.16 pandas>=2.2 scipy requests numpy-financial matplotlib xlsxwriter
50+
- name: Run workflow
51+
run: python tests/integration_testing/run_workflow.py
52+
- name: Upload artifacts
53+
uses: actions/upload-artifact@v3
54+
with:
55+
name: results
56+
path: ./results/*.json
57+
- name: Commit test results
58+
run: |
59+
branch_name="${{ github.head_ref }}"
60+
git pull origin $branch_name
61+
cp -r ./results/*.json ./tests/integration_testing/results
62+
git add ./tests/integration_testing/*.json
63+
if [[ $(git diff --cached --exit-code) ]]; then
64+
git config --system user.email "[email protected]"
65+
git config --system user.name "GitHub Action"
66+
git commit -m "Upload results files from CI build"
67+
echo "Pushing to branch: $branch_name"
68+
git push -u origin $branch_name
69+
fi
70+
71+
stop-runner:
72+
name: Stop self-hosted EC2 runner
73+
needs:
74+
- start-runner # required to get output from the start-runner job
75+
- run-test # required to wait when the main job is done
76+
runs-on: ubuntu-latest
77+
if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
78+
steps:
79+
- name: Configure AWS credentials
80+
uses: aws-actions/configure-aws-credentials@v2
81+
with:
82+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
83+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
84+
aws-region: ${{ secrets.AWS_REGION }}
85+
- name: Stop EC2 runner
86+
uses: machulav/ec2-github-runner@v2
87+
with:
88+
mode: stop
89+
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
90+
label: ${{ needs.start-runner.outputs.label }}
91+
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}

.github/workflows/tests.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: tests
2-
on: [push]
2+
on:
3+
push:
34
jobs:
45

56
code-quality-checks:
@@ -49,5 +50,20 @@ jobs:
4950
- name: Run tests
5051
run: python -m unittest discover -p '*_test.py'
5152

53+
check-PR:
54+
# Check if there is a PR - allows one main workflow with dependency on previous jobs
55+
needs: [code-quality-checks, python-tests]
56+
runs-on: ubuntu-latest
57+
outputs:
58+
PR_status: ${{ steps.PR.outputs.pr_found }}
59+
PR: ${{ steps.PR.outputs.pr }}
60+
steps:
61+
- name: Check if PR
62+
uses: 8BitJonny/[email protected]
63+
id: PR
5264

53-
65+
integration-tests:
66+
needs: [check-PR]
67+
if: needs.check-PR.outputs.PR_status == 'true' && fromJSON(needs.check-PR.outputs.PR).base.ref == 'master'
68+
uses: ./.github/workflows/integration_tests.yml
69+
secrets: inherit

ecm_definitions/energyplus_data/savings_shapes/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)