-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters