Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update cli #460

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
npm run build:h5-netlify

- name: Upload dist artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
Expand All @@ -37,7 +37,7 @@ jobs:

- name: Upload PR number
if: ${{ always() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3
with:
name: pr
path: ./pr-id.txt
12 changes: 6 additions & 6 deletions .github/workflows/preview-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' && github.repository == 'doocs/md'
steps:
- name: Download PR artifact
uses: dawidd6/action-download-artifact@v6
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: pr
Expand All @@ -22,7 +22,7 @@ jobs:
run: echo "id=$(<pr-id.txt)" >> "$GITHUB_OUTPUT"

- name: Download dist artifact
uses: dawidd6/action-download-artifact@v6
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
workflow_conclusion: success
Expand All @@ -35,7 +35,7 @@ jobs:
npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }}

- name: Upload status comment
uses: actions-cool/maintain-one-comment@v3
uses: actions-cool/maintain-one-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
Expand All @@ -49,7 +49,7 @@ jobs:

- name: The job failed
if: ${{ failure() }}
uses: actions-cool/maintain-one-comment@v3
uses: actions-cool/maintain-one-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
Expand All @@ -66,7 +66,7 @@ jobs:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' && github.repository == 'doocs/md'
steps:
- name: Download PR artifact
uses: dawidd6/action-download-artifact@v6
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: pr
Expand All @@ -76,7 +76,7 @@ jobs:
run: echo "id=$(<pr-id.txt)" >> "$GITHUB_OUTPUT"

- name: The job failed
uses: actions-cool/maintain-one-comment@v3
uses: actions-cool/maintain-one-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
Expand Down
84 changes: 44 additions & 40 deletions bin/release.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
import packageJson from '../md-cli/package.json' assert { type: 'json' };
import child_process from 'child_process';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

(async function () {
const fs = require('fs');
const path = require('path');
const packageJson = require('../md-cli/package.json');
const child_process = require('child_process');
// 自动更新版本
// version可以传递如 6.1.1 | patch | minor | major
const execCommand = arr => (Array.isArray(arr) ? arr : [arr]).forEach(c => {
try {
console.log(`start: ${c}...`)
console.log(child_process.execSync(c).toString('utf8'))
} catch (error) {
console.log('\x1B[31m%s\x1B[0m', error.stdout.toString())
process.exit(1)
}
})
const getNewVersion = (oldVersion, version = 'patch') => {
const execCommand = (arr) =>
(Array.isArray(arr) ? arr : [arr]).forEach((c) => {
try {
console.log(`start: ${c}...`);
console.log(child_process.execSync(c).toString("utf8"));
} catch (error) {
console.log("\x1B[31m%s\x1B[0m", error.stdout.toString());
process.exit(1);
}
});
const getNewVersion = (oldVersion, version = "patch") => {
// [<newversion> | major | minor | patch]
if (/^([0-9]+\.*)+$/.test(version)) return version
const types = ['major', 'minor', 'patch']
const index = types.indexOf(version)
if (/^([0-9]+\.*)+$/.test(version)) return version;
const types = ["major", "minor", "patch"];
const index = types.indexOf(version);
if (index >= 0) {
const versionArr = oldVersion.split('.')
versionArr[index] = Number(versionArr[index]) + 1
return versionArr.map((e, i) => i > index ? 0 : e).join('.')
}
return getNewVersion(oldVersion)
const versionArr = oldVersion.split(".");
versionArr[index] = Number(versionArr[index]) + 1;
return versionArr.map((e, i) => (i > index ? 0 : e)).join(".");
}
const newVersionObj = {
version: getNewVersion(packageJson.version, process.argv[2]),
};
fs.writeFileSync(
path.resolve(__dirname, '../md-cli/package.json'),
JSON.stringify(Object.assign({}, packageJson, newVersionObj), null, 2) +
'\n'
);
console.log(newVersionObj);
execCommand([
`git commit -a -m 'chore: update version cli-v${newVersionObj.version}'`,
`git tag cli-v${newVersionObj.version}`,
'git push && git push --tags',
])
console.log('\x1B[32m%s\x1B[0m', '发布完成,请关注github CI构建')
}())
return getNewVersion(oldVersion);
};
const newVersionObj = {
version: getNewVersion(packageJson.version, process.argv[2]),
};
await fs.writeFile(
path.resolve(__dirname, "../md-cli/package.json"),
JSON.stringify(Object.assign({}, packageJson, newVersionObj), null, 2) +
"\n"
);
console.log(newVersionObj);
execCommand([
`git commit -a -m 'chore: update version cli-v${newVersionObj.version}'`,
`git tag cli-v${newVersionObj.version}`,
"git push && git push --tags",
]);
console.log("\x1B[32m%s\x1B[0m", "发布完成,请关注 GitHub CI 构建");
})();
2 changes: 1 addition & 1 deletion md-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ new Promise(async () => {
;[port, testPort, replayPort] = await Promise.all([port, port+1, port+2].map(item => getPort({port: item}) )).catch(err => console.log(`err`, err))
const line = Object.entries({
...arg,
proxy: `https://doocs.gitee.io/`,
proxy: `https://doocs-md.pages.dev`,
port,
testPort,
replayPort,
Expand Down
Loading
Loading