|
6 | 6 | build:
|
7 | 7 | name: Build and Test
|
8 | 8 | runs-on: ${{ matrix.os }}
|
9 |
| - # We want to run on external PRs, but not on internal ones as push automatically builds |
10 |
| - # H/T: https://github.com/Dart-Code/Dart-Code/commit/612732d5879730608baa9622bf7f5e5b7b51ae65 |
11 |
| - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'partiql/partiql-lang-rust' |
12 | 9 | strategy:
|
13 | 10 | matrix:
|
14 | 11 | os: [ubuntu-latest, windows-latest, macos-latest]
|
|
77 | 74 | # Adding comments to the PR requires the GITHUB_TOKEN secret.
|
78 | 75 | token: ${{ secrets.GITHUB_TOKEN }}
|
79 | 76 | args: --all-features
|
| 77 | + # Cache the `cargo build` so future jobs can reuse build |
| 78 | + - name: Cache cargo build |
| 79 | + if: matrix.os == 'ubuntu-latest' |
| 80 | + uses: actions/cache@v2 |
| 81 | + id: restore-build |
| 82 | + with: |
| 83 | + path: ./* |
| 84 | + key: ${{ github.sha }} |
| 85 | + # Conformance report generation and comparison report generation job will run only after the `Build and Test` job |
| 86 | + # succeeds. |
| 87 | + conformance: |
| 88 | + name: Check conformance |
| 89 | + runs-on: ubuntu-latest |
| 90 | + needs: [build] |
| 91 | + steps: |
| 92 | + # Pull down the cached `partiql-lang-rust` build from the `Build and Test` job. This allows us to reuse without |
| 93 | + # needing to rebuild. If pulling the build fails, the subsequent `cargo test` will rebuild. |
| 94 | + - uses: actions/checkout@v2 |
| 95 | + with: |
| 96 | + submodules: recursive |
| 97 | + - name: Rust Toolchain |
| 98 | + uses: actions-rs/toolchain@v1 |
| 99 | + with: |
| 100 | + profile: minimal |
| 101 | + toolchain: stable |
| 102 | + override: true |
| 103 | + - uses: actions/cache@v2 |
| 104 | + id: restore-build |
| 105 | + with: |
| 106 | + path: ./* |
| 107 | + key: ${{ github.sha }} |
| 108 | + # Run the conformance tests (i.e. `cargo test`) and save to a json file. This uses the "format" unstable compile |
| 109 | + # option to save as json. In the future, may want to use the `cargo_metadata` crate (https://crates.io/crates/cargo_metadata) |
| 110 | + # to format and use the output. |
| 111 | + - name: Cargo Test of the conformance tests (can fail) and save to json file |
| 112 | + continue-on-error: true |
| 113 | + run: cargo test --verbose --package partiql-conformance-tests --features "conformance_test" -- -Z unstable-options --format json > cargo_test_results.json |
| 114 | + # Create a conformance report from the `cargo test` json file |
| 115 | + - run: ./target/debug/generate_cts_report cargo_test_results.json ${GITHUB_SHA} cts_report.json |
| 116 | + # Upload conformance report for comparison with future runs |
| 117 | + - name: Upload cts_report.json |
| 118 | + uses: actions/upload-artifact@v3 |
| 119 | + with: |
| 120 | + path: cts_report.json |
| 121 | + # Download conformance report from `main` to create comparison report. If `main` has no report, use a backup |
| 122 | + # report (stored in partiql-conformance-tests/backup_conformance_report.json). Alternatively, we could consider |
| 123 | + # - pulling `main` branch and rerun the tests |
| 124 | + # - pulling latest release and rerun the tests |
| 125 | + # - compare to an empty file |
| 126 | + # - don't perform comparisons |
| 127 | + - name: Download cts_report.json from `main` branch |
| 128 | + uses: dawidd6/action-download-artifact@v2 |
| 129 | + id: download-report |
| 130 | + continue-on-error: true |
| 131 | + with: |
| 132 | + workflow: ci_build_test.yml |
| 133 | + branch: main |
| 134 | + - name: backup case if download fails |
| 135 | + if: ${{ steps.download-report.outcome == 'failure' }} |
| 136 | + run: mkdir -p main-branch-report && cp -r ./partiql-conformance-tests/backup_conformance_report.json ./main-branch-report/cts_report.json |
| 137 | + # Run conformance report comparison. Generates cts-comparison-report.md |
| 138 | + - run: ./target/debug/generate_comparison_report ./main-branch-report/cts_report.json cts_report.json cts-comparison-report.md |
| 139 | + # Print conformance report to GitHub actions workflow summary page |
| 140 | + - name: print markdown in run |
| 141 | + run: cat cts-comparison-report.md >> $GITHUB_STEP_SUMMARY |
| 142 | + # Find comment w/ conformance comparison if previous comment published |
| 143 | + - name: Find Comment |
| 144 | + uses: peter-evans/find-comment@v2 |
| 145 | + id: fc |
| 146 | + if: github.event_name == 'pull_request' |
| 147 | + with: |
| 148 | + issue-number: ${{ github.event.pull_request.number }} |
| 149 | + comment-author: 'github-actions[bot]' |
| 150 | + body-includes: Conformance |
| 151 | + # Convert the markdown comparison report to a readable form for GitHub PR comments |
| 152 | + - id: get-comment-body |
| 153 | + run: | |
| 154 | + body="$(cat ./cts-comparison-report.md)" |
| 155 | + body="${body//'%'/'%25'}" |
| 156 | + body="${body//$'\n'/'%0A'}" |
| 157 | + body="${body//$'\r'/'%0D'}" |
| 158 | + echo "::set-output name=body::$body" |
| 159 | + # Create or update (if previous comment exists) with markdown version of comparison report |
| 160 | + - name: Create or update comment |
| 161 | + uses: peter-evans/create-or-update-comment@v2 |
| 162 | + if: github.event_name == 'pull_request' |
| 163 | + with: |
| 164 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 165 | + issue-number: ${{ github.event.pull_request.number }} |
| 166 | + body: ${{ steps.get-comment-body.outputs.body }} |
| 167 | + edit-mode: replace |
0 commit comments