mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-03-25 14:22:24 +08:00
153 lines
3.9 KiB
YAML
153 lines
3.9 KiB
YAML
name: Build Docker
|
|
|
|
on:
|
|
pull_request:
|
|
push:
|
|
tags:
|
|
- '\d+\.\d+\.\d+'
|
|
- '\d+\.\d+'
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- name: Set up Python 3.11
|
|
uses: actions/setup-python@v3
|
|
with:
|
|
python-version: "3.11"
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
if [ -f backend/requirements.txt ]; then pip install -r backend/requirements.txt; fi
|
|
pip install pytest
|
|
- name: Test
|
|
working-directory: ./backend/src
|
|
run: |
|
|
mkdir -p config
|
|
pytest
|
|
|
|
build-webui:
|
|
runs-on: ubuntu-latest
|
|
needs: [test]
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Install Node.js
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: latest
|
|
|
|
- uses: pnpm/action-setup@v2
|
|
name: Install pnpm
|
|
id: pnpm-install
|
|
with:
|
|
version: latest
|
|
run_install: true
|
|
|
|
- name: Build
|
|
run: |
|
|
cd webui
|
|
pnpm build && zip -r dist.zip dist
|
|
|
|
- name: Upload artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: dist
|
|
path: webui/dist.zip
|
|
|
|
|
|
draft-release:
|
|
runs-on: ubuntu-latest
|
|
needs: [test]
|
|
if: >
|
|
github.event.pull_request.merged == true &&
|
|
github.event.pull_request.base.ref == 'main'
|
|
steps:
|
|
|
|
- name: Checkout code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: download artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: dist
|
|
path: dist.zip
|
|
|
|
- name: Generate Release
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
tag_name: ${{ github.event.pull_request.title }}
|
|
name: 🌟${{ github.event.pull_request.title }}
|
|
body: ${{ github.event.pull_request.body }}
|
|
draft: true
|
|
prerelease: false
|
|
files: |
|
|
dist.zip
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
|
|
|
build-docker:
|
|
runs-on: ubuntu-latest
|
|
needs: [test, build-webui]
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Create Version info
|
|
working-directory: ./backend/src
|
|
run: |
|
|
echo "VERSION = '$GITHUB_REF_NAME'" > module/__version__.py
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
|
|
- name: Set up Docker Buildx
|
|
id: buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v4
|
|
with:
|
|
images: |
|
|
ghcr.io/estrellaxd/auto_bangumi
|
|
estrellaxd/auto_bangumi
|
|
ghcr.io/${{ github.repository }}
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=raw,value=latest
|
|
|
|
- name: Login to DockerHub
|
|
if: ${{ github.event_name == 'push' }}
|
|
uses: docker/login-action@v2
|
|
with:
|
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
|
|
|
- name: Login to ghcr.io
|
|
if: ${{ github.event_name == 'push' }}
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.ACCESS_TOKEN }}
|
|
|
|
- name: Download artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: dist
|
|
path: backend/dist.zip
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: .
|
|
builder: ${{ steps.buildx.output.name }}
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
push: ${{ github.event_name == 'push' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha, scope=${{ github.workflow }}
|
|
cache-to: type=gha, scope=${{ github.workflow }}
|