Skip to content

Commit

Permalink
Merge branch 'master' into contributing-signing
Browse files Browse the repository at this point in the history
  • Loading branch information
djahandarie authored Dec 28, 2024
2 parents 2bd95ec + fd577b8 commit ae28bbc
Show file tree
Hide file tree
Showing 70 changed files with 16,562 additions and 10,329 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

731 changes: 0 additions & 731 deletions .eslintrc.json

This file was deleted.

17 changes: 17 additions & 0 deletions .github/actionlint-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "actionlint",
"pattern": [
{
"regexp": "^(?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*: (?:\\x1b\\[\\d+m)*(.+?)(?:\\x1b\\[\\d+m)* \\[(.+?)\\]$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
}
]
}
]
}
14 changes: 14 additions & 0 deletions .github/workflows/actionlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Lint GitHub Actions workflows
on: [push, pull_request]

jobs:
actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check workflow files
run: |
echo "::add-matcher::.github/actionlint-matcher.json"
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/v1.7.4/scripts/download-actionlint.bash)
./actionlint -color
shell: bash
4 changes: 2 additions & 2 deletions .github/workflows/auto-approve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
shell: bash
env:
PR_NUM: ${{ github.event.number }}
run: echo $PR_NUM > pr_num.txt
run: echo "$PR_NUM" > pr_num.txt
- name: Upload the PR number
uses: actions/upload-artifact@v4
with:
name: pr_num
path: ./pr_num.txt
path: ./pr_num.txt
3 changes: 2 additions & 1 deletion .github/workflows/create-prerelease-on-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
id: hash
run: |
cd builds
echo "hashes=$(sha256sum * | base64 -w0)" >> "$GITHUB_OUTPUT"
echo "hashes=$(sha256sum -- * | base64 -w0)" >> "$GITHUB_OUTPUT"
- name: Release
id: release
Expand All @@ -52,6 +52,7 @@ jobs:
workflow: publish-chrome-development
token: ${{ secrets.GITHUB_TOKEN }}
wait-for-completion: false
inputs: '{ "upload_url": "${{ steps.release.outputs.upload_url }}" }'

- name: Dispatch publish-firefox-development
uses: aurelien-baudet/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7 # pin@v2
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/delay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ jobs:
inputs: |
{
"attemptNumber": "${{ github.event.inputs.attemptNumber }}",
"maxAttempts": "${{ github.event.inputs.maxAttempts }}",
"environment": "${{ github.event.inputs.environment }}"
"maxAttempts": "${{ github.event.inputs.maxAttempts }}"
}
96 changes: 72 additions & 24 deletions .github/workflows/playwright_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,47 @@ jobs:
egress-policy: audit

- name: Grab playwright-output from PR run
uses: dawidd6/action-download-artifact@80620a5d27ce0ae443b965134db88467fc607b43 # pin@v2
uses: dawidd6/action-download-artifact@80620a5d27ce0ae443b965134db88467fc607b43 # v7
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
run_id: ${{ github.event.workflow_run.id }}
name: playwright-output

- name: Grab master-screenshots-outcome from PR run
uses: dawidd6/action-download-artifact@80620a5d27ce0ae443b965134db88467fc607b43 # pin@v2
uses: dawidd6/action-download-artifact@80620a5d27ce0ae443b965134db88467fc607b43 # v7
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
run_id: ${{ github.event.workflow_run.id }}
name: master-screenshots-outcome

- name: Grab playwright-results-json from PR run
uses: dawidd6/action-download-artifact@80620a5d27ce0ae443b965134db88467fc607b43 # pin@v2
uses: dawidd6/action-download-artifact@80620a5d27ce0ae443b965134db88467fc607b43 # v7
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
run_id: ${{ github.event.workflow_run.id }}
name: playwright-results-json

- name: Dry-run grab playwright-report from PR run so we have its ID
uses: dawidd6/action-download-artifact@80620a5d27ce0ae443b965134db88467fc607b43 # v7
id: playwright-report
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
run_id: ${{ github.event.workflow_run.id }}
name: playwright-report
dry_run: true

