From 532d6f263ac01b0bbe3741d6e2f6236ccac4d6c9 Mon Sep 17 00:00:00 2001 From: avi Date: Tue, 19 Aug 2025 16:51:32 +1200 Subject: [PATCH 1/4] some minor changes to ci syntax --- .github/workflows/compas-compile-ci.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/compas-compile-ci.yml b/.github/workflows/compas-compile-ci.yml index 66ca2296c..4db2acfe3 100644 --- a/.github/workflows/compas-compile-ci.yml +++ b/.github/workflows/compas-compile-ci.yml @@ -1,6 +1,7 @@ name: COMPAS compile test -'on': - workflow_dispatch: null + +on: + workflow_dispatch: pull_request: branches: - dev @@ -12,7 +13,7 @@ name: COMPAS compile test push: branches: - dev - - + # Ensures only the latest workflow run for the same branch is active, canceling any in-progress runs. concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -25,13 +26,16 @@ jobs: ARTIFACT_PATH: py_tests/test_artifacts name: Build COMPAS - runs-on: '${{ matrix.os}}' - container: '${{matrix.container}}' + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} strategy: fail-fast: false matrix: os: - ubuntu-22.04 + container: + - ubuntu:22.04 + steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -42,7 +46,7 @@ jobs: # - name: Install TeXLive # uses: teatimeguest/setup-texlive-action@v3.3.4 - name: Install dependencies on ubuntu - if: 'startsWith(matrix.os, ''ubuntu-2'')' + if: startsWith(matrix.os, 'ubuntu-2') run: | cd misc/cicd-scripts chmod 755 linux-dependencies @@ -83,8 +87,8 @@ jobs: id: upload uses: actions/upload-artifact@v4 with: - name: '${{ env.ARTIFACT_NAME }}' - path: '${{ env.ARTIFACT_PATH }}/${{ env.ARTIFACT_NAME }}' + name: ${{ env.ARTIFACT_NAME }} + path: ${{ env.ARTIFACT_PATH }}/${{ env.ARTIFACT_NAME }} if-no-files-found: error - name: Test Summary run: | From 42b58b1a96cd8f73d24687cec77cd4fbd05cf103 Mon Sep 17 00:00:00 2001 From: avi Date: Tue, 19 Aug 2025 18:40:26 +1200 Subject: [PATCH 2/4] remove matrix --- .github/workflows/compas-compile-ci.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/compas-compile-ci.yml b/.github/workflows/compas-compile-ci.yml index 4db2acfe3..e74c6c589 100644 --- a/.github/workflows/compas-compile-ci.yml +++ b/.github/workflows/compas-compile-ci.yml @@ -26,15 +26,7 @@ jobs: ARTIFACT_PATH: py_tests/test_artifacts name: Build COMPAS - runs-on: ${{ matrix.os }} - container: ${{ matrix.container }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-22.04 - container: - - ubuntu:22.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 From 597e89bf712421f72037c983f2463853d3c555f6 Mon Sep 17 00:00:00 2001 From: avi Date: Tue, 19 Aug 2025 18:56:52 +1200 Subject: [PATCH 3/4] remove matrix in steps --- .github/workflows/compas-compile-ci.yml | 1 - .../workflows/pr_artifact_url_commenter.yml | 28 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/compas-compile-ci.yml b/.github/workflows/compas-compile-ci.yml index e74c6c589..f10e7a9f1 100644 --- a/.github/workflows/compas-compile-ci.yml +++ b/.github/workflows/compas-compile-ci.yml @@ -38,7 +38,6 @@ jobs: # - name: Install TeXLive # uses: teatimeguest/setup-texlive-action@v3.3.4 - name: Install dependencies on ubuntu - if: startsWith(matrix.os, 'ubuntu-2') run: | cd misc/cicd-scripts chmod 755 linux-dependencies diff --git a/.github/workflows/pr_artifact_url_commenter.yml b/.github/workflows/pr_artifact_url_commenter.yml index 62bca978d..a3759ed99 100644 --- a/.github/workflows/pr_artifact_url_commenter.yml +++ b/.github/workflows/pr_artifact_url_commenter.yml @@ -11,6 +11,14 @@ jobs: runs-on: ubuntu-latest if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: + - name: Set up GitHub CLI + uses: actions/setup-gh@v2 + with: + version: latest + + - name: Auth GitHub CLI + run: gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}" + - name: Get Artifact and Pull request info env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -24,8 +32,14 @@ jobs: SUITE_ID=$(jq -r '.check_suite_id' <<< "$WORKFLOW_RUN_EVENT_OBJ") echo "SUITE_ID=$SUITE_ID" >> "$GITHUB_ENV" - ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \ - --jq ".artifacts[] | select(.workflow_run.id==$PREVIOUS_JOB_ID and .expired==false and .name=='detailedEvolutionPlot.png') | .id" | head -n1) + # Retry loop to wait for artifact availability + for i in {1..5}; do + ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \ + --jq ".artifacts[] | select(.workflow_run.id==$PREVIOUS_JOB_ID and .expired==false and .name==\"detailedEvolutionPlot.png\") | .id" | head -n1) + if [[ -n "$ARTIFACT_ID" ]]; then break; fi + echo "Artifact not found yet. Retrying in 10s..." + sleep 10 + done echo "ARTIFACT_ID=$ARTIFACT_ID" >> "$GITHUB_ENV" PR_NUMBER=$(gh api "/repos/$OWNER/$REPO/commits/${{ github.event.workflow_run.head_sha }}/pulls" --jq '.[0].number') @@ -37,7 +51,7 @@ jobs: - name: Download artifact if: env.PR_NUMBER != 'null' && env.ARTIFACT_ID != '' run: | - gh api /repos/${{ github.repository }}/actions/artifacts/${{ env.ARTIFACT_ID }}/zip -H "Accept: application/vnd.github.v3+json" --output artifact.zip + gh api /repos/${{ github.repository }}/actions/artifacts/${{ env.ARTIFACT_ID }}/zip --output artifact.zip unzip artifact.zip rm artifact.zip @@ -45,7 +59,7 @@ jobs: if: env.PR_NUMBER != 'null' && env.ARTIFACT_ID != '' env: JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}" - ARTIFACT_URL: "${{ github.server_url }}/${{ github.repository }}/suites/${{ env.SUITE_ID }}/artifacts/${{ env.ARTIFACT_ID }}" + ARTIFACT_DL: "${{ github.server_url }}/${{ github.repository }}/actions/artifacts/${{ env.ARTIFACT_ID }}" uses: actions/github-script@v6 with: github-token: ${{secrets.GITHUB_TOKEN}} @@ -65,11 +79,11 @@ jobs: | -------- | ----------------------- | | Commit | ${process.env.HEAD_SHA} | | Logs | ${process.env.JOB_PATH} | - | Download | ${process.env.ARTIFACT_URL} | + | Download | ${process.env.ARTIFACT_DL} | ### Detailed Evolution Plot ![Detailed Evolution Plot](data:image/png;base64,${imageData}) - [badge]: https://img.shields.io/badge/Build_Success!-0d1117?style=for-the-badge&labelColor=3fb950&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiBmaWxsPSIjZmZmZmZmIj48cGF0aCBkPSJNMjEuMDMgNS43MmEuNzUuNzUgMCAwIDEgMCAxLjA2bC0xMS41IDExLjVhLjc0Ny43NDcgMCAwIDEtMS4wNzItLjAxMmwtNS41LTUuNzVhLjc1Ljc1IDAgMSAxIDEuMDg0LTEuMDM2bDQuOTcgNS4xOTVMMTkuOTcgNS43MmEuNzUuNzUgMCAwIDEgMS4wNiAwWiI+PC9wYXRoPjwvc3ZnPg== + [badge]: https://img.shields.io/badge/Build_Success!-0d1117?style=for-the-badge&labelColor=3fb950 ` - }) + }) \ No newline at end of file From eba8ca39ec230407084db95387b0f106ab8939ce Mon Sep 17 00:00:00 2001 From: avi Date: Tue, 19 Aug 2025 19:38:12 +1200 Subject: [PATCH 4/4] attempt at fixing commenter --- .../workflows/pr_artifact_url_commenter.yml | 271 ++++++++++++++---- 1 file changed, 218 insertions(+), 53 deletions(-) diff --git a/.github/workflows/pr_artifact_url_commenter.yml b/.github/workflows/pr_artifact_url_commenter.yml index a3759ed99..90a3604d3 100644 --- a/.github/workflows/pr_artifact_url_commenter.yml +++ b/.github/workflows/pr_artifact_url_commenter.yml @@ -11,14 +11,6 @@ jobs: runs-on: ubuntu-latest if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - - name: Set up GitHub CLI - uses: actions/setup-gh@v2 - with: - version: latest - - - name: Auth GitHub CLI - run: gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}" - - name: Get Artifact and Pull request info env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -26,64 +18,237 @@ jobs: OWNER: ${{ github.repository_owner }} REPO: ${{ github.event.repository.name }} run: | + # Extract workflow run info PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ") echo "PREVIOUS_JOB_ID=$PREVIOUS_JOB_ID" >> "$GITHUB_ENV" - SUITE_ID=$(jq -r '.check_suite_id' <<< "$WORKFLOW_RUN_EVENT_OBJ") - echo "SUITE_ID=$SUITE_ID" >> "$GITHUB_ENV" - - # Retry loop to wait for artifact availability - for i in {1..5}; do - ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \ - --jq ".artifacts[] | select(.workflow_run.id==$PREVIOUS_JOB_ID and .expired==false and .name==\"detailedEvolutionPlot.png\") | .id" | head -n1) - if [[ -n "$ARTIFACT_ID" ]]; then break; fi - echo "Artifact not found yet. Retrying in 10s..." - sleep 10 - done - echo "ARTIFACT_ID=$ARTIFACT_ID" >> "$GITHUB_ENV" + HEAD_SHA="${{ github.event.workflow_run.head_sha }}" + echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV" - PR_NUMBER=$(gh api "/repos/$OWNER/$REPO/commits/${{ github.event.workflow_run.head_sha }}/pulls" --jq '.[0].number') - echo "PR_NUMBER=${PR_NUMBER:-null}" >> "$GITHUB_ENV" + # Get PR number from the workflow run + echo "Looking for PR associated with commit $HEAD_SHA..." + PR_NUMBER=$(gh api "/repos/$OWNER/$REPO/commits/$HEAD_SHA/pulls" \ + --jq '.[0].number // empty' 2>/dev/null || echo "") - HEAD_SHA=${{ github.event.workflow_run.head_sha }} - echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV" + if [[ -n "$PR_NUMBER" && "$PR_NUMBER" != "null" ]]; then + echo "Found PR #$PR_NUMBER" + echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV" + + # Look for the specific artifact + ARTIFACT_NAME="detailedEvolutionPlot.png" + echo "Searching for artifact: $ARTIFACT_NAME from workflow run $PREVIOUS_JOB_ID..." + + # Retry loop with better error handling + ARTIFACT_ID="" + for i in {1..8}; do + echo "Attempt $i/8: Looking for artifact..." + + # Use more robust jq filter + ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \ + --jq --arg workflow_id "$PREVIOUS_JOB_ID" --arg name "$ARTIFACT_NAME" \ + '.artifacts[] | select(.workflow_run.id == ($workflow_id | tonumber) and .expired == false and .name == $name) | .id' \ + 2>/dev/null | head -n1 || echo "") + + if [[ -n "$ARTIFACT_ID" ]]; then + echo "Found artifact with ID: $ARTIFACT_ID" + break + fi + + echo "Artifact not available yet, waiting 12s before retry..." + sleep 12 + done + + if [[ -z "$ARTIFACT_ID" ]]; then + echo "Warning: Could not find artifact '$ARTIFACT_NAME' after 8 attempts" + echo "This might be expected if the artifact generation failed or is still processing." + fi + + echo "ARTIFACT_ID=${ARTIFACT_ID:-}" >> "$GITHUB_ENV" + else + echo "No PR found for this workflow run (this is normal for direct pushes to main/dev)" + echo "PR_NUMBER=" >> "$GITHUB_ENV" + echo "ARTIFACT_ID=" >> "$GITHUB_ENV" + fi - name: Download artifact - if: env.PR_NUMBER != 'null' && env.ARTIFACT_ID != '' + if: env.PR_NUMBER != '' && env.ARTIFACT_ID != '' run: | - gh api /repos/${{ github.repository }}/actions/artifacts/${{ env.ARTIFACT_ID }}/zip --output artifact.zip - unzip artifact.zip - rm artifact.zip + echo "Downloading artifact ${{ env.ARTIFACT_ID }}..." + + # Download with better error handling + if gh api "/repos/${{ github.repository }}/actions/artifacts/${{ env.ARTIFACT_ID }}/zip" --output artifact.zip; then + echo "Successfully downloaded artifact.zip" + + # Extract and verify + if unzip -q artifact.zip; then + rm artifact.zip + + if [[ -f "detailedEvolutionPlot.png" ]]; then + echo "Found detailedEvolutionPlot.png" + echo "File size: $(du -h detailedEvolutionPlot.png | cut -f1)" + # Verify it's actually a PNG file + if file detailedEvolutionPlot.png | grep -q "PNG image"; then + echo "Verified as valid PNG image" + else + echo "Warning: File may not be a valid PNG" + fi + else + echo "Error: detailedEvolutionPlot.png not found in extracted files" + echo "Available files:" + ls -la + exit 1 + fi + else + echo "Error: Failed to extract artifact.zip" + exit 1 + fi + else + echo "Error: Failed to download artifact" + exit 1 + fi - - name: Update Comment - if: env.PR_NUMBER != 'null' && env.ARTIFACT_ID != '' + - name: Create success comment with artifact + if: env.PR_NUMBER != '' && env.ARTIFACT_ID != '' env: JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}" - ARTIFACT_DL: "${{ github.server_url }}/${{ github.repository }}/actions/artifacts/${{ env.ARTIFACT_ID }}" - uses: actions/github-script@v6 + ARTIFACT_DL: "${{ github.server_url }}/${{ github.repository }}/suites/${{ github.event.workflow_run.check_suite_id }}/artifacts/${{ env.ARTIFACT_ID }}" + uses: actions/github-script@v7 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | const fs = require('fs'); - const imageData = fs.readFileSync('detailedEvolutionPlot.png', {encoding: 'base64'}); - github.rest.issues.createComment({ - issue_number: process.env.PR_NUMBER, + + try { + // Read and validate the image + if (!fs.existsSync('detailedEvolutionPlot.png')) { + throw new Error('detailedEvolutionPlot.png file not found'); + } + + const stats = fs.statSync('detailedEvolutionPlot.png'); + console.log(`Image file size: ${(stats.size / 1024).toFixed(1)} KB`); + + if (stats.size === 0) { + throw new Error('detailedEvolutionPlot.png is empty'); + } + + // GitHub has a ~65KB limit for image embeds, warn if approaching + if (stats.size > 50000) { + console.log('Warning: Image is quite large, may not display properly in GitHub'); + } + + const imageData = fs.readFileSync('detailedEvolutionPlot.png', {encoding: 'base64'}); + const shortSha = process.env.HEAD_SHA.substring(0, 7); + + const commentBody = \`![badge] + + ## Build Successful! + + Your COMPAS compilation and test suite completed successfully! + + | Item | Value | + |------|-------| + | **Commit** | [\\\`\${shortSha}\\\`](https://github.com/\${context.repo.owner}/\${context.repo.repo}/commit/\${process.env.HEAD_SHA}) | + | **Logs** | [View workflow logs](\${process.env.JOB_PATH}) | + | **Artifact** | [Download evolution plot](\${process.env.ARTIFACT_DL}) | + + ### Detailed Evolution Plot + +
+ Click to view/hide evolution plot + + ![Detailed Evolution Plot](data:image/png;base64,\${imageData}) + +
+ + --- + Generated by COMPAS CI • [View workflow run](\${process.env.JOB_PATH}) + + [badge]: https://img.shields.io/badge/Build_Success-28a745?style=for-the-badge&logo=github-actions&logoColor=white\`; + + await github.rest.issues.createComment({ + issue_number: parseInt(process.env.PR_NUMBER), + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + }); + + console.log(`Successfully commented on PR #${process.env.PR_NUMBER} with artifact`); + + } catch (error) { + console.error('Error creating comment with artifact:', error); + + // Fallback: create comment without image + const fallbackBody = \`![badge] + + ## Build Successful! + + Your COMPAS compilation completed successfully, but there was an issue displaying the evolution plot. + + | Item | Value | + |------|-------| + | **Commit** | [\\\`\${process.env.HEAD_SHA.substring(0, 7)}\\\`](https://github.com/\${context.repo.owner}/\${context.repo.repo}/commit/\${process.env.HEAD_SHA}) | + | **Logs** | [View workflow logs](\${process.env.JOB_PATH}) | + | **Artifact** | [Download evolution plot](\${process.env.ARTIFACT_DL}) | + + **Note:** Evolution plot could not be embedded (\${error.message}) + + --- + Generated by COMPAS CI • [View workflow run](\${process.env.JOB_PATH}) + + [badge]: https://img.shields.io/badge/Build_Success-28a745?style=for-the-badge&logo=github-actions&logoColor=white\`; + + await github.rest.issues.createComment({ + issue_number: parseInt(process.env.PR_NUMBER), + owner: context.repo.owner, + repo: context.repo.repo, + body: fallbackBody + }); + + console.log(`Created fallback comment on PR #${process.env.PR_NUMBER}`); + } + + - name: Create success comment without artifact + if: env.PR_NUMBER != '' && env.ARTIFACT_ID == '' + env: + JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}" + uses: actions/github-script@v7 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const shortSha = process.env.HEAD_SHA.substring(0, 7); + + const commentBody = \`![badge] + + ## Build Successful! + + Your COMPAS compilation and test suite completed successfully! + + | Item | Value | + |------|-------| + | **Commit** | [\\\`\${shortSha}\\\`](https://github.com/\${context.repo.owner}/\${context.repo.repo}/commit/\${process.env.HEAD_SHA}) | + | **Logs** | [View workflow logs](\${process.env.JOB_PATH}) | + + **Note:** The detailed evolution plot artifact was not found or is not yet available. This might be expected if the plot generation step was skipped or failed. + + --- + Generated by COMPAS CI • [View workflow run](\${process.env.JOB_PATH}) + + [badge]: https://img.shields.io/badge/Build_Success-28a745?style=for-the-badge&logo=github-actions&logoColor=white\`; + + await github.rest.issues.createComment({ + issue_number: parseInt(process.env.PR_NUMBER), owner: context.repo.owner, - repo: context.repo.name, - body: ` - ![badge] - - Build Successful! You can find a link to the downloadable artifact below. - - | Name | Link | - | -------- | ----------------------- | - | Commit | ${process.env.HEAD_SHA} | - | Logs | ${process.env.JOB_PATH} | - | Download | ${process.env.ARTIFACT_DL} | - - ### Detailed Evolution Plot - ![Detailed Evolution Plot](data:image/png;base64,${imageData}) - - [badge]: https://img.shields.io/badge/Build_Success!-0d1117?style=for-the-badge&labelColor=3fb950 - ` - }) \ No newline at end of file + repo: context.repo.repo, + body: commentBody + }); + + console.log(`Successfully commented on PR #${process.env.PR_NUMBER} (no artifact)`); + + - name: Debug info for non-PR runs + if: env.PR_NUMBER == '' + run: | + echo "This workflow run was not associated with a pull request" + echo "Head SHA: ${{ github.event.workflow_run.head_sha }}" + echo "Event: ${{ github.event.workflow_run.event }}" + echo "Branch: ${{ github.event.workflow_run.head_branch }}" + echo "This is normal for direct pushes to main/dev branches" \ No newline at end of file