Skip to content

Commit

Permalink
chore: test ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuro-P committed Dec 20, 2023
1 parent 6b516b8 commit 1014c19
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 10 deletions.
30 changes: 20 additions & 10 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@ run-name: Deploy by @${{ github.actor }}

on:
push:
branches: ["develop"]
branches: ["test"]
pull_request:
branches: ["develop"]
branches: ["test"]

env:
TZ: Asia/Shanghai

jobs:
test-package-version:
runs-on: ubuntu-latest
steps:
- name: Setup node version
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'

- name: Compare version
run: node common/compare-version.js

- name: Console test
run: echo "version check completely"

build-and-deploy:
runs-on: ubuntu-latest
steps:
Expand All @@ -33,14 +48,9 @@ jobs:
node-version: 18
cache: 'npm'

- name: Get package info
id: package
uses: codex-team/[email protected]

- name: Get the output
run: |
echo "name: ${{ steps.package.outputs.name }}"
echo "version: ${{ steps.package.outputs.version }}"
# - name: Check version change and commit message?
# run: echo "IS_CHANGED=$(git diff './package.json')"
# run: echo "IS_CHANGED=$(node common/compare-version.js)"

- name: Cache node modules
uses: actions/cache@v3
Expand Down
44 changes: 44 additions & 0 deletions common/compare-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 存放一席常用的工具方法
const package = require('../package.json')
const https = require('node:https')
const { compare, compareVersions } = require('compare-versions')
const process = require('process')

const prodPackage = 'https://raw.githubusercontent.com/Kuro-P/Kuro-P.github.io/develop/package.json';


// 与线上版本进行对比
function compareVersion() {
console.log('local package version', package.version)

https.get(prodPackage,
(res) => {
console.log('statusCode:', res.statusCode);
let _data = ''

res.on('data', (chunk) => {
_data += chunk
});


res.on('end', () => {
try {
const data = JSON.parse(_data)
console.log('current version', data.version)

versionChanged = compareVersions(package.version, data.version)
if (!versionChanged) {
console.log('version not changed !!!')
process.exit(1)
}
console.log('version changed !!!')
} catch (e) {
console.log('response error', e.message)
}
})
}).on('error', (e) => {
console.error(e);
});
}

compareVersion()
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"version": "6.3.0"
},
"dependencies": {
"compare-versions": "^6.1.0",
"hexo": "^6.3.0",
"hexo-deployer-git": "^4.0.0",
"hexo-douban": "^2.2.1",
Expand Down

0 comments on commit 1014c19

Please sign in to comment.