Dark theme #18
Workflow file for this run
This file contains 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: Format, Lint and add changes on PR | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
- ready_for_review | |
branches: | |
- main | |
permissions: | |
contents: write | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup repo | |
uses: actions/checkout@v4 | |
- name: Setup Deno | |
uses: denoland/setup-deno@v2 | |
with: | |
deno-version: v2.x | |
- name: Switch to branch | |
run: | | |
git fetch origin "${{ github.head_ref }}" | |
git switch "${{ github.head_ref }}" | |
- name: Run linter and comment on failure | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const fs = require('fs'); | |
// Run the lint task using the shell command | |
exec('deno task lint', (error, stdout, stderr) => { | |
// Capture any stderr (error output) | |
console.log('a',error); | |
console.log('b',stdout); | |
console.log('c',stderr,stderr.length === 0); | |
if (stderr) { | |
console.error(`stderr: ${stderr}`); | |
if (stderr.length === 0) return; // If there's no error output, exit early | |
// Extract PR number from GitHub event path | |
const eventPath = process.env.GITHUB_EVENT_PATH; | |
const eventData = JSON.parse(fs.readFileSync(eventPath, 'utf8')); | |
const prNumber = eventData.pull_request.number; | |
// Output the PR number and context issue number | |
console.log(prNumber); | |
console.log(context.issue.number); | |
// Create a comment on the PR with the error message | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `## Linter Failed:\n\n\`\`\`${stderr}\`\`\`` | |
}); | |
} else if (error) { | |
console.error(`exec error: ${error}`); | |
} | |
}); | |
- name: Verify formatting | |
run: deno task fmt | |
- name: Ensure Changes Exist | |
run: | | |
if git diff --exit-code; then | |
echo "No changes to commit, exiting." | |
exit 0 | |
fi | |
- name: Set up Git user | |
run: | | |
git config user.name "github-actions" | |
git config user.email "[email protected]" | |
- name: Push fmt changes | |
run: | | |
git commit -am "deno formatting" | |
git push https://x-access-token:${{ github.token }}@github.com/${{ github.repository }} "${{ github.head_ref }}" |