From 3bc791bcba97f0810165c7a2e215563993a0989b Mon Sep 17 00:00:00 2001 From: Dominik G Date: Tue, 9 May 2023 20:01:56 +0200 Subject: [PATCH 1/6] feat: add workflow to trigger ecosystem-ci from svelte PRs (#8571) --- .github/workflows/ecosystem-ci-trigger.yml | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/ecosystem-ci-trigger.yml diff --git a/.github/workflows/ecosystem-ci-trigger.yml b/.github/workflows/ecosystem-ci-trigger.yml new file mode 100644 index 000000000000..952f83a861f8 --- /dev/null +++ b/.github/workflows/ecosystem-ci-trigger.yml @@ -0,0 +1,93 @@ +name: ecosystem-ci trigger + +on: + issue_comment: + types: [created] + +jobs: + trigger: + runs-on: ubuntu-latest + if: github.repository == 'sveltejs/svelte' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/ecosystem-ci run') + steps: + - uses: actions/github-script@v6 + with: + script: | + const user = context.payload.sender.login + console.log(`Validate user: ${user}`) + + let hasTriagePermission = false + try { + const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ + owner: context.repo.owner, + repo: context.repo.repo, + username: user, + }); + hasTriagePermission = data.user.permissions.triage + } catch (e) { + console.warn(e) + } + + if (hasTriagePermission) { + console.log('Allowed') + await github.rest.reactions.createForIssueComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: '+1', + }) + } else { + console.log('Not allowed') + await github.rest.reactions.createForIssueComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: '-1', + }) + throw new Error('not allowed') + } + - uses: actions/github-script@v6 + id: get-pr-data + with: + script: | + console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`) + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }) + return { + num: context.issue.number, + branchName: pr.head.ref, + repo: pr.head.repo.full_name + } + - id: generate-token + uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 #keep pinned for security reasons, currently 1.8.0 + with: + app_id: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }} + private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }} + repository: "${{ github.repository_owner }}/svelte-ecosystem-ci" + - uses: actions/github-script@v6 + id: trigger + env: + COMMENT: ${{ github.event.comment.body }} + with: + github-token: ${{ steps.generate-token.outputs.token }} + result-encoding: string + script: | + const comment = process.env.COMMENT.trim() + const prData = ${{ steps.get-pr-data.outputs.result }} + + const suite = comment.split('\n')[0].replace(/^\/ecosystem-ci run/, '').trim() + + await github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: 'svelte-ecosystem-ci', + workflow_id: 'ecosystem-ci-from-pr.yml', + ref: 'main', + inputs: { + prNumber: '' + prData.num, + branchName: prData.branchName, + repo: prData.repo, + suite: suite === '' ? '-' : suite + } + }) From 235e5120865c60e2caad85582a1ecc8c12f12d65 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Wed, 24 May 2023 21:29:29 +0300 Subject: [PATCH 2/6] fix(perf): use classList.toggle instead of shenanigans `classList.toggle(..., flag)` has been a part of the DOM standard forever, so better use it instead of possibly causing browser deopts by using dynamic attribute access. The `!!` is required because an `undefined` flag means flipping the current state. --- src/runtime/internal/dom.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 066fa6eb1c02..db29ef698876 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -753,7 +753,7 @@ export const resize_observer_device_pixel_content_box = /* @__PURE__ */ new Resi export { ResizeObserverSingleton }; export function toggle_class(element, name, toggle) { - element.classList[toggle ? 'add' : 'remove'](name); + element.classList.toggle(name, !!toggle); } export function custom_event(type: string, detail?: T, { bubbles = false, cancelable = false } = {}): CustomEvent { From 07ef0af72a3336fae170d4166c1349507a56a338 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 24 May 2023 15:34:14 -0700 Subject: [PATCH 3/6] remove file that snuck onto PR --- .github/workflows/ecosystem-ci-trigger.yml | 93 ---------------------- 1 file changed, 93 deletions(-) delete mode 100644 .github/workflows/ecosystem-ci-trigger.yml diff --git a/.github/workflows/ecosystem-ci-trigger.yml b/.github/workflows/ecosystem-ci-trigger.yml deleted file mode 100644 index 952f83a861f8..000000000000 --- a/.github/workflows/ecosystem-ci-trigger.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: ecosystem-ci trigger - -on: - issue_comment: - types: [created] - -jobs: - trigger: - runs-on: ubuntu-latest - if: github.repository == 'sveltejs/svelte' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/ecosystem-ci run') - steps: - - uses: actions/github-script@v6 - with: - script: | - const user = context.payload.sender.login - console.log(`Validate user: ${user}`) - - let hasTriagePermission = false - try { - const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ - owner: context.repo.owner, - repo: context.repo.repo, - username: user, - }); - hasTriagePermission = data.user.permissions.triage - } catch (e) { - console.warn(e) - } - - if (hasTriagePermission) { - console.log('Allowed') - await github.rest.reactions.createForIssueComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: context.payload.comment.id, - content: '+1', - }) - } else { - console.log('Not allowed') - await github.rest.reactions.createForIssueComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: context.payload.comment.id, - content: '-1', - }) - throw new Error('not allowed') - } - - uses: actions/github-script@v6 - id: get-pr-data - with: - script: | - console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`) - const { data: pr } = await github.rest.pulls.get({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.issue.number - }) - return { - num: context.issue.number, - branchName: pr.head.ref, - repo: pr.head.repo.full_name - } - - id: generate-token - uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 #keep pinned for security reasons, currently 1.8.0 - with: - app_id: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }} - private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }} - repository: "${{ github.repository_owner }}/svelte-ecosystem-ci" - - uses: actions/github-script@v6 - id: trigger - env: - COMMENT: ${{ github.event.comment.body }} - with: - github-token: ${{ steps.generate-token.outputs.token }} - result-encoding: string - script: | - const comment = process.env.COMMENT.trim() - const prData = ${{ steps.get-pr-data.outputs.result }} - - const suite = comment.split('\n')[0].replace(/^\/ecosystem-ci run/, '').trim() - - await github.rest.actions.createWorkflowDispatch({ - owner: context.repo.owner, - repo: 'svelte-ecosystem-ci', - workflow_id: 'ecosystem-ci-from-pr.yml', - ref: 'main', - inputs: { - prNumber: '' + prData.num, - branchName: prData.branchName, - repo: prData.repo, - suite: suite === '' ? '-' : suite - } - }) From 7df1e06ee590aa7921ab31c8493e6d91ccc7b9db Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 26 May 2023 13:08:09 +0200 Subject: [PATCH 4/6] Update src/runtime/internal/dom.js Co-authored-by: Rich Harris --- src/runtime/internal/dom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/internal/dom.js b/src/runtime/internal/dom.js index 8a78a38e03d7..85023f4e42b1 100644 --- a/src/runtime/internal/dom.js +++ b/src/runtime/internal/dom.js @@ -993,7 +993,7 @@ export { ResizeObserverSingleton }; /** * @returns {void} */ export function toggle_class(element, name, toggle) { - element.classList.toggle(name, !!toggle); + element.classList.toggle(name, toggle); } /** From 4830d59750c21201ef2cf967d36e80b556407ba5 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 26 May 2023 13:19:58 +0200 Subject: [PATCH 5/6] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbafadc80703..901f159679dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * **breaking** Error on falsy values instead of stores passed to `derived` ([#7947](https://github.com/sveltejs/svelte/pull/7947)) * **breaking** Custom store implementers now need to pass an `update` function additionally to the `set` function ([#6750](https://github.com/sveltejs/svelte/pull/6750)) * **breaking** Change order in which preprocessors are applied ([#8618](https://github.com/sveltejs/svelte/pull/8618)) +* **breaking** The runtime now makes use of `classList.toggle(name, boolean)` which does not work in very old browsers ([#8629](https://github.com/sveltejs/svelte/pull/8629)) * Add a way to modify attributes for script/style preprocessors ([#8618](https://github.com/sveltejs/svelte/pull/8618)) * Improve hydration speed by adding `data-svelte-h` attribute to detect unchanged HTML elements ([#7426](https://github.com/sveltejs/svelte/pull/7426)) * Add `a11y no-noninteractive-element-interactions` rule ([#8391](https://github.com/sveltejs/svelte/pull/8391)) From 79c31c34c66f8dc2209f7718630ee0c2b0863fee Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 26 May 2023 13:22:00 +0200 Subject: [PATCH 6/6] Update src/runtime/internal/dom.js --- src/runtime/internal/dom.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime/internal/dom.js b/src/runtime/internal/dom.js index 85023f4e42b1..aced965a6754 100644 --- a/src/runtime/internal/dom.js +++ b/src/runtime/internal/dom.js @@ -993,7 +993,8 @@ export { ResizeObserverSingleton }; /** * @returns {void} */ export function toggle_class(element, name, toggle) { - element.classList.toggle(name, toggle); + // The `!!` is required because an `undefined` flag means flipping the current state. + element.classList.toggle(name, !!toggle); } /**