Merge pull request #65 from he0119/main

Add GitHub Actions
This commit is contained in:
felinae98 2022-05-21 22:18:34 +08:00 committed by GitHub
commit 08bf8782e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 429 additions and 0 deletions

14
.github/actions/build-docs/action.yml vendored Normal file
View File

@ -0,0 +1,14 @@
name: Build Docs
description: Build Docs
runs:
using: "composite"
steps:
- name: Setup Node Environment
uses: ./.github/actions/setup-node
- name: Build Frontend
shell: bash
run: |
yarn install
yarn docs:build

View File

@ -0,0 +1,15 @@
name: Build Frontend
description: Build Frontend
runs:
using: "composite"
steps:
- name: Setup Node Environment
uses: ./.github/actions/setup-node
- name: Build Frontend
shell: bash
working-directory: ./admin-frontend
run: |
yarn install
yarn build

18
.github/actions/setup-node/action.yml vendored Normal file
View File

@ -0,0 +1,18 @@
name: Setup Node
description: Setup Node
runs:
using: "composite"
steps:
- uses: actions/setup-node@v2
with:
node-version: "16"
- id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
shell: bash
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

40
.github/actions/setup-python/action.yml vendored Normal file
View File

@ -0,0 +1,40 @@
name: Setup Python
description: Setup Python
inputs:
python-version:
description: Python version
required: false
default: "3.9"
runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ inputs.python-version }}
- name: Install poetry
uses: Gr1N/setup-poetry@v7
- name: Cache Windows dependencies
uses: actions/cache@v2
if: ${{ runner.os == 'Windows' }}
with:
path: ~/AppData/Local/pypoetry/Cache/virtualenvs
key: ${{ runner.os }}-poetry-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Cache Linux dependencies
uses: actions/cache@v2
if: ${{ runner.os == 'Linux' }}
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Cache macOS dependencies
uses: actions/cache@v2
if: ${{ runner.os == 'macOS' }}
with:
path: ~/Library/Caches/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

