Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 56 additions & 6 deletions .github/workflows/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -76,30 +76,80 @@ 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 }}

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: |
// Probably, there's more universal way of getting outputs, but my gh-actions-fu is not that good.
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({
Expand Down