From 65bb0a9940b2511104b4cafc5b8406fbc49ef9bb Mon Sep 17 00:00:00 2001 From: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:01:59 -0700 Subject: [PATCH] split jobs into unit and integration, split integration into 4 shards doc-only PRs skip integration skip-integration label skips integration --- .github/workflows/ci.yml | 98 ++++++++++++++++++- Gemfile.lock | 1 + README.md | 28 +++++- .../integration/write_and_run_osws_spec.rb | 13 +++ 4 files changed, 135 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d69b87f..ac19f54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,29 +2,119 @@ name: Continuous Integration on: pull_request: + types: [opened, synchronize, reopened, labeled, unlabeled] push: branches: - "develop" tags: - '*' + schedule: + - cron: '0 7 * * *' + workflow_dispatch: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true jobs: - tests: - name: Tests + unit: + name: unit container: nrel/openstudio:3.10.0 runs-on: ubuntu-latest + timeout-minutes: 20 env: LANG: C.UTF-8 LC_ALL: C.UTF-8 steps: - name: Checkout Code uses: actions/checkout@v4 + - name: Cache gems + uses: actions/cache@v4 + with: + path: .bundle/install + key: gems-${{ runner.os }}-os3.10.0-${{ hashFiles('Gemfile.lock', '*.gemspec') }} - name: Setup run: | git config --global --add safe.directory "$GITHUB_WORKSPACE" gem install bundler -v 2.4.10 bundle config set --local path "$GITHUB_WORKSPACE/.bundle/install" bundle install + - name: Run Unit Tests + run: bundle exec rspec spec/tests/unit --profile 10 + + changes: + name: detect changes + runs-on: ubuntu-latest + outputs: + code: ${{ steps.diff.outputs.code }} + steps: + - name: Checkout Code + if: github.event_name == 'pull_request' + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check for non-documentation changes + id: diff + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + if [ "${{ github.event_name }}" != "pull_request" ]; then + echo "code=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + # Documentation-only paths; anything else counts as a code change. + code_files=$(git diff --name-only "$BASE_SHA"..."$HEAD_SHA" \ + | grep -Ev '(\.md$|^docs/|^LICENSE)' || true) + if [ -n "$code_files" ]; then + echo "code=true" >> "$GITHUB_OUTPUT" + else + echo "code=false" >> "$GITHUB_OUTPUT" + fi + + integration: + name: integration (shard ${{ matrix.shard }}) + needs: changes + if: >- + needs.changes.outputs.code == 'true' && + !contains(github.event.pull_request.labels.*.name, 'skip-integration') + container: nrel/openstudio:3.10.0 + runs-on: ubuntu-latest + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + shard: [0, 1, 2, 3] + env: + LANG: C.UTF-8 + LC_ALL: C.UTF-8 + BOSS_SHARD: ${{ matrix.shard }} + BOSS_SHARDS: '4' + steps: + - name: Checkout Code + uses: actions/checkout@v4 + - name: Cache gems + uses: actions/cache@v4 + with: + path: .bundle/install + key: gems-${{ runner.os }}-os3.10.0-${{ hashFiles('Gemfile.lock', '*.gemspec') }} + - name: Cache external measures + uses: actions/cache@v4 + with: + path: vendor/external_measures + key: ext-measures-${{ hashFiles('config/external_measure_repos.yml') }} + - name: Setup + run: | + git config --global --add safe.directory '*' + gem install bundler -v 2.4.10 + bundle config set --local path "$GITHUB_WORKSPACE/.bundle/install" + bundle install bundle exec rake measures:install_external - - name: Run Tests - run: bundle exec rspec + - name: Run Integration Tests + run: bundle exec rspec spec/tests/integration --profile 10 + - name: Upload output on failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: integration-output-shard-${{ matrix.shard }} + path: spec/output diff --git a/Gemfile.lock b/Gemfile.lock index 1e540f6..9f58992 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -189,6 +189,7 @@ GEM PLATFORMS arm64-darwin-24 ruby + x64-mingw-ucrt DEPENDENCIES BOSS! diff --git a/README.md b/README.md index 0a8fad3..b598c6f 100644 --- a/README.md +++ b/README.md @@ -175,8 +175,34 @@ bundle exec boss write_baseline_osw "spec/files/v2.7.0/L100_Audit-1.0.0.xml" -o ## Tests -To run the tests you can use the Rake task: +Integration tests need the external measures installed first: + +```bash +bundle exec rake measures:install_external +``` + +Run the full suite (unit + all integration simulations): ```bash bundle exec rake ``` + +Run only the fast unit tests: + +```bash +bundle exec rspec spec/tests/unit +``` + +Run the integration smoke subset (2 simulations): + +```bash +BOSS_SMOKE=1 bundle exec rspec spec/tests/integration +``` + +Run one shard of the full integration suite (here shard 0 of 4, as in CI): + +```bash +BOSS_SHARD=0 BOSS_SHARDS=4 bundle exec rspec spec/tests/integration +``` + +In CI, unit tests run on every pull request. The full integration suite (4 parallel shards) also runs on every pull request, except documentation-only changes (`*.md`, `docs/`, `LICENSE`) or pull requests labeled `skip-integration`. It always runs on pushes to `develop`, tags, nightly, and on manual dispatch. diff --git a/spec/tests/integration/write_and_run_osws_spec.rb b/spec/tests/integration/write_and_run_osws_spec.rb index d45b4c3..8b0a4f1 100644 --- a/spec/tests/integration/write_and_run_osws_spec.rb +++ b/spec/tests/integration/write_and_run_osws_spec.rb @@ -34,6 +34,19 @@ ['Reference-PrimarySchool-L100-Audit.xml', ASHRAE90_1, nil, 'v2.7.0'], ] +# BOSS_SMOKE=1 runs a small representative subset (used on pull requests). +SMOKE_FILES = ['building_151.xml', 'example-smalloffice-level1.xml'].freeze +test_configs = test_configs.select { |config| SMOKE_FILES.include?(config[0]) } if ENV['BOSS_SMOKE'] == '1' + +# BOSS_SHARD / BOSS_SHARDS split the fixtures across parallel CI jobs. +if ENV['BOSS_SHARDS'] + shards = Integer(ENV['BOSS_SHARDS']) + shard = Integer(ENV.fetch('BOSS_SHARD', '0')) + raise ArgumentError, "BOSS_SHARD must be in 0...#{shards}" if shards < 1 || shard.negative? || shard >= shards + + test_configs = test_configs.select.with_index { |_config, index| index % shards == shard } +end + RSpec.describe 'BOSS' do describe 'boss should' do before do