Skip to content

Commit

Permalink
add axe scan to docs cd
Browse files Browse the repository at this point in the history
  • Loading branch information
nruffing committed Jan 15, 2024
1 parent e396031 commit ca42ad3
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/docs_ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@ jobs:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
- name: Axe Accessibility Scan
run: pnpm run axe
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}


1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"useGitignore": true,
"words": [
"allowcolumnreorder",
"ansicolor",
"clickanalytics",
"datagridvue",
"docsearch",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
},
"devDependencies": {
"@axe-core/cli": "^4.8.2",
"@azure/communication-email": "^1.0.0",
"@azure/identity": "^4.0.0",
"@azure/keyvault-secrets": "^4.7.0",
"@babel/types": "^7.23.6",
Expand All @@ -92,6 +93,7 @@
"@vue/tsconfig": "^0.5.1",
"@vuepress/utils": "2.0.0-rc.0",
"adm-zip": "^0.5.10",
"ansicolor": "^2.0.1",
"cspell": "^8.3.2",
"dotenv": "^16.3.1",
"googleapis": "^130.0.0",
Expand Down
50 changes: 50 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 40 additions & 15 deletions scripts/axe/axe.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
import { getUrlsAsync } from '../shared/urls.js'
import { exec } from 'node:child_process'
import { sendEmail } from '../shared/email.js'
import { ExecException, exec } from 'node:child_process'

const urls = await getUrlsAsync()

const output = [] as string[]

function appendLog(url: string, stdout: string) {
const txt = `${url} | ${stdout}`
output.push(txt)
console.log(txt)
}

function appendError(url: string, err: ExecException | string) {
const txt = `${url} | ${err}`
output.push(txt)
console.error(txt)
}

const promises = [] as Promise<void>[]

for (const url of urls) {
console.log(`Processing ${url}...`)
exec(`./node_modules/.bin/axe "${url}"`, (err, stdout, stderr) => {
if (err) {
console.error(`Error on ${url} | ${err}`)
return
}

if (stderr) {
console.error(`Error on ${url} | ${err}`)
return
}

console.log(`${url} | ${stdout}`)
})
promises.push(
new Promise((resolve, reject) => {
const process = exec(`./node_modules/.bin/axe "${url}"`, (err: ExecException | null, stdout: string, stderr: string) => {
if (err) {
appendError(url, err)
return
}

if (stderr) {
appendError(url, stderr)
return
}

appendLog(url, stdout)
})

process.on('close', resolve)
}),
)
}

await Promise.all(promises)
await sendEmail('Axe Results - data-grid-vue', output)
3 changes: 2 additions & 1 deletion scripts/axe/tsconfig.axe.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"baseUrl": "./",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": false
"noEmit": false,
"noImplicitAny": false
},
"include": ["./**/*.ts", "../shared/**/*.ts"]
}
45 changes: 45 additions & 0 deletions scripts/shared/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { EmailClient, EmailMessage, EmailSendResponse } from '@azure/communication-email'
import { EnvironmentCredential } from '@azure/identity'
import { SecretClient } from '@azure/keyvault-secrets'
import { parse } from 'ansicolor'

Check failure on line 4 in scripts/shared/email.ts

View workflow job for this annotation

GitHub Actions / Build and Deploy Job (18.x)

Could not find a declaration file for module 'ansicolor'. '/home/runner/work/data-grid-vue/data-grid-vue/node_modules/.pnpm/ansicolor@2.0.1/node_modules/ansicolor/build/ansicolor.mjs' implicitly has an 'any' type.

interface AzureEmailConfig {
connectionString: string
senderAddress: string
toEmail: string
}

const credential = new EnvironmentCredential()
const client = new SecretClient('https://data-grid-vue.vault.azure.net/', credential)

const secret = await client.getSecret('EmailService')
const config = JSON.parse(secret.value ?? '{}') as AzureEmailConfig

const emailClient = new EmailClient(config.connectionString)

export async function sendEmail(subject: string, ansiTexts: string[]): Promise<EmailSendResponse> {
const parsed = parse(ansiTexts.join('\r\n'))
const html = parsed.spans.map(s => s.text).join('<br />')

Check failure on line 22 in scripts/shared/email.ts

View workflow job for this annotation

GitHub Actions / Build and Deploy Job (18.x)

Parameter 's' implicitly has an 'any' type.

const message: EmailMessage = {
senderAddress: config.senderAddress,
recipients: {
to: [
{
address: config.toEmail,
},
],
},
content: {
subject,
html,
},
}

const poller = await emailClient.beginSend(message)
const response = await poller.pollUntilDone()

console.log('EMAIL RESPONSE', response)

return response
}

0 comments on commit ca42ad3

Please sign in to comment.