Skip to content

Commit

Permalink
ci: dev测试版发布工作流 [publish dev]
Browse files Browse the repository at this point in the history
  • Loading branch information
zkz098 committed Nov 1, 2024
1 parent f866e7c commit 7c330ff
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/dev-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Nodejs Package on Dev Version

on:
push:
branches:
- develop

jobs:
publish:
if: "contains(github.event.head_commit.message, '[publish dev]')"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/

- name: Install dependencies
run: npm install pnpm -g

- name: Build TypeScript files
run: |
pnpm install
node ./toolbox/dev-version.js
pnpm run build
- run: npm publish --tag dev
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
3 changes: 1 addition & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ jobs:
- name: Build TypeScript files
run: |
pnpm install
echo "NO_DEPS_HOIST=true" >> $GITHUB_ENV
pnpm run build
- run: npm publish
if: "!github.event.release.prerelease"
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}

- run: npm publish --tag dev
- run: npm publish --tag beta
if: "github.event.release.prerelease"
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-theme-shokax",
"version": "0.4.16",
"version": "0.5.0",
"description": "a hexo theme based on shoka",
"main": "index.js",
"repository": "https://github.com/theme-shoka-x/hexo-theme-shokaX",
Expand Down Expand Up @@ -65,4 +65,4 @@
"object.values": "npm:@nolyfill/object.values@latest"
}
}
}
}
14 changes: 14 additions & 0 deletions toolbox/dev-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fs from 'node:fs';
import { execSync } from 'child_process';

const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
const currentVersion = packageJson.version;

const shortHash = execSync('git rev-parse --short HEAD').toString().trim();

const newVersion = `${currentVersion}-dev-${shortHash}`;

packageJson.version = newVersion;
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 4));

console.log(`Updated package version to ${newVersion}`);

0 comments on commit 7c330ff

Please sign in to comment.