108
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,108 @@
name: CI
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Frontend
uses: ./.github/actions/build-frontend
- name: Upload dist
uses: actions/upload-artifact@v3
with:
name: frontend
path: ./admin-frontend/build/
test:
name: Test Coverage
runs-on: ${{ matrix.os }}
needs: build-frontend
strategy:
matrix:
python-version: ["3.9", "3.10"]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false
env:
OS: ${{ matrix.os }}
PYTHON_VERSION: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- name: Download frontend files
uses: actions/download-artifact@v2
with:
name: frontend
path: ./src/plugins/nonebot_bison/admin_page/dist
- name: Setup Python environment
uses: ./.github/actions/setup-python
with:
python-version: ${{ matrix.python-version }}
- name: Install prerequisites
run: poetry install
- name: Run Pytest
run: poetry run pytest --cov-report xml --cov=./src/plugins/nonebot_bison -k 'not compare and not render'
- name: Upload coverage report
uses: codecov/codecov-action@v3
with:
env_vars: OS,PYTHON_VERSION
docker:
name: Docker
runs-on: ubuntu-latest
needs: [build-frontend, test]
strategy:
matrix:
include:
- file: ./docker/Dockerfile_with_frontend
tags: felinae98/nonebot-bison:main
- file: ./docker/Dockerfile_with_frontend_sentry
tags: felinae98/nonebot-bison:main-sentry
steps:
- uses: actions/checkout@v3
- name: Download frontend files
uses: actions/download-artifact@v2
with:
name: frontend
path: ./src/plugins/nonebot_bison/admin_page/dist
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ${{ matrix.file }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ matrix.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max

39
.github/workflows/release-drafter.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: Release Drafter
on:
pull_request_target:
branches:
- main
types:
- closed
jobs:
update-release-drafter:
runs-on: ubuntu-latest
concurrency:
group: pull-request-changelog
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
- uses: release-drafter/release-drafter@v5
id: release-drafter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update Changelog
uses: docker://ghcr.io/nonebot/auto-changelog:master
with:
latest_changes_position: '# Change Log\n\n'
latest_changes_title: '## 最近更新'
replace_regex: '(?<=## 最近更新\n)[\s\S]*?(?=\n## )'
changelog_body: ${{ steps.release-drafter.outputs.body }}
commit_and_push: false
- name: Commit and Push
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add .
git diff-index --quiet HEAD || git commit -m ":memo: Update changelog"
git push

35
.github/workflows/release-trigger.yml vendored Normal file
View File

@ -0,0 +1,35 @@
name: Trigger Release
on:
workflow_dispatch:
jobs:
archive:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python environment
uses: ./.github/actions/setup-python
- run: echo "TAG_NAME=v$(poetry version -s)" >> $GITHUB_ENV
- name: Archive Changelog
uses: docker://ghcr.io/nonebot/auto-changelog:master
with:
archive_regex: '(?<=## )最近更新(?=\n)'
archive_title: ${{ env.TAG_NAME }}
commit_and_push: false
- name: Push Tag
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add .
git commit -m ":bookmark: Release $(poetry version -s)"
git tag ${{ env.TAG_NAME }}
git push && git push --tags

124
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,124 @@
name: Release
on:
push:
tags:
- v*
jobs:
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Frontend
uses: ./.github/actions/build-frontend
- name: Upload dist
uses: actions/upload-artifact@v3
with:
name: frontend
path: ./admin-frontend/build/
publish-pypi-github:
runs-on: ubuntu-latest
needs: build-frontend
steps:
- uses: actions/checkout@v3
- name: Download frontend files
uses: actions/download-artifact@v2
with:
name: frontend
path: ./src/plugins/nonebot_bison/admin_page/dist
- name: Setup Python environment
uses: ./.github/actions/setup-python
# - name: Publish PyPI
# run: poetry publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} || echo "Already pushed to pypi"
- run: |
echo "TAG_NAME=${GITHUB_REF#refs/tags/} >> $GITHUB_ENV"
- uses: release-drafter/release-drafter@v5
with:
name: Release ${{ env.TAG_NAME }}
tag: ${{ env.TAG_NAME }}
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
gh release upload --clobber ${{ env.TAG_NAME }} dist/*
publish-docker:
runs-on: ubuntu-latest
needs: build-frontend
steps:
- uses: actions/checkout@v3
- name: Download frontend files
uses: actions/download-artifact@v2
with:
name: frontend
path: ./src/plugins/nonebot_bison/admin_page/dist
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/Dockerfile_with_frontend
push: true
tags: |
felinae98/nonebot-bison:latest
felinae98/nonebot-bison:${{ github.event.release.tag_name }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build Sentry and push
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/Dockerfile_with_frontend_sentry
push: true
tags: felinae98/nonebot-bison:${{ github.event.release.tag_name }}-sentry
cache-from: type=gha
cache-to: type=gha,mode=max
deploy-web:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Docs
uses: ./.github/actions/build-docs
- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v1
with:
publish-dir: "./docs/.vuepress/dist"
production-deploy: true
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Deploy ${{ github.event.release.tag_name }}"
enable-commit-comment: false
alias: ${{ github.event.release.tag_name }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}

36
.github/workflows/website-preview.yml vendored Normal file
View File

@ -0,0 +1,36 @@
name: Site Deploy(Preview)
on:
pull_request_target:
jobs:
preview:
runs-on: ubuntu-latest
concurrency:
group: pull-request-preview-${{ github.event.number }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Build Docs
uses: ./.github/actions/build-docs
- name: Get Deploy Name
run: |
echo "DEPLOY_NAME=deploy-preview-${{ github.event.number }}" >> $GITHUB_ENV
- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v1
with:
publish-dir: "./docs/.vuepress/dist"
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Deploy ${{ env.DEPLOY_NAME }}@${{ github.sha }}"
enable-commit-comment: false
alias: ${{ env.DEPLOY_NAME }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}