Skip to content

Package against main #37

Package against main

Package against main #37

Workflow file for this run

name: "Run prebuild's and Create GitHub and NPM release"
run-name: Package against ${{ github.ref_name }} # 每次运行的时候显示的名字
# 本yml参考于 https://github.com/WiseLibs/better-sqlite3/blob/master/.github/workflows/build.yml
on:
workflow_dispatch: # 手动触发
inputs: # 定义触发的时候可以输入的参数
job: # 参数名称 通过 ${{ github.event.inputs.job }} 访问值 下面是参数的要求描述
description: "任务类型"
required: true
default: prebuild
type: string
tag:
description: '发布docker可选的docker标签'
required: false
default: ''
# 所有的jobs下的任务都会被执行
jobs:
push-npm: # 执行node的 预构建
if: ${{ github.event.inputs.job == 'push-npm' || github.event.inputs.job == 'push-all' }}
runs-on: windows-2022
name: Prebuild on windows-2022
# needs: test
steps:
- uses: actions/checkout@v4 # 使用社区的指令
- uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org
- run: pip.exe install setuptools
- run: npm install
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
push-docker:
if: ${{ github.event.inputs.job == 'push-docker' || github.event.inputs.job == 'push-all' }}
runs-on: ubuntu-latest
container: node:18-alpine
env:
DOCKER_REPO: ${{ secrets.DOCKER_USERNAME }}/filecat
DOCKER_PLATFORMS: linux/amd64,linux/arm,linux/arm64 # 目标平台
steps:
- uses: actions/checkout@v4 # 使用社区的指令
- run: apk add docker build-base linux-headers git python3 py3-setuptools --update-cache
# - uses: actions/setup-node@v4
# with:
# node-version: 18
# registry-url: https://registry.npmjs.org
# - run: |
# sudo apt update
# sudo apt install gcc-10 g++-10 -y
# sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10
- name: Docker meta # 镜像仓库
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_REPO }}
ghcr.io/${{ github.repository }}
tags: |
${{ github.ref_name }}
latest
${{ github.event.inputs.tag && github.event.inputs.tag || '' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: build
run: | # --ignore-scripts 不能使用不能跳过一些安装脚本
npm install
npm run docker-build
- name: Login to Docker Hub # login to Docker Hub, automatically logout at the end of job
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run buildx and push
uses: docker/build-push-action@v6
with:
context: .
provenance: false
push: true # push to docker hub
platforms: ${{ env.DOCKER_PLATFORMS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-pkg:
if: ${{ github.event.inputs.job == 'build-pkg' }}
strategy:
matrix:
os: [ ubuntu-20.04, windows-2019 ]
architecture: [ x64, arm64 ]
node: [ 18 ]
name: Prebuild on ${{ matrix.os }},${{ matrix.architecture }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4 # 使用社区的指令
- uses: actions/setup-node@v4
with:
node-version: 18
- run: npm install
- if: ${{ startsWith(matrix.os, 'windows') && matrix.architecture == 'x64' }}
run: |
npm run pkg-build && npx pkg . --no-dependencies --targets node18-win-x64 --output filecat-win-x64.exe --no-input
npx --no-install prebuild --upload-files-zip "filecat-win-x64.exe" -u ${{ secrets.GITHUB_TOKEN }}
- if: ${{ startsWith(matrix.os, 'windows') && matrix.architecture == 'arm64' }}
run: |
npm run pkg-build && npx pkg . --no-dependencies --targets node18-win-arm64 --output filecat-win-arm64.exe --no-input
npx --no-install prebuild --upload-files-zip "filecat-win-arm64.exe" -u ${{ secrets.GITHUB_TOKEN }}
- if: ${{ startsWith(matrix.os, 'ubuntu') && matrix.architecture == 'x64' }}
run: |
npm run pkg-build && npx pkg . --no-dependencies --targets node18-linux-x64 --output filecat-linux-x64 --no-input
npx --no-install prebuild --upload-files-zip "filecat-linux-x64" -u ${{ secrets.GITHUB_TOKEN }}
- if: ${{ startsWith(matrix.os, 'ubuntu') && matrix.architecture == 'arm64' }}
run: |
npm run pkg-build && npx pkg . --no-dependencies --targets node18-linux-arm64 --output filecat-linux-arm64 --no-input
npx --no-install prebuild --upload-files-zip "filecat-linux-arm64" -u ${{ secrets.GITHUB_TOKEN }}