Add maxlength on input components #580
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: Pull Request | |
env: | |
PW_COMPONENT_FILTER: | |
on: | |
pull_request: | |
branches: [ main, develop ] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
permissions: write-all | |
jobs: | |
pr-lint: | |
name: Lint | |
timeout-minutes: 15 | |
runs-on: macos-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16.x | |
registry-url: 'https://registry.npmjs.org' | |
always-auth: true | |
- name: Install Package Dependencies 🔗 | |
# https://peps.python.org/pep-0632/#migration-advice | |
# https://github.com/actions/runner/issues/2958#issuecomment-2186602747 | |
run: | | |
pip install packaging | |
pip install --upgrade setuptools | |
brew install python-setuptools | |
npm ci --force | |
- name: Run Lint Checks | |
run: | | |
npm run lint:check | |
pr-format: | |
name: Format | |
timeout-minutes: 15 | |
runs-on: macos-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16.x | |
registry-url: 'https://registry.npmjs.org' | |
always-auth: true | |
- name: Install Package Dependencies 🔗 | |
# https://peps.python.org/pep-0632/#migration-advice | |
# https://github.com/actions/runner/issues/2958#issuecomment-2186602747 | |
run: | | |
pip install packaging | |
pip install --upgrade setuptools | |
brew install python-setuptools | |
npm ci --force | |
- name: Run Format Checks | |
run: | | |
npm run format:check | |
pr-prepare: | |
name: "Detect required tests" | |
runs-on: macos-latest | |
outputs: | |
matrix: ${{ steps.get-component-filter.outputs.result }} | |
steps: | |
- name: Configure OS | |
run: | | |
echo "Setting CGFontDisableAntialiasing" | |
defaults write CoreGraphics CGFontDisableAntialiasing YES | |
echo "Disabling AppleFontSmoothing" | |
defaults write -g AppleFontSmoothing -int 0 | |
echo "Completed OS configure" | |
- name: Dump env 💩 | |
run: env | sort | |
- name: Dump GitHub context 💩 | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
run: echo "$GITHUB_CONTEXT" | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
with: | |
persist-credentials: true | |
fetch-depth: 0 | |
- name: Ensure branch up to date 🌿 | |
# Only on branches | |
if: ${{ startsWith(github.ref, 'refs/heads/') }} | |
run: | | |
git pull | |
- name: Use Node.js 16.x ✔ | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16.x | |
registry-url: 'https://registry.npmjs.org' | |
always-auth: true | |
- name: Install Package Dependencies | |
# https://peps.python.org/pep-0632/#migration-advice | |
# https://github.com/actions/runner/issues/2958#issuecomment-2186602747 | |
run: | | |
pip install packaging | |
pip install --upgrade setuptools | |
brew install python-setuptools | |
npm ci --force | |
- name: Detect necessary components to test | |
uses: actions/github-script@v6 | |
id: get-component-filter | |
with: | |
script: | | |
console.log('Checking required components'); | |
const path = require('path'); | |
const { execSync } = require('child_process'); | |
const { globby } = await import('${{ github.workspace }}/node_modules/globby/index.js'); | |
const ghCtx = ${{ toJson(github) }}; | |
let files = []; | |
let excludeFiles = []; | |
async function getAllComponents() { | |
const entryPoints = (await globby('${{ github.workspace }}/src/**/!(*.(style|test|stories|spec)).(ts|js)')) | |
.filter(value => | |
!value.startsWith('./src/utils') && | |
!value.includes('OmniInputPlaywright') && | |
!value.includes('OmniInputStories')); | |
return entryPoints.map(e => e.replace('./', '').replace('${{ github.workspace }}/', '')).join('\n'); | |
} | |
let list = ''; | |
if (ghCtx.event_name === 'workflow_dispatch') { | |
console.log('Manual Dispatch'); | |
try { | |
const response = await github.request(`GET /repos/${ghCtx.repository}/actions/runs?branch=${ghCtx.ref_name}&event=workflow_dispatch&per_page=100`); | |
const before = response.data.workflow_runs.find(wr => wr.name === ghCtx.workflow && wr.id?.toString() !== ghCtx.run_id?.toString() && wr.head_sha && wr.head_sha !== ghCtx.sha && wr.head_branch === ghCtx.ref_name && wr.status === 'completed' && wr.conclusion !== 'failure')?.head_sha; | |
if (before) { | |
list = execSync(`git diff-tree --no-commit-id --name-only -r ${before} ${ghCtx.sha}`).toString(); | |
} else { | |
list = await getAllComponents(); | |
} | |
} catch (error) { | |
console.warn(error); | |
list = await getAllComponents(); | |
} | |
} else if (ghCtx.event_name === 'pull_request') { | |
console.log('Pull Request Automated Workflow'); | |
try { | |
const response = await github.request(`GET /repos/${ghCtx.repository}/actions/runs?branch=${ghCtx.head_ref}&event=pull_request&per_page=100`); | |
const beforeWorkflows = response.data.workflow_runs.filter(wr => wr.name === ghCtx.workflow && wr.id?.toString() !== ghCtx.run_id?.toString() && wr.head_sha && wr.head_sha !== ghCtx.sha && wr.head_branch === ghCtx.head_ref && wr.status === 'completed' && wr.pull_requests && wr.pull_requests.length > 0 && wr.pull_requests.find(p => p.id === ghCtx.event.pull_request?.id)); | |
let currentSha = ghCtx.event.pull_request?.head?.sha ?? ghCtx.sha; | |
if (beforeWorkflows && beforeWorkflows.length > 0) { | |
for (let index = 0; index < beforeWorkflows.length; index++) { | |
const beforeWorkflow = beforeWorkflows[index]; | |
if (beforeWorkflow?.head_sha) { | |
const jobsResponse = await github.request(`GET /repos/${ghCtx.repository}/actions/runs/${beforeWorkflow.id}/attempts/${beforeWorkflow.run_attempt}/jobs`); | |
if (jobsResponse?.data) { | |
const passedBefore = jobsResponse.data.jobs.filter(j => j.name.startsWith('Test (') && j.status === 'completed' && j.conclusion === 'success').map(j => j.name.match(/\(([^)]+)\)/)[1]); | |
if (passedBefore && passedBefore.length > 0) { | |
const diffList = execSync(`git diff-tree --no-commit-id --name-only -r ${beforeWorkflow?.head_sha} ${currentSha}`).toString(); | |
const changedFiles = []; | |
diffList.split(/(\r\n|\n|\r)/gm).forEach(f => { | |
if (f.startsWith('src') && !f.startsWith('src/utils') && !f.startsWith('src/core') && !f.startsWith('src/icons') && !f.endsWith('index.ts') && f.endsWith('.ts')) { | |
const filter = path.basename(f).replace('.stories', '').replace('.spec', '').replace('.ts', '.spec.ts'); | |
if (!changedFiles.includes(filter)) { | |
changedFiles.push(filter); | |
} | |
} | |
}); | |
excludeFiles = [...excludeFiles, ...passedBefore.filter(p => !changedFiles.includes(p) && !excludeFiles.includes(p))]; | |
} | |
} | |
} | |
} | |
} | |
list = execSync(`git diff-tree --no-commit-id --name-only -r ${ghCtx.event.pull_request?.base?.sha ?? ghCtx.event.before} ${ghCtx.event.pull_request?.head?.sha ?? ghCtx.sha}`).toString(); | |
} catch (error) { | |
list = execSync(`git diff-tree --no-commit-id --name-only -r ${ghCtx.event.pull_request?.base?.sha ?? ghCtx.event.before} ${ghCtx.event.pull_request?.head?.sha ?? ghCtx.sha}`).toString(); | |
} | |
} else { | |
console.log('Automated Workflow'); | |
list = execSync(`git diff-tree --no-commit-id --name-only -r ${ghCtx.event.pull_request?.base?.sha ?? ghCtx.event.before} ${ghCtx.event.pull_request?.head?.sha ?? ghCtx.sha}`).toString(); | |
} | |
if (list.includes('src/core')) { | |
console.log('Core was changed. Testing all components'); | |
list = await getAllComponents(); | |
} | |
if (!list) { | |
console.log('No specific component modified. Testing all components'); | |
list = await getAllComponents(); | |
} | |
console.log(list); | |
list.split(/(\r\n|\n|\r)/gm).forEach(f => { | |
if (f.startsWith('src') && !f.startsWith('src/utils') && !f.startsWith('src/core') && !f.startsWith('src/icons') && !f.endsWith('index.ts') && f.endsWith('.ts')) { | |
const filter = path.basename(f).replace('.stories', '').replace('.spec', '').replace('.ts', '.spec.ts'); | |
if (!files.includes(filter)) { | |
files.push(filter); | |
} | |
} | |
}); | |
if (excludeFiles.length > 0) { | |
console.log('Excluding files: ', JSON.stringify(excludeFiles)); | |
} | |
files = files.filter(p => !excludeFiles.includes(p)); | |
console.log(JSON.stringify(files)); | |
return files; | |
result-encoding: json | |
pr-test: | |
if: ${{ needs.pr-prepare.outputs.matrix != '[]' && needs.pr-prepare.outputs.matrix != '' && needs.pr-prepare.outputs.matrix }} | |
needs: [ pr-lint, pr-format, pr-prepare ] | |
permissions: write-all | |
name: "Test" | |
timeout-minutes: 300 | |
runs-on: macos-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
value: ${{fromJson(needs.pr-prepare.outputs.matrix)}} | |
steps: | |
- name: Configure OS | |
run: | | |
echo "Setting CGFontDisableAntialiasing" | |
defaults write CoreGraphics CGFontDisableAntialiasing YES | |
echo "Disabling AppleFontSmoothing" | |
defaults write -g AppleFontSmoothing -int 0 | |
echo "Completed OS configure" | |
- name: Dump env 💩 | |
run: env | sort | |
- name: Dump GitHub context 💩 | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
run: echo "$GITHUB_CONTEXT" | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
with: | |
persist-credentials: true | |
fetch-depth: 0 | |
- name: Ensure branch up to date 🌿 | |
# Only on branches | |
if: ${{ startsWith(github.ref, 'refs/heads/') }} | |
run: | | |
git pull | |
- name: Use Node.js 16.x ✔ | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16.x | |
registry-url: 'https://registry.npmjs.org' | |
always-auth: true | |
- name: Install Package Dependencies | |
# https://peps.python.org/pep-0632/#migration-advice | |
# https://github.com/actions/runner/issues/2958#issuecomment-2186602747 | |
run: | | |
pip install packaging | |
pip install --upgrade setuptools | |
brew install python-setuptools | |
npm ci --force | |
- name: Update PW_COMPONENT_FILTER | |
run: | | |
PW_COMPONENT_FILTER="${{matrix.value}}" | |
echo PW_COMPONENT_FILTER=${PW_COMPONENT_FILTER} >> $GITHUB_ENV | |
- name: Install Playwright Chrome Dependencies | |
run: npx playwright install --with-deps | |
- name: Run Tests | |
run: npm run test | |
env: | |
CI: true | |
- name: Upload Test Results | |
uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: "playwright-report-${{matrix.value}}" | |
path: playwright-report/ | |
retention-days: 30 | |
- name: Upload Test Coverage | |
uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: "coverage-report-${{matrix.value}}" | |
path: coverage/ | |
retention-days: 30 | |
pr-pass: | |
needs: [ pr-prepare, pr-test ] | |
if: ${{ always() }} | |
name: "Ensure All Tests Pass" | |
runs-on: macos-latest | |
steps: | |
- name: Fail on Error or Cancelation | |
run: | | |
echo "${{ toJson(needs) }}" | |
exit 1 | |
# see https://github.com/orgs/community/discussions/26822#discussioncomment-5122101 | |
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} |