Diff at module-info should show #671
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: AST diff Bot | |
| on: | |
| issues: | |
| types: [opened, edited] | |
| issue_comment: | |
| types: [created, edited] | |
| jobs: | |
| diff: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| steps: | |
| # Step 0: Check for @diff trigger and get the URL command | |
| - name: Check for @diff trigger | |
| id: trigger | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| let body = ""; | |
| if (context.payload.issue && context.eventName === "issues") { | |
| body = context.payload.issue.body || ""; | |
| console.log("Checking issue body..."); | |
| } else if (context.payload.comment && context.eventName === "issue_comment") { | |
| body = context.payload.comment.body || ""; | |
| console.log("Checking comment body..."); | |
| } | |
| const regexScreenshot = /@diff\s+(\S+)\s+(\S+)/; // Match URL + screenshot flag | |
| const regexArtifact = /@diff\s+(\S+)/; // Match only URL | |
| let match = body.match(regexScreenshot); | |
| if (match) { | |
| core.setOutput('triggered', 'true'); | |
| core.setOutput('url', match[1].trim()); | |
| core.setOutput('screenshot', match[2].trim()); | |
| core.setOutput('mode', 'screenshot'); | |
| } else { | |
| match = body.match(regexArtifact); | |
| if (match) { | |
| core.setOutput('triggered', 'true'); | |
| core.setOutput('url', match[1].trim()); | |
| core.setOutput('screenshot', ''); | |
| core.setOutput('mode', 'artifact'); | |
| } else { | |
| core.setOutput('triggered', 'false'); | |
| } | |
| } | |
| # Step 1: Run the exporter | |
| - name: Running the RM action exporter | |
| if : ${{ steps.trigger.outputs.triggered == 'true'}} | |
| uses: pouryafard75/[email protected] | |
| id: run_rm_exporter | |
| with: | |
| OAuthToken: ${{ secrets.OAUTHTOKEN }} | |
| URL: ${{ steps.trigger.outputs.url }} | |
| screenshot: ${{ steps.trigger.outputs.screenshot }} | |
| # Step 2: Reply to the user with artifact url | |
| - name: Reply Artifact zip | |
| if: ${{ steps.trigger.outputs.triggered == 'true' && steps.trigger.outputs.screenshot == '' }} | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const url = '${{ steps.trigger.outputs.url }}'; | |
| const artifact_url = '${{ steps.run_rm_exporter.outputs.artifact_url }}'; // Add artifact_url output | |
| await github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `👋 You triggered the bot with the URL: \`${url}\`. You can download it here: [Download Artifact](${artifact_url}).` | |
| }) | |
| - name: Generate image list | |
| id: generate-paths | |
| if: ${{ steps.trigger.outputs.screenshot != null && steps.run_rm_exporter.outputs.numberOfScreenshots != 0 }} | |
| run: | | |
| # Ensure the output from the previous step is evaluated properly | |
| number_of_screenshots="${{ steps.run_rm_exporter.outputs.numberOfScreenshots }}" | |
| screenshots_path="${{ steps.run_rm_exporter.outputs.screenshots_path }}" | |
| # Initialize an empty string to store paths | |
| paths="" | |
| # Loop through the screenshots and append to the paths variable | |
| for i in $(seq 1 $((number_of_screenshots))); do | |
| paths+=$'\n'"${screenshots_path}$i.png" | |
| done | |
| # Set paths as an environment variable for later steps | |
| echo "paths<<EOF" >> $GITHUB_ENV | |
| echo "$paths" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| - name: Upload image | |
| if: ${{ steps.trigger.outputs.screenshot != null && steps.run_rm_exporter.outputs.numberOfScreenshots != 0 }} | |
| id: upload-image-all | |
| uses: McCzarny/[email protected] | |
| with: | |
| path: ${{ env.paths }} | |
| uploadMethod: imgbb | |
| apiKey: '${{ secrets.IMGBB_API_KEY }}' | |
| - name: 'Comment Screenshots' | |
| uses: actions/github-script@v7 | |
| if: ${{ steps.trigger.outputs.screenshot != null && steps.run_rm_exporter.outputs.numberOfScreenshots != 0 }} | |
| with: | |
| script: | | |
| let commentBody = 'Image(s):\n'; | |
| console.log('Initializing comment body...'); | |
| const varValue = ${{ steps.run_rm_exporter.outputs.numberOfScreenshots }} | |
| console.log(`Number of screenshots (varValue): ${varValue}`); | |
| if (isNaN(varValue)) { | |
| console.log('Error: The number of screenshots is not a valid number.'); | |
| return; | |
| } | |
| for (let i = 1; i <= varValue; i++) { | |
| console.log(`Processing image ${i}...`); | |
| index = i-1; | |
| // Access the image URL from the output | |
| const urls = JSON.parse('${{ steps.upload-image-all.outputs.urls }}'); | |
| const imageUrl = urls[index]; // Access the specific image URL | |
| // Append the image URL to the comment body | |
| commentBody += `\n`; | |
| } | |
| console.log('Comment body constructed:\n' + commentBody); | |
| await github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: commentBody | |
| }); | |
| console.log('Comment posted to the issue!'); |