From e9f12851e1e0f45f3cc85a22eab72d64cdf7b1b3 Mon Sep 17 00:00:00 2001 From: Abel Soares Siqueira Date: Tue, 6 May 2025 14:25:58 +0200 Subject: [PATCH] Fix CompareMPS when files differ in length If the files had different length, the script prints errors, but was not returning errors. This returns the correct exit flag. We also update the message to make it easier to find the comment and try to avoid duplicate CompareMPS messages. Finally, we clarify that forks won't have the messages. Closes #1188 --- .github/workflows/CompareMPS.yml | 22 +++++++++++----------- docs/src/91-developer.md | 2 +- utils/scripts/model-mps-compare.jl | 1 + 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/CompareMPS.yml b/.github/workflows/CompareMPS.yml index 220b65fa..a06dba64 100644 --- a/.github/workflows/CompareMPS.yml +++ b/.github/workflows/CompareMPS.yml @@ -28,7 +28,7 @@ jobs: with: issue-number: ${{ github.event.pull_request.number }} comment-author: "github-actions[bot]" - body-includes: This was CompareMPS + body-includes: CompareMPS report - name: Comment on PR with CompareMPS if: github.event.pull_request.head.repo.full_name == github.repository uses: peter-evans/create-or-update-comment@v4 @@ -36,11 +36,11 @@ jobs: comment-id: ${{ steps.find-old-comment.outputs.comment-id }} issue-number: ${{ github.event.pull_request.number }} body: | + ## :robot: CompareMPS report + ### :hourglass: Running MPS comparison Please wait. - - :robot: This was CompareMPS, we hope you have enjoyed this program. edit-mode: replace - name: Clone uses: actions/checkout@v4 @@ -59,9 +59,11 @@ jobs: - name: Create PR body if: failure() run: | - echo '## :warning: MPS files differ + echo '## :robot: CompareMPS report + + ### :warning: MPS files differ - ### What to do? + What to do? #### :+1: If this is expected @@ -71,7 +73,7 @@ jobs: julia --project=. utils/scripts/model-mps-update.jl ``` - #### :-1: This is bad + #### :-1: If this is bad Then, review the log below to figure out why the files differ: @@ -84,8 +86,6 @@ jobs: For more details about this workflow, check . - - :robot: This was CompareMPS, we hope you have enjoyed this program. ' >> body.md echo "::warning title=MPS files are different::$(cat body.md)" - name: Find Comment @@ -95,7 +95,7 @@ jobs: with: issue-number: ${{ github.event.pull_request.number }} comment-author: "github-actions[bot]" - body-includes: This was CompareMPS + body-includes: CompareMPS report - name: Comment on PR with log if failed if: failure() && github.event.pull_request.head.repo.full_name == github.repository uses: peter-evans/create-or-update-comment@v4 @@ -111,7 +111,7 @@ jobs: comment-id: ${{ steps.find-comment.outputs.comment-id }} issue-number: ${{ github.event.pull_request.number }} body: | - ### :white_check_mark: MPS files match + ## :robot: CompareMPS report - :robot: This was CompareMPS, we hope you have enjoyed this program. + ### :white_check_mark: MPS files match edit-mode: replace diff --git a/docs/src/91-developer.md b/docs/src/91-developer.md index 049c8736..b966a578 100644 --- a/docs/src/91-developer.md +++ b/docs/src/91-developer.md @@ -588,7 +588,7 @@ When creating a pull request, the workflow `CompareMPS.yml` will run the compari 2. **Unexpected failure**: If you made modifications that were not supposed to change the model, then you need to investigate what happened. Use the MPS difference to debug what you have done. There is no easy fix for this. If you think there are bugs in the comparison script, discuss with your PR reviewer and open an issue if necessary. !!! warning - The comparison workflow only writes PR comments if the branch is made from within `TulipaEnergyModel`. To see the log online in that case, you have to open the GitHub action log, or run the comparison locally, as explained in the previous section. + The comparison workflow only writes PR comments if the branch is made from within `TulipaEnergyModel` (i.e., not from forks). To see the log online in that case, you have to open the GitHub action log, or run the comparison locally, as explained in the previous section. ## Procedure for Releasing a New Version (Julia Registry) diff --git a/utils/scripts/model-mps-compare.jl b/utils/scripts/model-mps-compare.jl index 83254eb6..7e9cced7 100644 --- a/utils/scripts/model-mps-compare.jl +++ b/utils/scripts/model-mps-compare.jl @@ -39,6 +39,7 @@ function compare_mps(existing_mps_folder) new_lines = readlines(new_mps_file) if length(existing_lines) != length(new_lines) + no_issues = false @error "Files don't have the same size" else zipped_lines = zip(existing_lines, new_lines)