- name: Store playwright-report ID
id: playwright-report-artifact-id
env:
ARTIFACTS_JSON: ${{ steps.playwright-report.outputs.artifacts }}
run: |
ID=$(echo "$ARTIFACTS_JSON" | jq -r '.[0].id');
echo "id=$ID" >> "$GITHUB_OUTPUT"
- name: Generate summary from playwright-results.json (expected to fail to comment)
id: playwright-summary
uses: daun/playwright-report-summary@v3
Expand All @@ -53,42 +72,71 @@ jobs:
id: playwright
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "PLAYWRIGHT_OUTPUT<<$EOF" >> $GITHUB_OUTPUT
cat ./playwright-output >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
echo "MASTER_SCREENSHOTS_OUTCOME<<$EOF" >> $GITHUB_OUTPUT
cat ./master-screenshots-outcome >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
echo "FAILED=$(grep -c '^ *[0-9] failed$' $GITHUB_OUTPUT)" >> $GITHUB_OUTPUT
echo "FLAKY=$(grep -c '^ *[0-9] flaky$' $GITHUB_OUTPUT)" >> $GITHUB_OUTPUT
{
echo "PLAYWRIGHT_OUTPUT<<$EOF";
cat ./playwright-output;
echo "$EOF";
echo "MASTER_SCREENSHOTS_OUTCOME<<$EOF";
cat ./master-screenshots-outcome;
echo "$EOF";
echo "FAILED=$(grep -c '^ *[0-9] failed$' ./playwright-output)";
echo "FLAKY=$(grep -c '^ *[0-9] flaky$' ./playwright-output)"
} >> "$GITHUB_OUTPUT"
# this is required because github.event.workflow_run.pull_requests is not available for PRs from forks
- name: "Get PR information"
uses: potiuk/get-workflow-origin@e2dae063368361e4cd1f510e8785cd73bca9352e # pin@v1_5
- name: Get PR context
id: source-run-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Find the most recently updated open PR at the repo with the requested commit:
SEARCH_QUERY: >-
type:pr state:open sort:updated-desc
repo:${{ github.repository }}
${{ github.event.workflow_run.head_sha }}
# Minimal graphql search query to fetch the PR `number` field:
GQL: |-
query($filter: String!) {
search( query: $filter, type: ISSUE, first: 1) {
nodes { ... on PullRequest { number } }
}
}
# Formats the GQL response into a `key=value` string + basic error handling
JQ_FILTER: >-
.data.search.nodes[0]
| if (.number == null) then error("Could not find PR number") end
| "pullRequestNumber=\(.number)"
run: |
gh api graphql --field "filter=$SEARCH_QUERY" --raw-field "query=$GQL" --jq "$JQ_FILTER" >> "${GITHUB_OUTPUT}"
- name: "[Comment] Couldn't download screenshots from master branch"
uses: mshick/add-pr-comment@dd126dd8c253650d181ad9538d8b4fa218fc31e8 # pin@v2
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2
if: steps.playwright.outputs.MASTER_SCREENSHOTS_OUTCOME == 'failure'
with:
issue: ${{ steps.source-run-info.outputs.pullRequestNumber }}
message: |
:heavy_exclamation_mark: Could not fetch screenshots from master branch, so had nothing to make a visual comparison against; please check the "master-screenshots" step in the workflow run and rerun it before merging.
- name: "[Comment] Warning: Flaky tests or visual differences caused by this PR; please check the playwright report"
uses: mshick/add-pr-comment@dd126dd8c253650d181ad9538d8b4fa218fc31e8 # pin@v2
if: steps.playwright.outputs.MASTER_SCREENSHOTS_OUTCOME != 'failure' && (steps.playwright.outputs.FLAKY != 0 || steps.playwright.outputs.FAILED != 0)
- name: "[Comment] Warning: Visual differences caused by this PR; please check the playwright report"
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2
if: steps.playwright.outputs.MASTER_SCREENSHOTS_OUTCOME != 'failure' && steps.playwright.outputs.FAILED != 0
with:
issue: ${{ steps.source-run-info.outputs.pullRequestNumber }}
message: |
:warning: <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/${{ steps.playwright-report-artifact-id.outputs.id }}">Visual changes detected by playwright; please check the report to verify if they are desirable.</a>
- name: "[Comment] Success (but flaky): No visual differences introduced by this PR (but flaky tests detected)"
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2
if: steps.playwright.outputs.MASTER_SCREENSHOTS_OUTCOME != 'failure' && steps.playwright.outputs.FLAKY != 0 && steps.playwright.outputs.FAILED == 0
with:
issue: ${{ steps.source-run-info.outputs.pullRequestNumber }}
message: ${{ steps.playwright-summary.outputs.summary }}
message: |
:heavy_check_mark: <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/${{ steps.playwright-report-artifact-id.outputs.id }}">No visual changes detected by playwright, but flaky tests were detected; please try to fix the tests.</a>
- name: "[Comment] Success: No visual differences introduced by this PR"
uses: mshick/add-pr-comment@dd126dd8c253650d181ad9538d8b4fa218fc31e8 # pin@v2
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2
if: steps.playwright.outputs.MASTER_SCREENSHOTS_OUTCOME != 'failure' && steps.playwright.outputs.FLAKY == 0 && steps.playwright.outputs.FAILED == 0
with:
issue: ${{ steps.source-run-info.outputs.pullRequestNumber }}
message: ${{ steps.playwright-summary.outputs.summary }}
update-only: true
message: |
:heavy_check_mark: <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/${{ steps.playwright-report-artifact-id.outputs.id }}">No visual changes detected by playwright.</a>
update-only: true
36 changes: 35 additions & 1 deletion .github/workflows/publish-chrome-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
description: "Max attempts"
required: false
default: "10"
upload_url:
description: "The upload_url from the release created by create-prerelease-on-tag.yml"
required: true
permissions:
contents: read
jobs:
Expand All @@ -18,9 +21,9 @@ jobs:
environment: cd
outputs:
result: ${{ steps.webStorePublish.outcome }}
releaseUploadUrl: ${{ steps.getZipAsset.outputs.releaseUploadUrl }}
permissions:
actions: write
contents: write
steps:
- name: Get the next attempt number
id: getNextAttemptNumber
Expand Down Expand Up @@ -95,3 +98,34 @@ jobs:
with:
extensionId: ${{ secrets.G_DEVELOPMENT_EXTENSION_ID }}
apiAccessToken: ${{ steps.fetchAccessToken.outputs.accessToken }}

release-crx:
runs-on: ubuntu-latest
environment: cd
permissions:
actions: write
contents: write

steps:
- uses: robinraju/release-downloader@a96f54c1b5f5e09e47d9504526e96febd949d4c2 # [email protected]
with:
tag: ${{ github.ref_name }}
fileName: "*"

- name: Sign Chrome crx for offline distribution
uses: cardinalby/webext-buildtools-chrome-crx-action@v2
with:
zipFilePath: 'yomitan-chrome-dev.zip'
crxFilePath: 'yomitan-chrome-dev.crx'
privateKey: ${{ secrets.CHROME_CRX_PRIVATE_KEY }}

- name: Upload offline crx release asset
id: uploadReleaseAsset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ inputs.upload_url }}
asset_path: yomitan-chrome-dev.crx
asset_name: yomitan-chrome-dev.crx
asset_content_type: application/x-chrome-extension
1 change: 0 additions & 1 deletion .github/workflows/publish-chrome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
environment: cd
outputs:
result: ${{ steps.webStorePublish.outcome }}
releaseUploadUrl: ${{ steps.getZipAsset.outputs.releaseUploadUrl }}
permissions:
actions: write
steps:
Expand Down
2 changes: 1 addition & 1 deletion .htmlvalidate.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"elements": [
"html5"
]
}
}
4 changes: 1 addition & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

echo "Husky pre-commit hook"
npx lint-staged
2 changes: 1 addition & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
"@stylistic/string-quotes": "single",
"@stylistic/unit-case": "lower"
}
}
}
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"recommendations": [
"dbaeumer.vscode-eslint",
"html-validate.vscode-html-validate",
"stylelint.vscode-stylelint"
"stylelint.vscode-stylelint",
"codeandstuff.package-json-upgrade"
]
}
}
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"runtimeArgs": [
"run",
"test:unit",
"--",
"--"
// "test/text-source-range.test.js" // Replace and uncomment this line to run a single test file
],
"runtimeExecutable": "npm",
Expand All @@ -17,4 +17,4 @@
"type": "node"
}
]
}
}
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"source.addMissingImports": "explicit",
"source.organizeImports": "explicit",
"source.fixAll.eslint": "explicit"
},
}
},
"[typescript]": {
"editor.codeActionsOnSave": {
"source.addMissingImports": "never",
"source.organizeImports": "never",
"source.fixAll.eslint": "explicit"
},
}
},
"eslint.format.enable": true,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The generated `ext/manfiest.json` should not be committed.
Linting rules are defined for a few types of files, and validation is performed as part of the standard tests
run by `npm test` and the continuous integration process.

- [.eslintrc.json](.eslintrc.json) rules are used for JavaScript files.
- [eslint.config.js](eslint.config.js) rules are used for JavaScript files.
- [.stylelintrc.json](.stylelintrc.json) rules are used for CSS files.
- [.htmlvalidate.json](.htmlvalidate.json) rules are used for HTML files.

Expand Down
7 changes: 7 additions & 0 deletions benches/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@
},
"types": [
"chrome",
"dom-webcodecs",
"firefox-webext-browser",
"handlebars",
"jszip",
"parse5",
"wanakana"
],
"lib": [
"ES2022",
"DOM",
"DOM.Iterable",
"WebWorker"
]
},
"include": [
Expand Down
3 changes: 3 additions & 0 deletions benches/translator.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import path from 'path';
import {bench, describe} from 'vitest';
import {parseJson} from '../dev/json.js';
import {createTranslatorContext} from '../test/fixtures/translator-test.js';
import {setupStubs} from '../test/utilities/database.js';
import {createFindKanjiOptions, createFindTermsOptions} from '../test/utilities/translator.js';

setupStubs();

const dirname = path.dirname(fileURLToPath(import.meta.url));
const dictionaryName = 'Test Dictionary 2';
const {translator} = await createTranslatorContext(path.join(dirname, '..', 'test', 'data/dictionaries/valid-dictionary1'), dictionaryName);
Expand Down
Loading

0 comments on commit ae28bbc

Please sign in to comment.