Skip to content

Package against main #23

Package against main

Package against main #23

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'}}
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 }}