Skip to content

Commit 84e9af3

Browse files
committed
Initial v1.0.0 commit
0 parents  commit 84e9af3

File tree

108 files changed

+11531
-0
lines changed

Some content is hidden

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

108 files changed

+11531
-0
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
charset = utf-8
11+
end_of_line = lf
12+
13+
[*.bat]
14+
indent_style = tab
15+
end_of_line = crlf
16+
17+
[LICENSE]
18+
insert_final_newline = false
19+
20+
[Makefile]
21+
indent_style = tab
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: BuildandTest
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
BuildandTest:
8+
runs-on: ubuntu-22.04
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
with:
13+
token: ${{ secrets.QN_RO_PAT }}
14+
ref: OFC_demo
15+
path: quantnet_server
16+
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
token: ${{ secrets.QN_RO_PAT }}
21+
repository: quant-net/quant-net-mq
22+
ref: schema-updates
23+
path: quantnet_mq
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.11'
29+
architecture: 'x64'
30+
31+
- name: Display Python version
32+
run: |
33+
python -c "import sys; print(sys.version)"
34+
35+
- name: Start MongoDB
36+
uses: supercharge/mongodb-github-action@1.12.0
37+
with:
38+
mongodb-version: 8.0
39+
40+
- name: Build
41+
run: |
42+
ls -al
43+
cd quantnet_mq
44+
pip install -e .
45+
cd ../quantnet_server
46+
pip3 install -e .
47+
48+
- name: Tests
49+
run: |
50+
cd quantnet_server
51+
pytest -sv

