mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-29 02:56:08 +08:00
167 lines
5.0 KiB
YAML
167 lines
5.0 KiB
YAML
name: Build And Push Docker Image
|
||
|
||
on:
|
||
push:
|
||
branches:
|
||
- 'master'
|
||
- 'develop'
|
||
# Sequence of patterns matched against refs/tags
|
||
tags:
|
||
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
|
||
schedule:
|
||
# 参考 https://jasonet.co/posts/scheduled-actions/
|
||
# note: 这里是GMT时间,北京时间减去八小时即可。如北京时间 22:30 => GMT 14:30
|
||
# minute hour day month dayOfWeek
|
||
- cron: '00 14 * * *' # GMT 14:00 => 北京时间 22:00
|
||
#- cron: '30 16 * * *' # GMT 16:30(前一天) => 北京时间 00:30
|
||
workflow_dispatch:
|
||
|
||
jobs:
|
||
to_gitlab:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- uses: actions/checkout@v3
|
||
with:
|
||
fetch-depth: 0
|
||
- uses: pixta-dev/repository-mirroring-action@v1
|
||
with:
|
||
target_repo_url:
|
||
git@gitlab.com:whyour/qinglong.git
|
||
ssh_private_key:
|
||
${{ secrets.GITLAB_SSH_PK }}
|
||
|
||
to_gitee:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- uses: actions/checkout@v3
|
||
with:
|
||
fetch-depth: 0
|
||
- uses: pixta-dev/repository-mirroring-action@v1
|
||
with:
|
||
target_repo_url:
|
||
git@gitee.com:whyour/qinglong.git
|
||
ssh_private_key:
|
||
${{ secrets.GITLAB_SSH_PK }}
|
||
|
||
build-static:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- uses: actions/checkout@v3
|
||
- uses: pnpm/action-setup@v2
|
||
with:
|
||
version: latest
|
||
|
||
- uses: actions/setup-node@v3
|
||
with:
|
||
cache: 'pnpm'
|
||
|
||
- name: build front and back
|
||
run: |
|
||
pnpm install --frozen-lockfile
|
||
pnpm build:front
|
||
pnpm build:back
|
||
|
||
- name: copy to static repo
|
||
env:
|
||
GITHUB_REPO: github.com/${{ github.repository_owner }}/qinglong-static
|
||
GITHUB_BRANCH: ${{ github.ref_name }}
|
||
REPO_GITEE: git@gitee.com:whyour/qinglong-static.git
|
||
REPO_GITLAB: git@gitlab.com:whyour/qinglong-static.git
|
||
PRIVATE_KEY: ${{ secrets.GITLAB_SSH_PK }}
|
||
run: |
|
||
mkdir -p tmp
|
||
cd ./tmp
|
||
cp -rf ../static/* ./
|
||
git init -b ${GITHUB_BRANCH} && git add .
|
||
git config --local user.name 'github-actions[bot]'
|
||
git config --local user.email 'github-actions[bot]@users.noreply.github.com'
|
||
git commit --allow-empty -m "copy static at $(date +'%Y-%m-%d %H:%M:%S')"
|
||
git push --force --quiet "https://${{ secrets.API_TOKEN }}@${GITHUB_REPO}.git" ${GITHUB_BRANCH}:${GITHUB_BRANCH}
|
||
|
||
mkdir -p ~/.ssh
|
||
echo "${PRIVATE_KEY}" > ~/.ssh/id_rsa
|
||
chmod 600 ~/.ssh/id_rsa
|
||
|
||
export GIT_SSH_COMMAND="ssh -v -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -l git"
|
||
git remote add gitee "${REPO_GITEE}"
|
||
git remote add gitlab "${REPO_GITLAB}"
|
||
git push --force --quiet gitee ${GITHUB_BRANCH}:${GITHUB_BRANCH}
|
||
git push --force --quiet gitlab ${GITHUB_BRANCH}:${GITHUB_BRANCH}
|
||
|
||
build:
|
||
needs: build-static
|
||
|
||
runs-on: ubuntu-latest
|
||
|
||
permissions:
|
||
packages: write
|
||
contents: read
|
||
|
||
steps:
|
||
- uses: actions/checkout@v3
|
||
- uses: pnpm/action-setup@v2
|
||
with:
|
||
version: latest
|
||
- uses: actions/setup-node@v3
|
||
with:
|
||
cache: 'pnpm'
|
||
|
||
- name: Setup timezone
|
||
uses: zcong1993/setup-timezone@master
|
||
with:
|
||
timezone: Asia/Shanghai
|
||
|
||
- name: Login to DockerHub
|
||
uses: docker/login-action@v2
|
||
with:
|
||
username: ${{ secrets.DOCKER_USERNAME }}
|
||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||
|
||
- name: Login to GHCR
|
||
uses: docker/login-action@v2
|
||
with:
|
||
registry: ghcr.io
|
||
username: ${{ github.repository_owner }}
|
||
password: ${{ secrets.GITHUB_TOKEN }}
|
||
|
||
- name: Extract metadata (tags, labels) for Docker
|
||
id: meta
|
||
uses: docker/metadata-action@v4
|
||
with:
|
||
images: |
|
||
${{ github.repository }}
|
||
ghcr.io/${{ github.repository }}
|
||
# generate Docker tags based on the following events/attributes
|
||
# nightly, master, pr-2, 1.2.3, 1.2, 1
|
||
tags: |
|
||
type=schedule,pattern=nightly
|
||
type=edge
|
||
type=ref,event=branch
|
||
type=ref,event=pr
|
||
type=semver,pattern={{version}}
|
||
type=semver,pattern={{major}}.{{minor}}
|
||
type=semver,pattern={{major}}
|
||
|
||
- name: Set up QEMU
|
||
uses: docker/setup-qemu-action@v2
|
||
|
||
- name: Set up Docker Buildx
|
||
uses: docker/setup-buildx-action@v2
|
||
|
||
- name: Build and push
|
||
id: docker_build
|
||
uses: docker/build-push-action@v3
|
||
with:
|
||
build-args: |
|
||
MAINTAINER=${{ github.repository_owner }}
|
||
QL_BRANCH=${{ github.ref_name }}
|
||
network: host
|
||
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
|
||
context: docker/
|
||
push: true
|
||
tags: ${{ steps.meta.outputs.tags }}
|
||
labels: ${{ steps.meta.outputs.labels }}
|
||
|
||
- name: Image digest
|
||
run: echo ${{ steps.docker_build.outputs.digest }}
|