mirror of
https://github.com/hi2shark/nazhua.git
synced 2026-01-12 23:30:42 +08:00
47 lines
1.2 KiB
YAML
47 lines
1.2 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main # 监听 main 分支的 push 操作
|
|
workflow_dispatch: # 手动触发
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Install dependencies
|
|
run: npm install
|
|
|
|
- name: Get version from package.json
|
|
id: get_version
|
|
run: echo "VERSION=$(node -p 'require("./package.json").version')" >> $GITHUB_ENV
|
|
|
|
- name: Print version
|
|
run: echo "Version is $VERSION"
|
|
|
|
- name: Build project
|
|
run: npm run build
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
docker build -t ghcr.io/${{ github.repository }}:$VERSION .
|
|
|
|
- name: Log in to GitHub Container Registry
|
|
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
|
|
|
- name: Push Docker image
|
|
run: |
|
|
docker push ghcr.io/${{ github.repository }}:$VERSION
|
|
docker tag ghcr.io/${{ github.repository }}:$VERSION ghcr.io/${{ github.repository }}:latest
|
|
docker push ghcr.io/${{ github.repository }}:latest
|