-
Notifications
You must be signed in to change notification settings - Fork 6
121 lines (118 loc) · 5.08 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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: ubuntu-20.04
name: Prebuild on ubuntu-20.04
# needs: test
steps:
- uses: actions/checkout@v4 # 使用社区的指令
- 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
- 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' }}
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-amd:
if: ${{ github.event.inputs.job == 'build-pkg' || github.event.inputs.job == 'push-all' }}
strategy:
matrix:
os: [ ubuntu-20.04, windows-latest ]
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 && pkg . --no-dependencies --targets node18-win-x64 --output filecat-win-x64.exe
- if: ${{ startsWith(matrix.os, 'windows') && matrix.architecture == 'arm64' }}
run: npm run pkg-build && pkg . --no-dependencies --targets node18-win-arm64 --output filecat-win-arm64.exe
- if: ${{ startsWith(matrix.os, 'ubuntu') && matrix.architecture == 'x64' }}
run: npm run pkg-build && pkg . --no-dependencies --targets node18-linux-x64 --output filecat-linux-x64
- if: ${{ startsWith(matrix.os, 'ubuntu') && matrix.architecture == 'arm64' }}
run: npm run pkg-build && pkg . --no-dependencies --targets node18-linux-arm64 --output filecat-linux-arm64
- run: prebuild --upload --files filecat-* -u ${{ secrets.GITHUB_TOKEN }}