-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into testing-doc
- Loading branch information
Showing
62 changed files
with
2,837 additions
and
3,009 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// @ts-check | ||
/* eslint-disable @typescript-eslint/no-var-requires, no-console */ | ||
const fs = require('node:fs/promises') | ||
|
||
/** @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments */ | ||
module.exports = async ({ core }) => { | ||
const manifestPath = './src/manifest.json' | ||
const manifestFile = await fs.readFile(manifestPath, 'utf8') | ||
const manifest = JSON.parse(manifestFile) | ||
/**@type {string} */ | ||
const existingVersion = manifest.version | ||
|
||
const bumpType = /** @type {BumpType} */ (process.env.INPUT_VERSION) | ||
if (!bumpType) { | ||
throw new Error('Missing bump type') | ||
} | ||
|
||
const version = bumpVersion(existingVersion, bumpType).join('.') | ||
|
||
console.log({ existingVersion, bumpType, version }) | ||
|
||
manifest.version = version | ||
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2)) | ||
core.setOutput('version', version) | ||
} | ||
|
||
/** | ||
* @typedef {'build' | 'patch' | 'minor'} BumpType | ||
* @param {string} existingVersion | ||
* @param {BumpType} type | ||
* @return {[major: number, minor: number, patch: number, build: number]} | ||
*/ | ||
function bumpVersion(existingVersion, type) { | ||
const parts = existingVersion.split('.').map(Number) | ||
if (parts.length !== 4 || parts.some((e) => !Number.isSafeInteger(e))) { | ||
throw new Error('Existing version does not have right format') | ||
} | ||
const [major, minor, patch, build] = parts | ||
|
||
switch (type) { | ||
case 'build': | ||
return [major, minor, patch, build + 1] | ||
case 'patch': | ||
return [major, minor, patch + 1, 0] | ||
case 'minor': | ||
return [major, minor + 1, 0, 0] | ||
default: | ||
throw new Error('Unknown bump type: ' + type) | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,61 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable no-console */ | ||
// @ts-check | ||
/* eslint-disable @typescript-eslint/no-var-requires, no-console */ | ||
const { BROWSERS } = require('./constants.cjs') | ||
|
||
async function getBrowserArfifacts({ github, owner, repo, name }) { | ||
const artifacts = [] | ||
/** | ||
* @param {Pick<import('github-script').AsyncFunctionArguments, 'github' | 'context'>} AsyncFunctionArguments | ||
* @param {string} name | ||
*/ | ||
async function getBrowserArtifacts({ github, context }, name) { | ||
const result = await github.rest.actions.listArtifactsForRepo({ | ||
owner, | ||
repo, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name | ||
}) | ||
|
||
for (let i = 0; i < result.data.total_count; i++) { | ||
artifacts.push(result.data.artifacts[i].id) | ||
} | ||
|
||
return artifacts | ||
return result.data.artifacts | ||
} | ||
|
||
async function getPRArtifacts({ github, owner, repo, prNumber }) { | ||
const promises = [] | ||
const artifacts = [] | ||
|
||
BROWSERS.forEach((browser) => | ||
promises.push( | ||
getBrowserArfifacts({ | ||
github, | ||
owner, | ||
repo, | ||
name: `${prNumber}-${browser}` | ||
}) | ||
/** | ||
* @param {Pick<import('github-script').AsyncFunctionArguments, 'github' | 'context'>} AsyncFunctionArguments | ||
* @param {number} prNumber | ||
*/ | ||
async function getPRArtifacts({ github, context }, prNumber) { | ||
const data = await Promise.all( | ||
BROWSERS.map((browser) => | ||
getBrowserArtifacts({ github, context }, `${prNumber}-${browser}`) | ||
) | ||
) | ||
|
||
const data = await Promise.all(promises) | ||
|
||
/** @type {{id: number}[]} */ | ||
const artifacts = [] | ||
for (let i = 0; i < data.length; i++) { | ||
// same as `artifacts.push(...data[i])` but it's a bit faster | ||
artifacts.push.apply(artifacts, data[i]) | ||
} | ||
|
||
return artifacts | ||
} | ||
|
||
/** @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments */ | ||
module.exports = async ({ github, context, core }) => { | ||
if (context.payload.action !== 'closed') { | ||
core.setFailed('This action only works on closed PRs.') | ||
} | ||
|
||
const { owner, repo } = context.repo | ||
/** @type {number} */ | ||
const prNumber = context.payload.number | ||
const promises = [] | ||
|
||
const artifacts = await getPRArtifacts({ github, owner, repo, prNumber }) | ||
const artifacts = await getPRArtifacts({ github, context }, prNumber) | ||
|
||
for (let i = 0; i < artifacts.length; i++) { | ||
promises.push( | ||
await Promise.all( | ||
artifacts.map((artifact) => | ||
github.rest.actions.deleteArtifact({ | ||
owner, | ||
repo, | ||
artifact_id: artifacts[i] | ||
artifact_id: artifact.id | ||
}) | ||
) | ||
} | ||
) | ||
|
||
await Promise.all(promises) | ||
console.log(`Deleted ${artifacts.length} artifacts for PR #${prNumber}.`) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @ts-check | ||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-var-requires */ | ||
const fs = require('node:fs/promises') | ||
|
||
/** | ||
* Retrieves the manifest version from the built extension. | ||
* @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments | ||
*/ | ||
module.exports = async ({ core }) => { | ||
const manifest = await fs | ||
.readFile('./dist/chrome/manifest.json', 'utf8') | ||
.then(JSON.parse) | ||
|
||
core.setOutput('version', manifest.version) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
name: Environment setup | ||
description: Sets up Node and pnpm | ||
|
||
runs: | ||
using: 'composite' | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// @ts-check | ||
|
||
/** | ||
* 1. Validate input version. | ||
* 2. Check if given tag/release is already promoted to stable. If so, crash. | ||
* @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments | ||
*/ | ||
module.exports = async ({ github, context }) => { | ||
if (context.ref !== 'refs/heads/main') { | ||
throw new Error('This action only works on main branch') | ||
} | ||
|
||
const { owner, repo } = context.repo | ||
const previewVersionTag = process.env.INPUT_VERSION | ||
if (!previewVersionTag) { | ||
throw new Error('Missing env.INPUT_VERSION') | ||
} | ||
if (!previewVersionTag.match(/^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+-preview$/)) { | ||
throw new Error('Input "version" must match vX.X.X.X-preview') | ||
} | ||
|
||
const versionTag = previewVersionTag.replace('-preview', '') | ||
try { | ||
await github.rest.repos.getReleaseByTag({ | ||
owner, | ||
repo, | ||
tag: versionTag | ||
}) | ||
throw new Error('Release already promoted to stable') | ||
} catch (error) { | ||
if (!error.status) { | ||
throw error | ||
} | ||
if (error.status === 404) { | ||
// do nothing | ||
} else { | ||
throw new Error(`Failed to check: HTTP ${error.status}`, { cause: error }) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.