Skip to content

Commit 9e2dbf7

Browse files
authored
Update GitHub Actions conformance comment when target branch conformance report unavailable (#292)
1 parent 5f349a5 commit 9e2dbf7

File tree

3 files changed

+46
-192
lines changed

3 files changed

+46
-192
lines changed

.github/workflows/ci_build_test.yml

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: CI Build
33
on: [push, pull_request]
44

55
env:
6+
CARGO_TEST_RESULT_NAME: cargo_test_results.json
7+
CONFORMANCE_REPORT_NAME: cts_report.json
8+
COMPARISON_REPORT_NAME: cts-comparison-report.md
69
RUST_TEST_TIME_UNIT: 150,5000
710
RUST_TEST_TIME_INTEGRATION: 150,5000
811

@@ -102,14 +105,14 @@ jobs:
102105
# to format and use the output.
103106
- name: Cargo Test of the conformance tests (can fail) and save to json file
104107
continue-on-error: true
105-
run: cargo test --verbose --package partiql-conformance-tests --features "conformance_test" --release -- -Z unstable-options --ensure-time --format json > cargo_test_results.json
108+
run: cargo test --verbose --package partiql-conformance-tests --features "conformance_test" --release -- -Z unstable-options --ensure-time --format json > ${{ env.CARGO_TEST_RESULT_NAME }}
106109
# Create a conformance report from the `cargo test` json file
107-
- run: cargo run --features report_tool --bin generate_cts_report cargo_test_results.json ${GITHUB_SHA} cts_report.json
110+
- run: cargo run --features report_tool --bin generate_cts_report ${{ env.CARGO_TEST_RESULT_NAME }} ${GITHUB_SHA} ${{ env.CONFORMANCE_REPORT_NAME }}
108111
# Upload conformance report for comparison with future runs
109-
- name: Upload cts_report.json
112+
- name: Upload conformance report
110113
uses: actions/upload-artifact@v3
111114
with:
112-
path: cts_report.json
115+
path: ${{ env.CONFORMANCE_REPORT_NAME }}
113116
# Cache the `cargo build` and conformance report for `conformance-report-comparison` job (pull_request event only)
114117
- name: Cache `cargo build` and conformance report
115118
if: github.event_name == 'pull_request'
@@ -137,27 +140,46 @@ jobs:
137140
with:
138141
path: ./*
139142
key: ${{ github.sha }}-conformance-report
140-
# Download conformance report from `main` to create comparison report. If `main` has no report, use a backup
141-
# report (stored in partiql-conformance-tests/backup_conformance_report.json). Alternatively, we could consider
142-
# - pulling `main` branch and rerun the tests
143-
# - pulling latest release and rerun the tests
144-
# - compare to an empty file
145-
# - don't perform comparisons
146-
- name: Download cts_report.json from `main` branch
143+
# Download conformance report from target branch to create comparison report. If target branch has no conformance
144+
# report, pull down target branch and rebuild conformance report.
145+
- name: Download conformance report from target branch
147146
uses: dawidd6/action-download-artifact@v2
148147
id: download-report
149148
continue-on-error: true
150149
with:
151150
workflow: ci_build_test.yml
152-
branch: main
153-
- name: backup case if download fails
151+
commit: ${{ github.event.pull_request.base.sha }}
152+
# (If download of target branch report fails) Run the conformance tests (i.e. `cargo test`) and save to a JSON file.
153+
- name: (If download of target branch conformance report fails) Checkout target branch
154+
uses: actions/checkout@v3
154155
if: ${{ steps.download-report.outcome == 'failure' }}
155-
run: mkdir -p artifact && cp -r ./partiql-conformance-tests/backup_conformance_report.json ./artifact/cts_report.json
156-
# Run conformance report comparison. Generates cts-comparison-report.md
157-
- run: cargo run --features report_tool --bin generate_comparison_report ./artifact/cts_report.json cts_report.json cts-comparison-report.md
156+
with:
157+
submodules: recursive
158+
path: ${{ github.event.pull_request.base.sha }}
159+
ref: ${{ github.event.pull_request.base.sha }}
160+
- name: (If download of target branch conformance report fails) Run conformance tests for target branch
161+
if: ${{ steps.download-report.outcome == 'failure' }}
162+
continue-on-error: true
163+
run: |
164+
cd ${{ github.event.pull_request.base.sha }}
165+
cargo test --verbose --package partiql-conformance-tests --features "conformance_test" --release -- -Z unstable-options --ensure-time --format json > ${{ env.CARGO_TEST_RESULT_NAME }}
166+
- name: (If download of target branch conformance report fails) Generate conformance test report for target branch
167+
if: ${{ steps.download-report.outcome == 'failure' }}
168+
continue-on-error: true
169+
run: |
170+
cd ${{ github.event.pull_request.base.sha }}
171+
cargo run --features report_tool --bin generate_cts_report ${{ env.CARGO_TEST_RESULT_NAME }} ${GITHUB_SHA} ${{ env.CONFORMANCE_REPORT_NAME }}
172+
- name: (If download of target branch conformance report fails) Move conformance test report of target branch to ./artifact directory
173+
if: ${{ steps.download-report.outcome == 'failure' }}
174+
continue-on-error: true
175+
run: |
176+
mkdir -p $GITHUB_WORKSPACE/artifact
177+
cp -r $GITHUB_WORKSPACE/${{ github.event.pull_request.base.sha }}/$CONFORMANCE_REPORT_NAME $GITHUB_WORKSPACE/artifact/$CONFORMANCE_REPORT_NAME
178+
# Run conformance report comparison. Generates comparison report
179+
- run: cargo run --features report_tool --bin generate_comparison_report ./artifact/${{ env.CONFORMANCE_REPORT_NAME }} ${{ env.CONFORMANCE_REPORT_NAME }} ${{ env.COMPARISON_REPORT_NAME }}
158180
# Print conformance report to GitHub actions workflow summary page
159181
- name: print markdown in run
160-
run: cat cts-comparison-report.md >> $GITHUB_STEP_SUMMARY
182+
run: cat ${{ env.COMPARISON_REPORT_NAME }} >> $GITHUB_STEP_SUMMARY
161183
# Find comment w/ conformance comparison if previous comment published
162184
- name: Find Comment
163185
uses: peter-evans/find-comment@v2
@@ -174,5 +196,5 @@ jobs:
174196
with:
175197
comment-id: ${{ steps.fc.outputs.comment-id }}
176198
issue-number: ${{ github.event.pull_request.number }}
177-
body-file: cts-comparison-report.md
199+
body-file: ${{ env.COMPARISON_REPORT_NAME }}
178200
edit-mode: replace

0 commit comments

Comments
 (0)