Skip to content

Workflow updates

Workflow updates #33

Workflow file for this run

name: Format, Lint and add changes on PR
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
permissions:
contents: write
pull-requests: 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 capture errors
id: lint
continue-on-error: true
run: |
# Run the Deno linter and capture stderr
deno task lint 2> lint-error.log || true # do not fail
- name: Comment on PR if linter fails
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
// Read the linter error output
const errorOutput = fs.readFileSync('lint-error.log', 'utf8');
const problemsFoundRegex = /Found [0-9]+ problem(s)?\n/m
if (!errorOutput || !errorOutput.match(problemsFoundRegex)) {
console.log("No lint errors.");
return;
}
// Remove ANSI codes
const ansiRegex = /\x1b\[[0-9;]*m/g;
const cleanErrorOutput = errorOutput.replace(ansiRegex, '');
// Create a comment on the PR with the error message
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## Linter Failed:\n\n\`\`\`${cleanErrorOutput}\`\`\``
});
// fail due to error found on previous step
process.exit(1);
- name: Remove lint-error.log
run: rm lint-error.log
- name: Verify formatting
run: deno task fmt
- name: Ensure Changes Exist
run: |
git diff --exit-code
echo "no_changes=$?" >> $GITHUB_ENV
- name: Push fmt changes
if: env.no_changes != '0'
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git commit -am "deno formatting"
git push https://x-access-token:${{ github.token }}@github.com/${{ github.repository }} "${{ github.head_ref }}"