mirror of
https://github.com/seepine/action-miniprogram-ci.git
synced 2025-04-07 05:30:15 +08:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b277a85ced | ||
|
6166125503 | ||
|
9d2b9bf1d6 | ||
|
1d7b9db8ea | ||
|
53aca87be0 | ||
|
73e3fda388 | ||
|
d7c77b36b1 | ||
|
3b085a9e01 | ||
|
cfeb1f9e74 |
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
// 保存时执行eslint
|
// 保存时执行eslint
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true
|
"source.fixAll.eslint": "explicit"
|
||||||
},
|
},
|
||||||
// 从不展示扩展缩写
|
// 从不展示扩展缩写
|
||||||
"emmet.showExpandedAbbreviation": "never",
|
"emmet.showExpandedAbbreviation": "never",
|
||||||
|
16
README.md
16
README.md
@ -64,13 +64,15 @@ appid 和 setting 相关设置将会自动从 `project.config.json` 文件中读
|
|||||||
|
|
||||||
| Name | Description | Default |
|
| Name | Description | Default |
|
||||||
| ------------------ | ------------------------------------------------------------------------------------------------------------- | --------------------- |
|
| ------------------ | ------------------------------------------------------------------------------------------------------------- | --------------------- |
|
||||||
| mode | ci 模式,可选 upload/preview. | upload |
|
| platform | ci 平台,可选 wechat/douyin | wechat |
|
||||||
| type | 小程序类型,可选 miniProgram/miniProgramPlugin/miniGame/miniGamePlugin | miniProgram |
|
| ci-version | ci的版本,默认值 `miniprogram-ci@2.0.8`, `tt-ide-cli@0.1.27` | |
|
||||||
| project-path | 项目的路径,即 project.config.json 所在的目录,默认根路径,即./, 若 uniapp 项目,一般传入./dist/build/mp-weixin | ./ |
|
| mode | ci 模式,可选 upload/preview. | upload |
|
||||||
| private-key | 私钥,在获取项目属性和上传时用于鉴权使用,在微信公众平台上登录后下载, 建议通过 secrets 设置 | |
|
| type | 小程序类型,可选 miniProgram/miniProgramPlugin/miniGame/miniGamePlugin | miniProgram |
|
||||||
| private-key-path | 私钥完整路径,private-key 为空时使用路径值,例如./private.key | |
|
| project-path | 项目的路径,即 project.config.json 所在的目录,默认根路径,即./, 若 uniapp 项目,一般传入./dist/build/mp-weixin | ./ |
|
||||||
| ignores | 指定需要排除的规则,默认忽略 node_modules 路径 | node_modules/**/* |
|
| private-key | 私钥,在获取项目属性和上传时用于鉴权使用,在微信公众平台上登录后下载, 建议通过 secrets 设置 | |
|
||||||
| version | 自定义版本号,空则根据时间戳自动生成 YYYY.MMDD.HHmmss | YYYY.MMDD.HHmmss |
|
| private-key-path | 私钥完整路径,private-key 为空时使用路径值,例如./private.key | |
|
||||||
|
| ignores | 指定需要排除的规则,默认忽略 node_modules 路径 | node_modules/**/* |
|
||||||
|
| version | 自定义版本号,空则根据时间戳自动生成 YYYY.MMDD.HHmmss | YYYY.MMDD.HHmmss |
|
||||||
| desc | 自定义备注 | 'fix some bug.' |
|
| desc | 自定义备注 | 'fix some bug.' |
|
||||||
| robot | 指定使用哪一个 ci 机器人,可选值:1 ~ 30 | 1 |
|
| robot | 指定使用哪一个 ci 机器人,可选值:1 ~ 30 | 1 |
|
||||||
| threads | 指定本地编译过程中开启的线程数 | 默认获取 cpu 线程数 |
|
| threads | 指定本地编译过程中开启的线程数 | 默认获取 cpu 线程数 |
|
||||||
|
10
action.yml
10
action.yml
@ -1,11 +1,18 @@
|
|||||||
name: 'action-miniprogram-ci'
|
name: 'action-miniprogram-ci'
|
||||||
description: '将 miniprogram-ci 封装为 action,通过 Actions 实现小程序自动化上传/预览'
|
description: '将 miniprogram-ci 封装为 action,通过 Actions 实现小程序自动化上传/预览'
|
||||||
author: 'seepine'
|
author: 'seepine'
|
||||||
|
branding:
|
||||||
|
icon: package
|
||||||
|
color: orange
|
||||||
inputs:
|
inputs:
|
||||||
mode:
|
mode:
|
||||||
required: false
|
required: false
|
||||||
description: 'ci模式,默认upload,可选preview'
|
description: 'ci模式,默认upload,可选preview'
|
||||||
default: 'upload'
|
default: 'upload'
|
||||||
|
platform:
|
||||||
|
required: false
|
||||||
|
description: '平台,默认wechat,可选douyin'
|
||||||
|
default: 'wechat'
|
||||||
type:
|
type:
|
||||||
required: false
|
required: false
|
||||||
description: '小程序类型,默认miniProgram,可选miniProgram/miniProgramPlugin/miniGame/miniGamePlugin'
|
description: '小程序类型,默认miniProgram,可选miniProgram/miniProgramPlugin/miniGame/miniGamePlugin'
|
||||||
@ -64,6 +71,9 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
description: '设置输出文件路径,默认为./output.txt'
|
description: '设置输出文件路径,默认为./output.txt'
|
||||||
default: './output.txt'
|
default: './output.txt'
|
||||||
|
ci-version:
|
||||||
|
required: false
|
||||||
|
description: 'ci版本'
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node16'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
5605
dist/index.js
generated
vendored
5605
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
34
package.json
34
package.json
@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "action-miniprogram-ci",
|
"name": "action-miniprogram-ci",
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "将 miniprogram-ci 封装为 action, 通过 Actions 实现小程序自动化上传/预览",
|
"description": "将 miniprogram-ci 封装为 action, 通过 Actions 实现小程序自动化上传/预览",
|
||||||
"main": "lib/main.js",
|
"main": "lib/main.js",
|
||||||
|
"packageManager": "yarn@1.22.19",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write **/*.ts",
|
||||||
@ -24,23 +25,22 @@
|
|||||||
"author": "seepine",
|
"author": "seepine",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "~1.10.0",
|
"@actions/core": "1.10.0",
|
||||||
"jimp": "~0.22.10",
|
"jimp": "0.22.10",
|
||||||
"jsqr": "~1.4.0",
|
"jsqr": "1.4.0",
|
||||||
"qrcode-terminal": "~0.12.0"
|
"qrcode-terminal": "0.12.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "~18.16.3",
|
"@types/node": "18.16.3",
|
||||||
"@typescript-eslint/parser": "~5.59.2",
|
"@typescript-eslint/parser": "5.59.2",
|
||||||
"@vercel/ncc": "~0.36.1",
|
"@vercel/ncc": "0.36.1",
|
||||||
"eslint": "~8.39.0",
|
"eslint": "8.39.0",
|
||||||
"eslint-plugin-github": "~4.7.0",
|
"eslint-plugin-github": "4.7.0",
|
||||||
"eslint-plugin-jest": "~27.2.1",
|
"eslint-plugin-jest": "27.2.1",
|
||||||
"jest": "~29.5.0",
|
"jest": "29.5.0",
|
||||||
"js-yaml": "~4.1.0",
|
"js-yaml": "4.1.0",
|
||||||
"miniprogram-ci": "~1.9.8",
|
"prettier": "2.8.8",
|
||||||
"prettier": "~2.8.8",
|
"ts-jest": "29.1.0",
|
||||||
"ts-jest": "~29.1.0",
|
"typescript": "5.0.4"
|
||||||
"typescript": "~5.0.4"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ export const preview = async (option: Preview): Promise<string> => {
|
|||||||
}
|
}
|
||||||
const command = [
|
const command = [
|
||||||
'npx',
|
'npx',
|
||||||
'miniprogram-ci',
|
`miniprogram-ci@${option.ciVersion || '2.0.8'}`,
|
||||||
'preview',
|
'preview',
|
||||||
...getArgs(option),
|
...getArgs(option),
|
||||||
...previewArgs
|
...previewArgs
|
||||||
|
@ -4,9 +4,12 @@ import {getArgs} from './utils'
|
|||||||
import * as cp from 'child_process'
|
import * as cp from 'child_process'
|
||||||
|
|
||||||
export const upload = async (option: Upload): Promise<void> => {
|
export const upload = async (option: Upload): Promise<void> => {
|
||||||
const command = ['npx', 'miniprogram-ci', 'upload', ...getArgs(option)].join(
|
const command = [
|
||||||
' '
|
'npx',
|
||||||
)
|
`miniprogram-ci@${option.ciVersion || '2.0.8'}`,
|
||||||
|
'upload',
|
||||||
|
...getArgs(option)
|
||||||
|
].join(' ')
|
||||||
|
|
||||||
core.info('Command:')
|
core.info('Command:')
|
||||||
core.info(` ${command}`)
|
core.info(` ${command}`)
|
||||||
|
41
src/douyin/preview.ts
Normal file
41
src/douyin/preview.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import {Preview} from '../type'
|
||||||
|
import * as core from '@actions/core'
|
||||||
|
import {generate, getQrCode} from '../utils/qrcode'
|
||||||
|
import fs from 'fs'
|
||||||
|
import {getArgs} from './utils'
|
||||||
|
import * as cp from 'child_process'
|
||||||
|
|
||||||
|
export const preview = async (option: Preview): Promise<string> => {
|
||||||
|
cp.execSync(
|
||||||
|
[
|
||||||
|
'npx',
|
||||||
|
`tt-ide-cli@${option.ciVersion || '0.1.27'}`,
|
||||||
|
'set-app-config',
|
||||||
|
option.appid,
|
||||||
|
'--token',
|
||||||
|
option.privateKey
|
||||||
|
].join(' ')
|
||||||
|
)
|
||||||
|
|
||||||
|
const command = [
|
||||||
|
'npx',
|
||||||
|
`tt-ide-cli@${option.ciVersion || '0.1.27'}`,
|
||||||
|
'preview',
|
||||||
|
...getArgs(option),
|
||||||
|
'--qrcode-output',
|
||||||
|
option.qrcodeOutputDest,
|
||||||
|
option.projectPath
|
||||||
|
].join(' ')
|
||||||
|
core.info('Command:')
|
||||||
|
core.info(` ${command}`)
|
||||||
|
cp.execSync(command)
|
||||||
|
cp.execSync(`npx ${`tt-ide-cli@${option.ciVersion || '0.1.27'}`} logout`)
|
||||||
|
if (option.qrcodeFormat === 'terminal') {
|
||||||
|
const qrcodeData = await getQrCode(option.qrcodeOutputDest)
|
||||||
|
const qrcode = await generate(qrcodeData)
|
||||||
|
core.info(`Generate terminal qrcode:\n${qrcode}`)
|
||||||
|
fs.promises.unlink(option.qrcodeOutputDest)
|
||||||
|
return qrcode
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
}
|
28
src/douyin/upload.ts
Normal file
28
src/douyin/upload.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import {Upload} from '../type'
|
||||||
|
import * as core from '@actions/core'
|
||||||
|
import {getArgs} from './utils'
|
||||||
|
import * as cp from 'child_process'
|
||||||
|
|
||||||
|
export const upload = async (option: Upload): Promise<void> => {
|
||||||
|
cp.execSync(
|
||||||
|
[
|
||||||
|
'npx',
|
||||||
|
`tt-ide-cli@${option.ciVersion || '0.1.27'}`,
|
||||||
|
'set-app-config',
|
||||||
|
option.appid,
|
||||||
|
'--token',
|
||||||
|
option.privateKey
|
||||||
|
].join(' ')
|
||||||
|
)
|
||||||
|
const command = [
|
||||||
|
'npx',
|
||||||
|
`tt-ide-cli@${option.ciVersion || '0.1.27'}`,
|
||||||
|
'upload',
|
||||||
|
...getArgs(option),
|
||||||
|
option.projectPath
|
||||||
|
].join(' ')
|
||||||
|
core.info('Command:')
|
||||||
|
core.info(` ${command}`)
|
||||||
|
cp.execSync(command)
|
||||||
|
cp.execSync(`npx ${`tt-ide-cli@${option.ciVersion || '0.1.27'}`} logout`)
|
||||||
|
}
|
14
src/douyin/utils.ts
Normal file
14
src/douyin/utils.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import {CiOption} from '../type'
|
||||||
|
import * as core from '@actions/core'
|
||||||
|
|
||||||
|
export const getArgs = (option: CiOption): string[] => {
|
||||||
|
const args = []
|
||||||
|
if (option.version) {
|
||||||
|
args.push(...[' --app-version', `'${option.version}'`])
|
||||||
|
}
|
||||||
|
if (option.desc) {
|
||||||
|
args.push(...['--app-changelog', `'${option.desc}'`])
|
||||||
|
}
|
||||||
|
core.debug(args.toString())
|
||||||
|
return args
|
||||||
|
}
|
20
src/main.ts
20
src/main.ts
@ -11,6 +11,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
CiOption,
|
CiOption,
|
||||||
filterMode,
|
filterMode,
|
||||||
|
filterPlatform,
|
||||||
filterQrcodeFormat,
|
filterQrcodeFormat,
|
||||||
filterType,
|
filterType,
|
||||||
Preview
|
Preview
|
||||||
@ -20,6 +21,8 @@ import * as fs from 'fs'
|
|||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import {upload} from './ci/upload'
|
import {upload} from './ci/upload'
|
||||||
import {preview} from './ci/preview'
|
import {preview} from './ci/preview'
|
||||||
|
import {upload as dyUpload} from './douyin/upload'
|
||||||
|
import {preview as dyPreview} from './douyin/preview'
|
||||||
|
|
||||||
const defaultPrivateKeyPath = '../private.key'
|
const defaultPrivateKeyPath = '../private.key'
|
||||||
|
|
||||||
@ -34,6 +37,7 @@ async function run(): Promise<void> {
|
|||||||
|
|
||||||
option = {
|
option = {
|
||||||
mode: filterMode(getInput(Inputs.mode)),
|
mode: filterMode(getInput(Inputs.mode)),
|
||||||
|
platform: filterPlatform(getInput(Inputs.platform)),
|
||||||
appid: '',
|
appid: '',
|
||||||
type: filterType(getInput(Inputs.type)),
|
type: filterType(getInput(Inputs.type)),
|
||||||
projectPath: getInput(Inputs.projectPath) || '',
|
projectPath: getInput(Inputs.projectPath) || '',
|
||||||
@ -44,7 +48,9 @@ async function run(): Promise<void> {
|
|||||||
version: getInput(Inputs.version) || '',
|
version: getInput(Inputs.version) || '',
|
||||||
desc: getInput(Inputs.desc),
|
desc: getInput(Inputs.desc),
|
||||||
robot: getInputAsInt(Inputs.robot),
|
robot: getInputAsInt(Inputs.robot),
|
||||||
threads: getInputAsInt(Inputs.threads)
|
threads: getInputAsInt(Inputs.threads),
|
||||||
|
|
||||||
|
ciVersion: getInput(Inputs.ciVersion)
|
||||||
}
|
}
|
||||||
if (getInput(Inputs.mode) === 'test') {
|
if (getInput(Inputs.mode) === 'test') {
|
||||||
isTest = true
|
isTest = true
|
||||||
@ -97,7 +103,11 @@ async function run(): Promise<void> {
|
|||||||
} else if (option.mode === 'upload') {
|
} else if (option.mode === 'upload') {
|
||||||
core.info('Options:')
|
core.info('Options:')
|
||||||
core.info(`${stringify(option)}`)
|
core.info(`${stringify(option)}`)
|
||||||
upload(option)
|
if (option.platform === 'wechat') {
|
||||||
|
await upload(option)
|
||||||
|
} else {
|
||||||
|
await dyUpload(option)
|
||||||
|
}
|
||||||
} else if (option.mode === 'preview') {
|
} else if (option.mode === 'preview') {
|
||||||
const previewOption: Preview = {
|
const previewOption: Preview = {
|
||||||
...option,
|
...option,
|
||||||
@ -115,7 +125,11 @@ async function run(): Promise<void> {
|
|||||||
)
|
)
|
||||||
core.info('Options:')
|
core.info('Options:')
|
||||||
core.info(`${stringify(previewOption)}`)
|
core.info(`${stringify(previewOption)}`)
|
||||||
qrcode = await preview(previewOption)
|
if (option.platform === 'wechat') {
|
||||||
|
qrcode = await preview(previewOption)
|
||||||
|
} else {
|
||||||
|
qrcode = await dyPreview(previewOption)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (autoPrivateKey) {
|
if (autoPrivateKey) {
|
||||||
fs.promises.unlink(option.privateKeyPath)
|
fs.promises.unlink(option.privateKeyPath)
|
||||||
|
@ -22,8 +22,12 @@ export const filterMode = (type?: string): Mode => {
|
|||||||
return 'upload'
|
return 'upload'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const filterPlatform = (val?: string): 'wechat' | 'douyin' => {
|
||||||
|
return val === 'douyin' ? 'douyin' : 'wechat'
|
||||||
|
}
|
||||||
export type CiOption = {
|
export type CiOption = {
|
||||||
mode: Mode
|
mode: Mode
|
||||||
|
platform: 'wechat' | 'douyin'
|
||||||
appid: string
|
appid: string
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
setting?: any
|
setting?: any
|
||||||
@ -36,6 +40,8 @@ export type CiOption = {
|
|||||||
desc?: string
|
desc?: string
|
||||||
robot?: number
|
robot?: number
|
||||||
threads?: number
|
threads?: number
|
||||||
|
|
||||||
|
ciVersion?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Upload = CiOption & {}
|
export type Upload = CiOption & {}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable no-shadow */
|
/* eslint-disable no-shadow */
|
||||||
export enum Inputs {
|
export enum Inputs {
|
||||||
mode = 'mode',
|
mode = 'mode',
|
||||||
|
platform = 'platform',
|
||||||
type = 'type',
|
type = 'type',
|
||||||
projectPath = 'project-path',
|
projectPath = 'project-path',
|
||||||
privateKey = 'private-key',
|
privateKey = 'private-key',
|
||||||
@ -18,7 +19,9 @@ export enum Inputs {
|
|||||||
scene = 'scene',
|
scene = 'scene',
|
||||||
// output
|
// output
|
||||||
output = 'output',
|
output = 'output',
|
||||||
outputPath = 'output-path'
|
outputPath = 'output-path',
|
||||||
|
|
||||||
|
ciVersion = 'ci-version'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Outputs {
|
export enum Outputs {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user