diff --git a/.github/workflows/commands.yml b/.github/workflows/commands.yml index 72fa71e6e9c..01203a6c562 100644 --- a/.github/workflows/commands.yml +++ b/.github/workflows/commands.yml @@ -14,7 +14,7 @@ permissions: jobs: cleanup_old_runs: if: github.event.schedule == '0 13 * * *' - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest permissions: actions: write env: @@ -33,7 +33,7 @@ jobs: run_command: if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/run') - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Extract command to run uses: actions/github-script@v3 @@ -76,13 +76,61 @@ jobs: if: steps.command-extractor.outputs.result == 'fantomas' id: fantomas run: dotnet fantomas . -r - - name: Process fantomas command + - name: Process xlf command if: steps.command-extractor.outputs.result == 'xlf' id: xlf run: dotnet build src/Compiler /t:UpdateXlf + - name: Post ilverify start comment + if: steps.command-extractor.outputs.result == 'ilverify' + uses: actions/github-script@v3 + with: + script: | + const body = `Started to run ilverify baseline update`; + await github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }); + + - name: Process ilverify command (Update ILVerify baselines) + if: steps.command-extractor.outputs.result == 'ilverify' + id: ilverify + env: + TEST_UPDATE_BSL: 1 + run: | + # Run the ilverify script with TEST_UPDATE_BSL=1 + pwsh tests/ILVerify/ilverify.ps1 + + # Calculate the changes per file + echo "Checking for changes in baseline files..." + FILES_CHANGED=0 + CHANGES_OUTPUT="" + + for file in tests/ILVerify/*.bsl; do + if git diff --quiet "$file"; then + continue + else + FILES_CHANGED=$((FILES_CHANGED + 1)) + LINES_CHANGED=$(git diff --numstat "$file" | awk '{print $1 + $2}') + CHANGES_OUTPUT="${CHANGES_OUTPUT}${file}: ${LINES_CHANGED} lines changed\n" + fi + done + + if [ "$FILES_CHANGED" -eq 0 ]; then + echo "result=The ilverify command ran and did not modify any baseline." >> $GITHUB_OUTPUT + else + echo -e "result=The ilverify command ran and triggered the following number of changes per file:\n${CHANGES_OUTPUT}" >> $GITHUB_OUTPUT + fi - name: Commit and push changes - if: steps.fantomas.outcome == 'success' || steps.xlf.outcome == 'success' + if: steps.fantomas.outcome == 'success' || steps.xlf.outcome == 'success' || steps.ilverify.outcome == 'success' run: | + # Only commit if there are actual changes + if git diff --quiet; then + echo "No changes to commit, skipping." + exit 0 + fi + git config --local user.name "github-actions[bot]" git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" git commit -a -m 'Automated command ran: ${{ steps.command-extractor.outputs.result }} @@ -90,7 +138,7 @@ jobs: Co-authored-by: ${{ github.event.comment.user.login }} <${{ github.event.comment.user.id }}+${{ github.event.comment.user.login }}@users.noreply.github.com>' git push - name: Post command comment - if: steps.fantomas.outcome == 'success' || steps.xlf.outcome == 'success' + if: steps.fantomas.outcome == 'success' || steps.xlf.outcome == 'success' || steps.ilverify.outcome == 'success' uses: actions/github-script@v3 with: script: | @@ -98,8 +146,10 @@ jobs: var output = "" if ("${{steps.command-extractor.outputs.result}}" == 'fantomas') { output = "${{steps.fantomas.outputs.result}}" - } else if("${{steps.command-extractor.outputs.result}}" == 'xlf') { + } else if ("${{steps.command-extractor.outputs.result}}" == 'xlf') { output = "${{steps.xlf.outputs.result}}" + } else if ("${{steps.command-extractor.outputs.result}}" == 'ilverify') { + output = "${{steps.ilverify.outputs.result}}" } const body = `Ran ${{ steps.command-extractor.outputs.result }}: https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}\n${output}`; await github.issues.createComment({