Commit 5628fbe7 authored by nanahira's avatar nanahira

Merge branch 'master' into pics

parents a200bb25 428c91ee
...@@ -8,17 +8,33 @@ variables: ...@@ -8,17 +8,33 @@ variables:
CONTAINER_TEST_ARM_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm CONTAINER_TEST_ARM_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
CONTAINER_TEST_X86_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86 CONTAINER_TEST_X86_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY build_package:
build-x86:
stage: build stage: build
tags:
- linux
script:
- npm ci
- npm run build
artifacts:
paths:
- dist/
.docker_op:
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
tags: tags:
- docker - docker
build-x86:
extends: .docker_op
stage: build
script: script:
- TARGET_IMAGE=$CONTAINER_TEST_X86_IMAGE - TARGET_IMAGE=$CONTAINER_TEST_X86_IMAGE
- docker build --pull -t $TARGET_IMAGE . - docker build --pull -t $TARGET_IMAGE .
- docker push $TARGET_IMAGE - docker push $TARGET_IMAGE
build-arm: build-arm:
extends: .docker_op
stage: build stage: build
tags: tags:
- docker-arm - docker-arm
...@@ -28,8 +44,6 @@ build-arm: ...@@ -28,8 +44,6 @@ build-arm:
- docker push $TARGET_IMAGE - docker push $TARGET_IMAGE
combine: combine:
stage: combine stage: combine
tags:
- docker
script: script:
- TARGET_IMAGE=$CONTAINER_TEST_IMAGE - TARGET_IMAGE=$CONTAINER_TEST_IMAGE
- SOURCE_IMAGE_2=$CONTAINER_TEST_ARM_IMAGE - SOURCE_IMAGE_2=$CONTAINER_TEST_ARM_IMAGE
...@@ -41,8 +55,6 @@ combine: ...@@ -41,8 +55,6 @@ combine:
- docker manifest push $TARGET_IMAGE - docker manifest push $TARGET_IMAGE
deploy_latest: deploy_latest:
stage: deploy stage: deploy
tags:
- docker
script: script:
- TARGET_IMAGE=$CONTAINER_RELEASE_IMAGE - TARGET_IMAGE=$CONTAINER_RELEASE_IMAGE
- SOURCE_IMAGE=$CONTAINER_TEST_IMAGE - SOURCE_IMAGE=$CONTAINER_TEST_IMAGE
...@@ -52,9 +64,8 @@ deploy_latest: ...@@ -52,9 +64,8 @@ deploy_latest:
only: only:
- master - master
deploy_tag: deploy_tag:
extends: .docker_op
stage: deploy stage: deploy
tags:
- docker
script: script:
- TARGET_IMAGE=$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG - TARGET_IMAGE=$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- SOURCE_IMAGE=$CONTAINER_TEST_IMAGE - SOURCE_IMAGE=$CONTAINER_TEST_IMAGE
...@@ -63,3 +74,16 @@ deploy_tag: ...@@ -63,3 +74,16 @@ deploy_tag:
- docker push $TARGET_IMAGE - docker push $TARGET_IMAGE
only: only:
- tags - tags
deploy_npm:
stage: deploy
dependencies:
- build_package
tags:
- linux
script:
- apt update;apt -y install coreutils
- echo $NPMRC | base64 --decode > ~/.npmrc
- npm publish . || true
only:
- master
...@@ -5,13 +5,17 @@ ...@@ -5,13 +5,17 @@
"scripts": { "scripts": {
"lint": "eslint --fix .", "lint": "eslint --fix .",
"build": "tsc", "build": "tsc",
"plugin": "node dist/install-plugin.js", "plugin": "node dist/entry.js install",
"prod": "node dist/entry.js prod",
"start": "koishi start" "start": "koishi start"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://code.mycard.moe/3rdeye/koishi-bootstrap.git" "url": "https://code.mycard.moe/3rdeye/koishi-bootstrap.git"
}, },
"bin": {
"koishi-bs": "./dist/entry.js"
},
"author": "Nanahira <nanahira@momobako.com>", "author": "Nanahira <nanahira@momobako.com>",
"license": "MIT", "license": "MIT",
"keywords": [], "keywords": [],
......
import { installPluginEntry } from './install-plugin';
import { prodEntry } from './prod';
const choice = process.argv[2];
switch (choice) {
case 'install':
installPluginEntry();
break;
case 'prod':
prodEntry();
break;
default:
console.log(`Unknown command '${choice}'.`);
process.exit(1);
}
...@@ -6,6 +6,7 @@ import { exec } from 'child_process'; ...@@ -6,6 +6,7 @@ import { exec } from 'child_process';
import { promisify } from 'util'; import { promisify } from 'util';
import loadJsonFile from 'load-json-file'; import loadJsonFile from 'load-json-file';
import path from 'path'; import path from 'path';
import { getPackageJsonPackages } from './utils/read-package-json';
const execAsync = promisify(exec); const execAsync = promisify(exec);
const logger = new Logger('bootstrap'); const logger = new Logger('bootstrap');
...@@ -36,11 +37,6 @@ async function loadConfig(): Promise<KoishiConfig | undefined> { ...@@ -36,11 +37,6 @@ async function loadConfig(): Promise<KoishiConfig | undefined> {
} }
} }
async function getPackageJsonPackages() {
const { dependencies } = await loadJsonFile<PackageConfig>('./package.json');
return dependencies;
}
async function checkPluginExists( async function checkPluginExists(
name: string, name: string,
allowCommunity: boolean, allowCommunity: boolean,
...@@ -143,8 +139,8 @@ async function installPlugin(name: string, info: any) { ...@@ -143,8 +139,8 @@ async function installPlugin(name: string, info: any) {
} }
} }
async function main() { export async function installPluginEntry() {
logger.info(`Bootstrapping`); logger.info(`Bootstrapping...`);
const config = await loadConfig(); const config = await loadConfig();
const plugins = config?.plugins; const plugins = config?.plugins;
if (!plugins) { if (!plugins) {
...@@ -161,4 +157,3 @@ async function main() { ...@@ -161,4 +157,3 @@ async function main() {
} }
logger.info(`Bootstrap finished.`); logger.info(`Bootstrap finished.`);
} }
main();
import path from 'path';
import { getPackageJsonPackages } from './utils/read-package-json';
import fs from 'fs';
async function handlePackageEntry(packageName: string, versionString: string) {
if (!versionString.startsWith('file:')) {
return;
}
console.log(`Cleaning package ${packageName}...`);
const packagePath = versionString.slice(5);
const packagesToRemove = ['koishi', '@koishijs/core', '@koishijs/utils'].map(
(p) => path.join(packagePath, 'node_modules', p),
);
await Promise.all(
packagesToRemove.map(async (path) => {
try {
await fs.promises.access(path);
console.log(`Removing ${path} ...`);
// await fs.promises.rmdir(path, { recursive: true });
} catch (e) {}
}),
);
}
export async function prodEntry() {
console.log(`Running production preparations...`);
const deps = await getPackageJsonPackages();
const entries = Object.entries(deps);
await Promise.all(
entries.map((entry) => handlePackageEntry(entry[0], entry[1])),
);
console.log(`Done.`);
}
import loadJsonFile from 'load-json-file';
import { PackageConfig } from '../def/interfaces';
export async function getPackageJsonPackages() {
const { dependencies } = await loadJsonFile<PackageConfig>('./package.json');
return dependencies;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment