Conversation
organise CI flow to be easier to follow
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #50 +/- ##
=======================================
Coverage 47.61% 47.61%
=======================================
Files 3 3
Lines 42 42
Branches 4 4
=======================================
Hits 20 20
Misses 22 22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds CI coverage for testing this repository against both the latest MUSE2 release and a build from the MUSE2 main branch, factoring the setup/verification logic into reusable workflows and composite actions.
Changes:
- Refactors CI to call a reusable workflow that runs the test matrix against a selected MUSE2 source (
releaseormain). - Adds composite actions to (a) install MUSE2 from the latest release, (b) build/install MUSE2 from
main, and (c) verifyMUSE2_PATHis set. - Updates the main CI workflow to run both “release” and “main” test suites.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/test-with-muse2.yml |
New reusable workflow that installs deps, sets up MUSE2 (main/release), verifies, runs pytest, and uploads coverage for release/Linux. |
.github/workflows/ci.yml |
Refactors CI to run two jobs (release + main) via the reusable workflow. |
.github/actions/verify-muse2/action.yml |
New composite action to validate MUSE2_PATH. |
.github/actions/setup-muse2-release/action.yml |
New composite action to download/extract latest MUSE2 release asset and set MUSE2_PATH. |
.github/actions/setup-muse2-main/action.yml |
New composite action to cargo install MUSE2 from the main branch and set MUSE2_PATH. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - name: Setup MUSE2 from main | ||
| if: inputs.muse2_source == 'main' | ||
| uses: ./.github/actions/setup-muse2-main | ||
| with: | ||
| muse2_exe: ${{ matrix.muse2_exe }} |
There was a problem hiding this comment.
Because MUSE2 setup is entirely conditional on inputs.muse2_source, any unexpected value will skip both setup steps and then fail later in verify-muse2 with a misleading “executable not found” error. Consider adding an explicit validation step early in the job (and a clear error message) to enforce allowed values (e.g. main/release).
There was a problem hiding this comment.
unlikely to come up but I added a check anyway
| test_main: | ||
| name: Test against MUSE2 main | ||
| uses: ./.github/workflows/test-with-muse2.yml | ||
| with: | ||
| muse2_source: main | ||
| secrets: inherit |
There was a problem hiding this comment.
This adds a full “build MUSE2 from main” test job to the standard CI on every push/PR, but the PR description/issue calls out running the main-branch build periodically. If the intent is periodic coverage, consider gating test_main behind a schedule/manual trigger (or making it conditional) to avoid significantly increasing CI duration and external network/build load on every PR.
There was a problem hiding this comment.
you probably need this in PR's too though?
There was a problem hiding this comment.
Yeah, we def want it for PRs, but it would be good to also run this every week or so. We have an issue for this (#43) and I've taken the liberty of assigning you to it just now 😉.
You just need to add a cron trigger for the workflow.
There was a problem hiding this comment.
Could you do this in this PR while you're at it? It's just a small change to this file.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Is this ready for review? |
Should be, although I'm just going through the copilot responses now. Also, I'm not totally understanding what those three pending checks are in the CI, I remember seeing it before and it blocking merging. |
Ok cool. I'll hold off reviewing for a mo until you've had a look at those then.
They're there because they're the ones that are required for merging. If you change the names of the checks, then you'll see the names of the old ones there forever. It's fine. Once I've reviewed this and it's ready to merge, we can update the list of required checks. |
add early checks for muse2_source compatiable string and codecov token is present
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| secrets: | ||
| CODECOV_TOKEN: | ||
| required: false |
There was a problem hiding this comment.
CODECOV_TOKEN is declared as optional (required: false) for workflow_call, but the workflow later treats it as mandatory on Linux release runs. Either mark the secret as required, or make coverage upload conditional on the token being present (so forks/other callers without the secret can still run tests).
There was a problem hiding this comment.
I made it required so it fails early without it
| run: | | ||
| cargo install \ | ||
| --git https://github.com/EnergySystemsModellingLab/MUSE2 \ | ||
| --branch main \ |
There was a problem hiding this comment.
cargo install from a git repo should generally be run with --locked to ensure the build uses the repo's Cargo.lock (and fails if it's out of date) rather than implicitly updating dependencies, which can make CI flaky and less reproducible.
| --branch main \ | |
| --branch main \ | |
| --locked \ |
| @@ -1,4 +1,4 @@ | |||
| name: Test and build | |||
| name: Test against MUSE2 | |||
There was a problem hiding this comment.
The PR/issue description mentions running the MUSE2-main build periodically, but ci.yml doesn't add a schedule trigger (it only runs on push/PR/manual). Either add a cron schedule for the main-branch job or adjust the description/issue expectations.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - name: Setup MUSE2 from main | ||
| if: inputs.muse2_source == 'main' | ||
| uses: ./.github/actions/setup-muse2-main | ||
| with: | ||
| muse2_exe: ${{ matrix.muse2_exe }} | ||
|
|
||
| - name: Setup MUSE2 from latest release | ||
| if: inputs.muse2_source == 'release' | ||
| uses: ./.github/actions/setup-muse2-release |
There was a problem hiding this comment.
muse2_source controls which setup step runs, but the workflow never validates the input. Any unexpected value will skip both setup steps and then fail in verify-muse2 with a misleading “executable not found” error. Add an explicit validation step early in the job to enforce allowed values (e.g. main/release) and emit a clear error message before proceeding.
There was a problem hiding this comment.
there doesn't seem to be a nice way to do this within actions scripts, and I don't think it's super likely to cause an issue
all good now whenever you're ready |
alexdewar
left a comment
There was a problem hiding this comment.
Looking good! I've suggested a few tweaks.
| cargo install \ | ||
| --git https://github.com/EnergySystemsModellingLab/MUSE2 \ | ||
| --branch main \ | ||
| --root "$GITHUB_WORKSPACE/muse2_cargo_root" \ |
There was a problem hiding this comment.
I think the alternative is to point MUSE2_PATH at wherever the default root is instead ($HOME/.cargo/?), I don't have too much of a preference if you think that's better
There was a problem hiding this comment.
Ah, I see! Well, I think cargo will install muse2 so that it's on the PATH and then the code will be able to find it directly, without you having to set MUSE2_PATH. See:
I think that would be slightly cleaner.
| shell: pwsh | ||
| run: | | ||
| $exePath = "${{ github.workspace }}\muse2_cargo_root\bin\${{ inputs.muse2_exe }}" | ||
| echo "MUSE2_PATH=$exePath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
There was a problem hiding this comment.
You can use the bash shell on Windows too btw. I'm not sure about passing the exe file name to this Action though. I feel like it should "know" that it needs a .exe extension for Windows. Same for the other Action.
There was a problem hiding this comment.
I guess my resistance to this is that you would have to update the exe name in multiple places if we ever changed it for some reason... Not that that would be too cumbersome though, do you prefer just having the actual names if the os branches rather than inputs.muse2_exe?
There was a problem hiding this comment.
If you take my suggestion above, I don't think you'll need the name of the muse2 exe at all.
| TAG=$(curl -sSf \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer ${{ inputs.github_token }}" \ | ||
| https://api.github.com/repos/EnergySystemsModellingLab/MUSE2/releases/latest \ | ||
| | jq -r '.tag_name') | ||
|
|
||
| if [[ -z "$TAG" || "$TAG" == "null" ]]; then | ||
| echo "::error::Failed to retrieve latest MUSE2 release tag." | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
You can do all this stuff with the gh command, which is included with the default runners. The only thing is that I'm not sure if the GitHub token will be passed to it automatically for an Action (it is for workflows, via an env var).
This could all be done with:
gh release list --json name,isLatest --jq '.[] | select(.isLatest)|.name'
I'd be tempted to try it and, if it doesn't work, then you can figure out how to pass the token (I think you just set the GITHUB_TOKEN env var).
| curl -sSfL \ | ||
| "https://github.com/EnergySystemsModellingLab/MUSE2/releases/download/${{ steps.muse2_release.outputs.tag }}/${{ runner.os == 'Windows' && 'muse2_windows.zip' || runner.os == 'macOS' && 'muse2_macos_arm.tar.gz' || 'muse2_linux.tar.gz' }}" \ | ||
| --output "muse2_asset_download" |
There was a problem hiding this comment.
Similarly this could be:
gh release download $TAGThere was a problem hiding this comment.
This is much nicer, you don't even need the tag step anymore because it uses the latest release by default
| test_main: | ||
| name: Test against MUSE2 main | ||
| uses: ./.github/workflows/test-with-muse2.yml | ||
| with: | ||
| muse2_source: main | ||
| secrets: inherit |
There was a problem hiding this comment.
Yeah, we def want it for PRs, but it would be good to also run this every week or so. We have an issue for this (#43) and I've taken the liberty of assigning you to it just now 😉.
You just need to add a cron trigger for the workflow.
| - name: Setup MUSE2 from main | ||
| if: inputs.muse2_source == 'main' | ||
| uses: ./.github/actions/setup-muse2-main | ||
| with: | ||
| muse2_exe: ${{ matrix.muse2_exe }} | ||
|
|
||
| - name: Setup MUSE2 from latest release | ||
| if: inputs.muse2_source == 'release' | ||
| uses: ./.github/actions/setup-muse2-release |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| secrets: | ||
| CODECOV_TOKEN: | ||
| required: true | ||
|
|
There was a problem hiding this comment.
CODECOV_TOKEN is marked as a required secret for the reusable workflow. Because required workflow_call secrets are enforced at invocation time (even when the Codecov step is skipped), this makes all callers (including the muse2_source: main run) require the token and will cause CI to fail for PRs from forks where secrets aren’t available. Consider making CODECOV_TOKEN optional and additionally gating the Codecov upload step on the token being present (or moving coverage upload to a separate workflow that’s only invoked for release).
alexdewar
left a comment
There was a problem hiding this comment.
I've suggested a few more small things.
| cargo install \ | ||
| --git https://github.com/EnergySystemsModellingLab/MUSE2 \ | ||
| --branch main \ | ||
| --root "$GITHUB_WORKSPACE/muse2_cargo_root" \ |
There was a problem hiding this comment.
Ah, I see! Well, I think cargo will install muse2 so that it's on the PATH and then the code will be able to find it directly, without you having to set MUSE2_PATH. See:
I think that would be slightly cleaner.
| shell: pwsh | ||
| run: | | ||
| $exePath = "${{ github.workspace }}\muse2_cargo_root\bin\${{ inputs.muse2_exe }}" | ||
| echo "MUSE2_PATH=$exePath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
There was a problem hiding this comment.
If you take my suggestion above, I don't think you'll need the name of the muse2 exe at all.
| test_main: | ||
| name: Test against MUSE2 main | ||
| uses: ./.github/workflows/test-with-muse2.yml | ||
| with: | ||
| muse2_source: main | ||
| secrets: inherit |
There was a problem hiding this comment.
Could you do this in this PR while you're at it? It's just a small change to this file.
We were only testing the analysis tools against the latest releases of MUSE2 which won't be that frequent - therefore we wanted to also have testing against a build of the current main branch we can run periodically. I have added this to the CI and refactored a bit so it's hopefully easier to follow
Description
Close #25
Type of change
Key checklist
python -m pytest)pre-commit run --all-files)Further checks
(Indicate issue here: # (issue))