.github/workflows/ci_cd.yml

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
name: CI/CD Test
2+
3+
on:
4+
schedule:
5+
- cron: '30 9 * * *' # Every day at midnight UTC
6+
workflow_dispatch: # Manual trigger
7+
8+
env:
9+
# Use docker.io for Docker Hub if empty
10+
REGISTRY: ghcr.io
11+
12+
# github.repository as <account>/<repo>
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
# Sign containers using cosign
16+
SIGN: false
17+
18+
# Set this to false to skip tests
19+
RUN_TESTS: true
20+
21+
jobs:
22+
build-test:
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 20 # Limit total job runtime to 4 minutes
25+
26+
permissions:
27+
contents: read
28+
issues: write
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v4
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: '3.10'
38+
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v3
41+
42+
- name: Clone quant-net-plugins repository
43+
run: |
44+
git clone --single-branch --branch develop https://${{secrets.QN_RO_PAT}}@github.com/quant-net/quant-net-plugins.git
45+
cp -r quant-net-plugins/plugins/schema ./conf/
46+
47+
# - name: Enable SSH agent
48+
# uses: webfactory/ssh-agent@v0.9.0
49+
# with:
50+
# ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
51+
52+
# - name: Set GitLab PyPI token
53+
# run: |
54+
# echo "PIP_EXTRA_INDEX_URL=https://__token__:${{ secrets.GITLAB_PAT }}@gitlab.es.net/api/v4/projects/939/packages/pypi/simple" >> $GITHUB_ENV
55+
- name: Log into registry ${{ env.REGISTRY }}
56+
uses: docker/login-action@v3
57+
with:
58+
registry: ${{ env.REGISTRY }}
59+
username: ${{ github.actor }}
60+
password: ${{ secrets.GHCR_TOKEN }}
61+
62+
- name: Build Docker containers
63+
run: |
64+
docker compose -f regression_tests/docker-compose.yml build --ssh default=${SSH_AUTH_SOCK}
65+
66+
- name: Start containers
67+
run: |
68+
ls -l regression_tests
69+
ls -l regression_tests/conf
70+
docker compose -f regression_tests/docker-compose.yml up -d
71+
72+
- name: Wait for containers to be ready
73+
run: |
74+
echo "Sleeping 30 seconds to allow services to start..."
75+
sleep 30
76+
docker compose -f regression_tests/docker-compose.yml ps
77+
docker compose -f regression_tests/docker-compose.yml logs --tail=50
78+
79+
80+
- name: Install dependencies for test
81+
run: |
82+
git clone --single-branch --branch develop https://${{secrets.QN_RO_PAT}}@github.com/quant-net/quant-net-mq.git quantnet-mq
83+
cd quantnet-mq && pip install --no-cache-dir .
84+
85+
- name: Run integration test and save output
86+
run: |
87+
RESULTS_FILE="test-results.txt"
88+
echo "@BinDong314 @youf3 @disprosium8" > "$RESULTS_FILE"
89+
echo "============================" >> "$RESULTS_FILE"
90+
echo "CI/CD Test Results - Run #${{ github.run_number }}" >> "$RESULTS_FILE"
91+
echo "Repository: ${{ github.repository }}" >> "$RESULTS_FILE"
92+
echo "Workflow: ${{ github.workflow }}" >> "$RESULTS_FILE"
93+
echo "Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> "$RESULTS_FILE"
94+
95+
echo "Check containers [before] running scripts: start" | tee -a "$RESULTS_FILE"
96+
chmod a+x ./regression_tests/scripts/check_container.sh
97+
./regression_tests/scripts/check_container.sh >> "$RESULTS_FILE" 2>&1
98+
EXIT_CODE=$?
99+
echo "Container check script finished with exit code: $EXIT_CODE" | tee -a "$RESULTS_FILE"
100+
echo "Check containers [before] running scripts: end" | tee -a "$RESULTS_FILE"
101+
102+
103+
# --- Initialization of python test cases---
104+
# An array to keep track of any tests that fail.
105+
declare -a FAILED_TESTS
106+
# A counter for the test number.
107+
TEST_NUM=1
108+
109+
# Clear the previous results file and write a header.
110+
echo "Starting regression tests on $(date)" >> "$RESULTS_FILE"
111+
echo "========================================" >> "$RESULTS_FILE"
112+
113+
# --- Test Execution Loop ---
114+
# Find all files ending in .py in the test directory and loop through them.
115+
for test_script in regression_tests/scripts/*.py; do
116+
# Extract just the filename from the full path.
117+
filename=$(basename "$test_script")
118+
119+
echo "" >> "$RESULTS_FILE"
120+
echo "Running Test #${TEST_NUM}: $filename"
121+
echo "--------------------------------" >> "$RESULTS_FILE"
122+
echo "Test #${TEST_NUM}: $filename" >> "$RESULTS_FILE"
123+
echo "--------------------------------" >> "$RESULTS_FILE"
124+
125+
# Allow the python script to fail without exiting the whole script.
126+
set +e
127+
128+
# Execute the python script, redirecting all output (stdout and stderr)
129+
# to the results file. The -u flag ensures unbuffered output.
130+
python -u "$test_script" >> "$RESULTS_FILE" 2>&1
131+
EXIT_CODE=$?
132+
133+
# Re-enable exiting on error.
134+
set -e
135+
136+
# Log the exit code to the results file.
137+
echo "" >> "$RESULTS_FILE"
138+
echo "Exit code: $EXIT_CODE" >> "$RESULTS_FILE"
139+
140+
# Check the exit code and report status.
141+
if [ $EXIT_CODE -ne 0 ]; then
142+
echo " -> FAILED with exit code $EXIT_CODE"
143+
# Add the failed script's name to our array of failures.
144+
FAILED_TESTS+=("$filename")
145+
else
146+
echo " -> PASSED"
147+
fi
148+
149+
# Increment the test counter.
150+
((TEST_NUM++))
151+
done
152+
153+
154+
# Check if the FAILED_TESTS array has any elements in it.
155+
if [ ${#FAILED_TESTS[@]} -ne 0 ]; then
156+
echo "SUMMARY: Failures detected in the following tests:"
157+
echo "SUMMARY: Failures detected!" >> "$RESULTS_FILE"
158+
# Loop through the array and print each failed test.
159+
for failed_test in "${FAILED_TESTS[@]}"; do
160+
echo " - $failed_test"
161+
echo " - $failed_test" >> "$RESULTS_FILE"
162+
done
163+
# Exit with a status of 1 to indicate failure, which is useful for CI/CD systems.
164+
exit 1
165+
else
166+
echo "✅ SUMMARY: All tests passed successfully!"
167+
echo "✅ SUMMARY: All tests passed successfully!" >> "$RESULTS_FILE"
168+
# Exit with a status of 0 to indicate success.
169+
#exit 0
170+
fi
171+
172+
echo "Check containers [after] running scripts: start"
173+
echo "Check containers [after] running scripts: start" >> "$RESULTS_FILE"
174+
./regression_tests/scripts/check_container.sh >> "$RESULTS_FILE" 2>&1
175+
EXIT_CODE=$?
176+
echo "Container check script finished with exit code: $EXIT_CODE" | tee -a "$RESULTS_FILE"
177+
echo "Check containers [after] running scripts: end"
178+
echo "Check containers [after] running scripts: end" >> "$RESULTS_FILE"
179+
180+
# --- Summary ---
181+
echo ""
182+
echo "========================================" >> "$RESULTS_FILE"
183+
echo "Test run complete." >> "$RESULTS_FILE"
184+
echo "========================================"
185+
186+
echo "Cat "$RESULTS_FILE" file for inspection if necessary"
187+
echo "======================Start Cat==============================="
188+
cat "$RESULTS_FILE"
189+
echo "======================End Cat==============================="
190+
191+
192+
- name: Upload test results artifact
193+
if: always()
194+
uses: actions/upload-artifact@v4
195+
with:
196+
name: test-results
197+
path: test-results.txt
198+
199+
- name: Create Failure Report
200+
if: failure() # This step ONLY runs if any previous step has failed.
201+
run: |
202+
# Check if the main test results file was NOT created.
203+
# This implies that a step BEFORE the tests failed.
204+
if [ ! -f "test-results.txt" ]; then
205+
echo "A setup step failed. Creating a failure summary."
206+
RESULTS_FILE="test-results.txt"
207+
echo "@BinDong314 @youf3 @disprosium8" > "$RESULTS_FILE"
208+
echo "" >> "$RESULTS_FILE"
209+
echo "### 🚨 CI/CD Workflow Failure - Run #${{ github.run_number }}" >> "$RESULTS_FILE"
210+
echo "**A critical error occurred before the integration tests could run.**" >> "$RESULTS_FILE"
211+
echo "" >> "$RESULTS_FILE"
212+
echo "Please check the workflow logs for details on the failed step." >> "$RESULTS_FILE"
213+
echo "" >> "$RESULTS_FILE"
214+
echo "**Workflow Run Link:** [${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> "$RESULTS_FILE"
215+
fi
216+
217+
#or if: failure()
218+
- name: Notify key developers on GitHub
219+
if: failure()
220+
uses: peter-evans/create-issue-from-file@v5
221+
with:
222+
title: "CI/CD Test Results - Run #${{ github.run_number }}"
223+
content-filepath: test-results.txt
224+
labels: ci-results
225+
env:
226+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
227+
# - name: Run integration test - pingpong
228+
# run: python regression_tests/ping.py
229+
230+
# - name: Run integration test - Single Photon Generation
231+
# run: python regression_tests/spg.py
232+
233+
- name: Tear down services
234+
if: always()
235+
run: docker compose -f regression_tests/docker-compose.yml down -v

0 commit comments

Comments
 (0)