ci: pkg arm64 use podman

This commit is contained in:
shanmite 2022-08-22 10:23:50 +08:00
parent 886ccff341
commit 82efbb4219
6 changed files with 99 additions and 32 deletions

View File

@ -1,4 +1,9 @@
**/**
!lib/
!script/
!test/
!main.js
!package.json
!main.js
!env.example.js
!my_config.example.js
!README.md

View File

@ -12,6 +12,7 @@ jobs:
with:
args: "https://gitlab.com/shanmiteko/LotteryAutoScript"
env:
FORCE_PUSH: "true"
GITLAB_HOSTNAME: "gitlab.com"
GITLAB_USERNAME: "shanmiteko"
GITLAB_PASSWORD: ${{ secrets.GITLAB_PASSWORD }}

View File

@ -6,28 +6,65 @@ on:
- "lib/**"
- "*.js"
- "*.json"
- ".github/workflows/pkg.yml"
- "script/build/pkg.sh"
workflow_dispatch:
jobs:
build_all:
x64:
runs-on: ubuntu-latest
name: node${{ matrix.nodev }}-${{ matrix.platform }}-x64
strategy:
matrix:
include:
- platform: linux
nodev: 18
- platform: macos
nodev: 18
- platform: win
nodev: 18
- platform: win
nodev: 12
steps:
- name: "Checkout codes"
uses: actions/checkout@v2
- name: "Use Node.js"
uses: actions/setup-node@v1
with:
node-version: "16"
node-version: "*"
- name: "Pkg this"
run: |
sudo apt install zip unzip
npm install
npm run build_all
npm run pkg "node${{ matrix.nodev }}-${{ matrix.platform }}-x64"
- name: "Upload to artifact"
uses: actions/upload-artifact@v2
with:
name: all_platform
path: dist/
name: node${{ matrix.nodev }}-${{ matrix.platform }}-x64
path: "dist/*.zip"
- name: "Upload to release draft"
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
file: "dist/*.zip"
delete_file: "dist/*.zip"
tag_name: "v2"
overwrite: true
arm64:
runs-on: ubuntu-latest
name: arm64
steps:
- name: "Checkout codes"
uses: actions/checkout@v2
- name: "Pkg this"
run: |
sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes
npm run pkg arm
- name: "Upload to artifact"
uses: actions/upload-artifact@v2
with:
name: arm64
path: "dist/*.zip"
- name: "Upload to release draft"
uses: xresloader/upload-to-github-release@v1
env:

22
Dockerfile.pkg-arm64 Normal file
View File

@ -0,0 +1,22 @@
FROM arm64v8/node
WORKDIR /root/lottery
COPY . .
RUN npm config set registry https://registry.npm.taobao.org && npm i
ENV DOWNLOAD_HOST=https://download.fastgit.org \
RELEASE_TAG=v3.4 \
NODEV=18.5.0 \
PKG_CACHE_PATH=/root/.pkg-cache \
PKG_IGNORE_TAG=true
RUN mkdir -p "${PKG_CACHE_PATH}" && \
curl -L "$DOWNLOAD_HOST/vercel/pkg-fetch/releases/download/$RELEASE_TAG/node-v$NODEV-linux-arm64" -o \
"${PKG_CACHE_PATH}/fetched-v$NODEV-linux-arm64" && \
curl -L "$DOWNLOAD_HOST/vercel/pkg-fetch/releases/download/$RELEASE_TAG/node-v$NODEV-linuxstatic-arm64" -o \
"${PKG_CACHE_PATH}/fetched-v$NODEV-linuxstatic-arm64"
CMD ["bash", "-c", "npx pkg -t node$NODEV-linuxstatic-arm64 -o dist/lottery-auto-script-node$NODEV-linuxstatic-arm64 . && \
npx pkg -t node$NODEV-linux-arm64 -o dist/lottery-auto-script-node$NODEV-linux-arm64 ."]

View File

@ -9,7 +9,7 @@
"clear": "node main.js clear",
"check": "node main.js check",
"update": "node main.js update",
"build_all": "bash script/build/pkg.sh",
"pkg": "bash script/build/pkg.sh",
"changelog": "bash script/build/changelog.sh"
},
"files": [
@ -22,17 +22,6 @@
"README.md"
],
"bin": "main.js",
"pkg": {
"targets": [
"node12-win-x64",
"node16-win-x64",
"node16-linux-x64",
"node16-macos-x64",
"node16-linuxstatic-arm64",
"node16-linuxstatic-armv7"
],
"outputPath": "dist"
},
"repository": {
"type": "git",
"url": "https://github.com/shanmiteko/AutoScript.git"
@ -55,4 +44,4 @@
"chalk": "^4.1.2",
"nodemailer": "^6.7.0"
}
}
}

View File

@ -1,12 +1,14 @@
#!/usr/bin/env bash
set -e
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"
TARGET_DIR="dist"
BIN_NAME="lottery"
create_win_bat() {
@ -17,28 +19,39 @@ if [ -d "$TARGET_DIR" ]; then
rm -rf "$TARGET_DIR"
fi
npx pkg .
if [[ -z "$1" ]]; then
$1=node18-linux-x64
fi
mkdir -p $TARGET_DIR
if [[ "$1" == *"arm"* ]]; then
podman build -f Dockerfile.pkg-arm64 -t pkg-arm64
podman run -it --rm -v ${PWD}/dist:/root/lottery/dist pkg-arm64
elif [[ "$1" == *"x64"* ]]; then
OUTFILE="$TARGET_DIR/lottery-auto-script-$1"
npx pkg -t "$1" -o $OUTFILE .
fi
# 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"
mkdir -p "$TMPDIR.d/"
mv $REMANE_FILE "$TMPDIR.d/"
cp $README "$TMPDIR.d/"
cp $TEMPLATE_CONFIG_FILE "$TMPDIR.d/$CONFIG_FILE"
cp $TEMPLATE_ENV_FILE "$TMPDIR.d/$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"
create_win_bat "${item}" >"$TMPDIR.d/$item.bat"
done
mv "$TMPDIR/$BIN_NAME" "$TMPDIR/$BIN_NAME.exe"
mv "$TMPDIR.d/$BIN_NAME" "$TMPDIR.d/$BIN_NAME.exe"
else
ZIP_NAME=latest_version0
cat >"$TMPDIR/update.sh" <<-EOF
cat >"$TMPDIR.d/update.sh" <<-EOF
#!/bin/bash
./lottery update
ZIP_NAME=$ZIP_NAME
@ -49,7 +62,7 @@ for file in "$TARGET_DIR/"*; do
fi
EOF
fi
cd $TMPDIR
cd $TMPDIR.d
zip -r "$TMPDIR_NAME.zip" .
mv "$TMPDIR_NAME.zip" ../
cd $ROOT