mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
chore: 移植并完善自动化构建脚本
This commit is contained in:
parent
6b09e26cbf
commit
07ef8dfb2e
2
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
2
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
@ -62,7 +62,9 @@ body:
|
||||
description: |
|
||||
控制台日志。
|
||||
placeholder: |
|
||||
```
|
||||
请在此黏贴运行日志。
|
||||
```
|
||||
|
||||
- id: system
|
||||
type: input
|
||||
|
||||
58
.github/workflows/pkg.yml
vendored
58
.github/workflows/pkg.yml
vendored
@ -16,35 +16,7 @@ on:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
pkg_x64:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: "Checkout codes"
|
||||
uses: actions/checkout@v2
|
||||
- name: "Use Node.js"
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: "16"
|
||||
- name: "Pkg this"
|
||||
run: |
|
||||
npm install
|
||||
npm run pkg_x64
|
||||
- name: "Upload to artifact(win)"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nlts-win-x64
|
||||
path: dist/nlts-win-x64/
|
||||
- name: "Upload to artifact(linux)"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nlts-linux-x64
|
||||
path: dist/nlts-linux-x64/
|
||||
- name: "Upload to artifact(macos)"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nlts-macos-x64
|
||||
path: dist/nlts-macos-x64/
|
||||
pkg_arm64:
|
||||
build_all:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Checkout codes"
|
||||
@ -55,28 +27,18 @@ jobs:
|
||||
node-version: "16"
|
||||
- name: "Pkg this"
|
||||
run: |
|
||||
sudo apt install zip unzip
|
||||
npm install
|
||||
npm run pkg_arm64
|
||||
npm run build_all
|
||||
- name: "Upload to artifact"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nlts-linux-arm64
|
||||
name: all_platform
|
||||
path: dist/
|
||||
pkg_armv7:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Checkout codes"
|
||||
uses: actions/checkout@v2
|
||||
- name: "Use Node.js"
|
||||
uses: actions/setup-node@v1
|
||||
- name: "Upload to release draft"
|
||||
uses: xresloader/upload-to-github-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
with:
|
||||
node-version: "16"
|
||||
- name: "Pkg this"
|
||||
run: |
|
||||
npm install
|
||||
npm run pkg_armv7
|
||||
- name: "Upload to artifact"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nlts-linux-armv7
|
||||
path: dist/
|
||||
file: "dist/*.zip"
|
||||
delete_file: "dist/*.zip"
|
||||
|
||||
13
package.json
13
package.json
@ -8,9 +8,7 @@
|
||||
"clear": "node main.js clear",
|
||||
"check": "node main.js check",
|
||||
"update": "node main.js update",
|
||||
"pkg_x64": "PowerShell .\\script\\pkg\\pkg.ps1",
|
||||
"pkg_arm64": "npx pkg -t node16-linux-arm64 -o dist/lottery main.js && cp my_config.example.js dist/my_config.js && cp env.example.js dist/env.js",
|
||||
"pkg_armv7": "npx pkg -t node16-linuxstatic-armv7 -o dist/lottery main.js && cp my_config.example.js dist/my_config.js && cp env.example.js dist/env.js"
|
||||
"build_all": "bash script/build/pkg.sh"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
@ -24,9 +22,12 @@
|
||||
"bin": "main.js",
|
||||
"pkg": {
|
||||
"targets": [
|
||||
"linux-x64",
|
||||
"win-x64",
|
||||
"macos-x64"
|
||||
"node12-win-x64",
|
||||
"node16-win-x64",
|
||||
"node16-linux-x64",
|
||||
"node16-macos-x64",
|
||||
"node16-linuxstatic-arm64",
|
||||
"node16-linuxstatic-armv7"
|
||||
],
|
||||
"outputPath": "dist"
|
||||
},
|
||||
|
||||
53
script/build/pkg.sh
Executable file
53
script/build/pkg.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ROOT=$PWD
|
||||
README="README.md"
|
||||
TEMPLATE_CONFIG_FILE="my_config.example.js"
|
||||
TEMPLATE_ENV_FILE="env.example.js"
|
||||
CONFIG_FILE="my_config.js"
|
||||
ENV_FILE="env.js"
|
||||
TARGET_DIR="./dist"
|
||||
BIN_NAME="lottery"
|
||||
|
||||
create_win_bat() {
|
||||
echo "@echo off && lottery $1 && pause"
|
||||
}
|
||||
|
||||
if [ -d "$TARGET_DIR" ]; then
|
||||
rm -rf "$TARGET_DIR"
|
||||
fi
|
||||
|
||||
npx pkg .
|
||||
|
||||
# Searching in the current directory
|
||||
for file in "$TARGET_DIR/"*; do
|
||||
TMPDIR="${file%.exe}"
|
||||
TMPDIR_NAME="${TMPDIR##*/}"
|
||||
REMANE_FILE="$TARGET_DIR/$BIN_NAME"
|
||||
mv $file $REMANE_FILE
|
||||
mkdir -p "$TMPDIR/"
|
||||
mv $REMANE_FILE "$TMPDIR/"
|
||||
cp $README "$TMPDIR/"
|
||||
cp $TEMPLATE_CONFIG_FILE "$TMPDIR/$CONFIG_FILE"
|
||||
cp $TEMPLATE_ENV_FILE "$TMPDIR/$ENV_FILE"
|
||||
if [ "$(echo $file | grep '.exe')" ]; then
|
||||
BATS=("start" "check" "clear" "update")
|
||||
for item in "${BATS[@]}"; do
|
||||
create_win_bat "${item}" >"$TMPDIR/$item.bat"
|
||||
done
|
||||
else
|
||||
cat >"$TMPDIR/update.sh" <<-EOF
|
||||
#!/bin/bash
|
||||
./lottery update
|
||||
if [[ -r "latest_version.zip" ]]; then
|
||||
unzip latest_version.zip
|
||||
rm latest_version.zip
|
||||
chmod u+x lottery
|
||||
fi
|
||||
EOF
|
||||
fi
|
||||
cd $TMPDIR
|
||||
zip -r "$TMPDIR_NAME.zip" .
|
||||
mv "$TMPDIR_NAME.zip" ../
|
||||
cd $ROOT
|
||||
done
|
||||
@ -129,7 +129,7 @@ echo "create remove_all.sh"
|
||||
cat >remove_all.sh <<EOF
|
||||
#!/bin/sh
|
||||
echo "remove all containers about $DOCKER_REPO"
|
||||
docker rm \$(docker ps -a | awk '/shanmite\/lottery_auto_docker/ {print \$1}')
|
||||
docker rm -v \$(docker ps -a | awk '/shanmite\/lottery_auto_docker/ {print \$1}')
|
||||
echo "remove image $DOCKER_REPO"
|
||||
docker image rm -f shanmite/lottery_auto_docker
|
||||
echo "see you next time!"
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
$README = "README.md"
|
||||
$TEMPLATE_CONFIG_FILE = "my_config.example.js"
|
||||
$TEMPLATE_ENV_FILE = "env.example.js"
|
||||
|
||||
$CONFIG_FILE = "my_config.js"
|
||||
$ENV_FILE = "env.js"
|
||||
|
||||
$TARGET_DIR = ".\dist"
|
||||
|
||||
$NAME = 'lottery-auto-script'
|
||||
|
||||
$TRIARR = @(
|
||||
@("$NAME-win.exe", "lottery.exe", "nlts-win-x64"),
|
||||
@("$NAME-linux", "lottery", "nlts-linux-x64"),
|
||||
@("$NAME-macos", "lottery", "nlts-macos-x64")
|
||||
)
|
||||
|
||||
if((Test-Path $TARGET_DIR) -eq "True") {
|
||||
Remove-Item -Path $TARGET_DIR -Recurse
|
||||
}
|
||||
|
||||
npx pkg .
|
||||
|
||||
Copy-Item -Path $TEMPLATE_ENV_FILE -Destination $TARGET_DIR -Force
|
||||
Copy-Item -Path $TEMPLATE_CONFIG_FILE -Destination $TARGET_DIR -Force
|
||||
Copy-Item -Path $README -Destination $TARGET_DIR -Force
|
||||
|
||||
Set-Location -Path $TARGET_DIR
|
||||
|
||||
Move-Item -Path $TEMPLATE_ENV_FILE -Destination $ENV_FILE -Force
|
||||
Move-Item -Path $TEMPLATE_CONFIG_FILE -Destination $CONFIG_FILE -Force
|
||||
|
||||
foreach ($TRI in $TRIARR) {
|
||||
$PROTO_BIN,$BIN,$DIR = $TRI
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $DIR
|
||||
|
||||
Move-Item -Path $PROTO_BIN -Destination $BIN -Force
|
||||
|
||||
Move-Item -Path $BIN -Destination $DIR -Force
|
||||
Copy-Item -Path $ENV_FILE -Destination $DIR -Force
|
||||
Copy-Item -Path $CONFIG_FILE -Destination $DIR -Force
|
||||
Copy-Item -Path $README -Destination $DIR -Force
|
||||
|
||||
if ($DIR -eq "nlts-win-x64") {
|
||||
New-Item -Path $DIR -Name "start.bat" -ItemType File -Value "@echo off && lottery start && pause" -Force
|
||||
New-Item -Path $DIR -Name "check.bat" -ItemType File -Value "@echo off && lottery check && pause" -Force
|
||||
New-Item -Path $DIR -Name "clear.bat" -ItemType File -Value "@echo off && lottery clear && pause" -Force
|
||||
New-Item -Path $DIR -Name "update.bat" -ItemType File -Value "@echo off && lottery update && pause" -Force
|
||||
}
|
||||
|
||||
Compress-Archive -Path $DIR -DestinationPath $DIR -Force
|
||||
}
|
||||
|
||||
Remove-Item -Path $ENV_FILE
|
||||
Remove-Item -Path $CONFIG_FILE
|
||||
Remove-Item -Path $README
|
||||
@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
./lottery update
|
||||
|
||||
if [[ -r "latest_version.zip" ]]; then
|
||||
unzip latest_version.zip
|
||||
rm latest_version.zip
|
||||
chmod u+x lottery
|
||||
fi
|
||||
Loading…
Reference in New Issue
Block a user