Merge pull request #471 from Giftia/dev #96
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
# Thanks @ssp97 for the initial work on this file. | |
name: Build ChatDACS One-Click-To-Deploy Package (ChatDACS一键运行包构建) | |
on: | |
push: | |
branches: | |
- master | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
# https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#multiple-operating-systems-and-architectures | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: | |
- windows-latest | |
- ubuntu-latest | |
node_version: | |
- 18 | |
architecture: | |
- x64 | |
name: Build On:${{ matrix.os }}_${{ matrix.architecture }} - Node ${{ matrix.node_version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js ${{ matrix.node_version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node_version }} | |
architecture: ${{ matrix.architecture }} | |
cache: 'npm' | |
cache-dependency-path: | | |
./package-lock.json | |
plugins/package-lock.json | |
- name: Remove go-cqhttp On Windows | |
if: runner.os == 'Windows' | |
run: rm ./plugins/go-cqhttp/go-cqhttp | |
- name: Remove go-cqhttp.exe On Linux | |
if: runner.os == 'Linux' | |
run: | | |
rm ./plugins/go-cqhttp/go-cqhttp_windows_amd64.exe | |
rm ./plugins/go-cqhttp/go-cqhttp.bat | |
- name: Clean Install Modules | |
run: | | |
npm ci --production | |
cd ./plugins/ | |
npm ci --production | |
rm package.json | |
rm package-lock.json | |
cd .. | |
- name: Install pkg Tool | |
run: npm i pkg -g | |
- name: Install sequelize-cli | |
run: npm i sequelize-cli | |
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#detecting-the-operating-system | |
- name: Use pkg To Package On Windows | |
if: runner.os == 'Windows' | |
run: pkg -t node${{ matrix.node_version }}-windows . --compress Brotli | |
- name: Use pkg to Package On Linux | |
if: runner.os == 'Linux' | |
run: pkg -t node${{ matrix.node_version }}-linux . --compress Brotli | |
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable | |
- name: Declare VERSION | |
shell: bash | |
run: | | |
node -e " | |
const fs = require('fs'); | |
const package = require('./package.json'); | |
fs.writeFileSync('version-number', 'VERSION_NUMBER=v' + package.version); | |
" | |
cat ./version-number >> $GITHUB_ENV | |
- name: Pre-compress | |
shell: bash | |
run: | | |
npm i archiver | |
node -e " | |
const archiver = require('archiver'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const output = fs.createWriteStream(path.join(__dirname, 'ChatDACS-${{ env.VERSION_NUMBER }}_${{ runner.os }}.zip')); | |
const archive = archiver('zip', { | |
zlib: { level: 9 } | |
}); | |
archive.pipe(output); | |
archive.directory('./config/', 'config'); | |
archive.directory('./static/', 'static'); | |
archive.directory('./plugins/', 'plugins'); | |
archive.directory('./migrations/', 'migrations'); | |
archive.directory('./node_modules', 'node_modules'); | |
archive.file('./README.md', { name: 'README.md' }); | |
archive.file('./LICENSE', { name: 'LICENSE' }); | |
archive.file('./package.json', { name: 'package.json' }); | |
archive.file('./chatdacs.exe', { name: 'chatdacs.exe' }); | |
archive.file('./chatdacs', { name: 'chatdacs' }); | |
archive.finalize(); | |
" | |
- name: Get Current Time | |
shell: bash | |
id: time | |
# set-output is deprecated: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ | |
run: echo "now=$(date +'%Y-%m-%d-%H-%M-%S')" >> $GITHUB_OUTPUT | |
- name: Upload Build Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ChatDACS-${{ env.VERSION_NUMBER }}_${{ runner.os }}-${{ steps.time.outputs.now }} | |
path: ChatDACS-${{ env.VERSION_NUMBER }}_${{ runner.os }}.zip | |
if-no-files-found: error |