-
-
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 pull request #386 from ikemo3/package/replace-scripts
package: replace scripts
- Loading branch information
Showing
10 changed files
with
340 additions
and
223 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
# | ||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details | ||
# | ||
version: '2.1' | ||
version: "2.1" | ||
orbs: | ||
browser-tools: circleci/[email protected] | ||
browser-tools: circleci/[email protected] | ||
jobs: | ||
build: | ||
docker: | ||
- image: cimg/node:18.4.0-browsers | ||
- image: cimg/node:16.16-browsers | ||
environment: | ||
- LANG: ja_JP.UTF-8 | ||
- LANGUAGE: ja_JP.UTF-8 | ||
|
@@ -17,29 +17,19 @@ jobs: | |
|
||
steps: | ||
- checkout | ||
- browser-tools/install-chrome | ||
- browser-tools/install-chromedriver | ||
- run: | ||
name: "Install Japanese font" | ||
command: | | ||
sudo apt update | ||
sudo apt install -y fonts-takao-gothic | ||
- run: | ||
name: "Download Firefox Developer Edition" | ||
command: | | ||
curl -L 'https://download.mozilla.org/?product=firefox-devedition-latest-ssl&os=linux64&lang=ja' > firefox.tar.bz2 | ||
tar xvfj firefox.tar.bz2 | ||
- run: | ||
command: make ci | ||
- store_test_results: | ||
path: reports | ||
- store_artifacts: | ||
path: reports | ||
- persist_to_workspace: | ||
root: tmp/workspace | ||
paths: | ||
- gossip-site-blocker.* | ||
- gossip-site-blocker-* | ||
deploy: | ||
docker: | ||
- image: cimg/go:1.17.1 | ||
- image: cimg/node:16.16 | ||
|
||
working_directory: ~/repo | ||
|
||
|
@@ -49,7 +39,16 @@ jobs: | |
at: tmp/workspace | ||
- run: | ||
name: "Publish Release on GitHub" | ||
command: make deploy | ||
command: | | ||
# install ghr | ||
sudo apt update | ||
sudo apt install -y golang | ||
go get -u -v github.com/tcnksm/ghr | ||
# deploy | ||
yarn install | ||
export PATH=$PATH:~/go/bin | ||
make deploy | ||
workflows: | ||
version: 2 | ||
|
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ ci: | |
./scripts/ci.sh | ||
|
||
deploy: | ||
./scripts/deploy.sh | ||
yarn deploy |
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,58 +1,74 @@ | ||
import { writeFileSync } from "fs"; | ||
import { join } from "path"; | ||
import { execFileSync, execSync } from "child_process"; | ||
import { createManifest, getManifest, getPackageName, getWebExtensionId, mkdirIfNeeded, writeManifest } from "./libs"; | ||
import { distDir, projectTop } from "./const"; | ||
|
||
const packageName = getPackageName(); | ||
const pemBase64 = process.env.PEM_BASE64; | ||
|
||
// create manifest.json | ||
createManifest(); | ||
|
||
// create Chrome Extension | ||
mkdirIfNeeded(join(projectTop, "tmp")); | ||
mkdirIfNeeded(join(projectTop, "tmp", "workspace")); | ||
|
||
if (pemBase64 !== undefined) { | ||
// decode private key | ||
const buffer = Buffer.from(pemBase64, "base64"); | ||
const pem = buffer.toString(); | ||
const pemPath = join(projectTop, "tmp", `${packageName}.pem`); | ||
writeFileSync(pemPath, pem); | ||
|
||
// create Chrome Extension(signed) | ||
console.info(`Create ${packageName}.crx with private key`); | ||
execFileSync("yarn", [ | ||
"crx", | ||
"pack", | ||
"-o", | ||
`tmp/workspace/${packageName}.crx`, | ||
"dist", | ||
"-p", | ||
`tmp/${packageName}.pem`, | ||
]); | ||
} else { | ||
// create Chrome Extension(signed, create private key) | ||
console.info(`Create ${packageName}.crx`); | ||
execFileSync("yarn", ["crx", "pack", "-o", `tmp/workspace/${packageName}.crx`, "dist"]); | ||
import { copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs"; | ||
import path from "path"; | ||
import { execSync } from "child_process"; | ||
import { zip } from "zip-a-folder"; | ||
|
||
function clearDirectory(path: string) { | ||
if (existsSync(path)) { | ||
rmSync(path, { recursive: true }); | ||
} | ||
} | ||
|
||
function getPackageName(projectDir: string) { | ||
const packageJsonPath = projectDir + "/package.json"; | ||
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString()); | ||
return packageJson.name; | ||
} | ||
|
||
function getExtensionId(projectDir: string) { | ||
const extensionIdPath = projectDir + "/apps/.web-extension-id"; | ||
const webExtensionId = readFileSync(extensionIdPath).toString(); | ||
return webExtensionId.split("\n")[2]; | ||
} | ||
|
||
async function createChromeExtension(packageName: string, projectDir: string) { | ||
console.log(`Create ${packageName}.zip`); | ||
await zip(projectDir + "/dist-chrome", projectDir + `/tmp/workspace/${packageName}-chrome.zip`); | ||
} | ||
|
||
async function createFirefoxExtension(packageName: string, projectDir: string) { | ||
// load manifest.json | ||
const extensionId = getExtensionId(projectDir); | ||
console.log(`Extension ID: ${extensionId}`); | ||
|
||
const manifestJsonPath = projectDir + "/apps/manifest.json"; | ||
const manifestJson = JSON.parse(readFileSync(manifestJsonPath).toString()); | ||
manifestJson.browser_specific_settings = { gecko: { id: extensionId } }; | ||
|
||
// write manifest.json | ||
const manifestJsonWritePath = projectDir + "/dist-firefox/manifest.json"; | ||
writeFileSync(manifestJsonWritePath, JSON.stringify(manifestJson, null, 2)); | ||
|
||
// create Firefox extension(xpi) | ||
await zip(projectDir + "/dist-firefox", projectDir + `/tmp/workspace/${packageName}-firefox.xpi`); | ||
} | ||
|
||
async function main() { | ||
// create if there is no dist directory | ||
const projectDir = path.dirname(__dirname); | ||
clearDirectory(projectDir + "/dist-chrome"); | ||
clearDirectory(projectDir + "/dist-firefox"); | ||
clearDirectory(projectDir + "/tmp"); | ||
mkdirSync(projectDir + "/tmp"); | ||
mkdirSync(projectDir + "/tmp/workspace"); | ||
|
||
// copy resources | ||
execSync("webpack", { stdio: "inherit" }); | ||
cpSync(projectDir + "/dist", projectDir + "/dist-chrome", { recursive: true }); | ||
cpSync(projectDir + "/dist", projectDir + "/dist-firefox", { recursive: true }); | ||
copyFileSync(projectDir + "/apps/.web-extension-id", projectDir + "/dist-firefox/.web-extension-id"); | ||
|
||
// load package.json | ||
const packageName = getPackageName(projectDir); | ||
|
||
// create Chrome extension | ||
await createChromeExtension(packageName, projectDir); | ||
|
||
// create Firefox extension | ||
await createFirefoxExtension(packageName, projectDir); | ||
} | ||
|
||
// create Chrome Extension(unsigned) | ||
console.info(`Create ${packageName}.zip`); | ||
execFileSync("yarn", ["crx", "pack", "--zip-output", `tmp/workspace/${packageName}.zip`, "dist"]); | ||
|
||
// create Firefox Extension | ||
const manifest = getManifest(); | ||
const extensionId = getWebExtensionId(); | ||
manifest.browser_specific_settings = { | ||
gecko: { | ||
id: extensionId, | ||
}, | ||
}; | ||
console.info(`extension id: ${extensionId}`); | ||
writeManifest(manifest); | ||
|
||
// create *.xpi | ||
console.info(`Create ${packageName}.xpi`); | ||
execSync(`zip -r ../tmp/workspace/${packageName}.xpi *`, { cwd: distDir }); | ||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,60 @@ | ||
import { execSync, spawnSync } from "child_process"; | ||
import { readFileSync, renameSync } from "fs"; | ||
import path from "path"; | ||
import { isError, configureGhrOption } from "./libs"; | ||
|
||
function getGitSha() { | ||
const sha = execSync("git rev-parse HEAD"); | ||
return sha.toString().trim(); | ||
} | ||
|
||
function getManifestVersion(projectDir: string) { | ||
const manifestJsonPath = projectDir + "/apps/manifest.json"; | ||
const manifestJson = JSON.parse(readFileSync(manifestJsonPath).toString()); | ||
return manifestJson.version; | ||
} | ||
|
||
function getManifestVersionName(projectDir: string) { | ||
const manifestJsonPath = projectDir + "/apps/manifest.json"; | ||
const manifestJson = JSON.parse(readFileSync(manifestJsonPath).toString()); | ||
return manifestJson.version_name; | ||
} | ||
|
||
function getPackageVersion(projectDir: string) { | ||
const packageJsonPath = projectDir + "/package.json"; | ||
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString()); | ||
return packageJson.version; | ||
} | ||
|
||
function getPackageName(projectDir: string) { | ||
const packageJsonPath = projectDir + "/package.json"; | ||
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString()); | ||
return packageJson.name; | ||
} | ||
|
||
function main() { | ||
const projectDir = path.dirname(__dirname); | ||
|
||
const branch = process.env.CIRCLE_BRANCH; | ||
const tag = process.env.CIRCLE_TAG; | ||
const packageVersion = getPackageVersion(projectDir); | ||
const manifestVersion = getManifestVersion(projectDir); | ||
const manifestVersionName = getManifestVersionName(projectDir); | ||
|
||
const config = configureGhrOption(branch, tag, manifestVersion, manifestVersionName, packageVersion); | ||
if (isError(config)) { | ||
console.log(config.message); | ||
process.exit(config.exitCode); | ||
} | ||
|
||
const packageName = getPackageName(projectDir); | ||
|
||
renameSync(`tmp/workspace/${packageName}-chrome.zip`, `tmp/workspace/${packageName}-${config.name}-chrome.zip`); | ||
renameSync(`tmp/workspace/${packageName}-firefox.xpi`, `tmp/workspace/${packageName}-${config.name}-firefox.xpi`); | ||
|
||
const args = ["-c", getGitSha(), "-n", config.name, ...config.ghrOptions, config.tag, "tmp/workspace/"]; | ||
console.log("ghr", args); | ||
spawnSync("ghr", args); | ||
} | ||
|
||
main(); |
Oops, something went wrong.