Skip to content

Commit

Permalink
adjust workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetWq committed May 5, 2024
1 parent fd92b34 commit 8eb2c40
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 27 deletions.
23 changes: 23 additions & 0 deletions .github/actions/setup-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Setup Environment
description: Setup Environment

runs:
using: "composite"
steps:
- name: Setup Poetry
uses: Gr1N/setup-poetry@v9

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install dependencies
run: poetry install

- name: Install fonts
run: |
apt install fonts-noto-color-emoji
mkdir /usr/share/fonts/myfonts
cp resources/fonts/* /usr/share/fonts/myfonts/
fc-cache -fv
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Docker
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
type=semver,pattern={{version}}
- name: Build and Publish
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/docker_memebot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build docker image

on:
push:
branches:
- "main"
pull_request:
paths:
- "meme_generator/**"
- "resources/**"
- "poetry.lock"
- "pyproject.toml"
workflow_dispatch:

jobs:
push_to_registry:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Setup Docker
uses: docker/setup-buildx-action@v3

- name: Login to Github Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate Tags
uses: docker/metadata-action@v4
id: metadata
with:
images: ghcr.io/meetwq/github-meme-bot
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
- name: Build and Publish
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.memebot
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
13 changes: 12 additions & 1 deletion .github/workflows/memebot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@ concurrency:

jobs:
meme-bot:
if: startsWith(github.event.comment.body, '/')
runs-on: ubuntu-latest
name: Run MemeBot
steps:
- name: Generate Tags
uses: docker/metadata-action@v4
id: metadata
with:
images: ghcr.io/meetwq/github-meme-bot
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
- name: MemeBot
uses: docker://ghcr.io/meetwq/github-meme-bot:main
uses: docker://${{ steps.metadata.outputs.tags[0] }}
env:
APP_ID: ${{ secrets.MEME_APP_ID }}
PRIVATE_KEY: ${{ secrets.MEME_PRIVATE_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
- uses: actions/checkout@v4

- name: Publish python package
uses: JRubics/poetry-publish@v1.16
uses: JRubics/poetry-publish@v2.0
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
29 changes: 6 additions & 23 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.10"

Expand All @@ -37,37 +37,20 @@ jobs:
- name: Checkout wiki repo
uses: actions/checkout@v4
with:
repository: ${{github.repository}}.wiki
repository: ${{ github.repository }}.wiki
path: wiki

- name: Setup python
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Setup Poetry
uses: Gr1N/setup-poetry@v8

- name: Install dependencies
run: poetry install

- name: Install fonts
run: |
sudo apt install fonts-noto-cjk fonts-noto-color-emoji
sudo locale-gen zh_CN zh_CN.UTF-8
sudo update-locale LC_ALL=zh_CN.UTF-8 LANG=zh_CN.UTF-8
sudo mkdir /usr/share/fonts/myfonts
sudo cp resources/fonts/* /usr/share/fonts/myfonts/
fc-cache -fv
- name: Setup Environment
uses: ./.github/actions/setup-env

- name: Update memes.md
run: poetry run python wiki/update_meme_list.py
run: python wiki/update_meme_list.py

- name: Commit & Push changes
uses: actions-js/push@master
with:
directory: "wiki"
repository: ${{github.repository}}.wiki
repository: ${{ github.repository }}.wiki
github_token: ${{ secrets.GITHUB_TOKEN }}
message: "update meme list"
branch: "master"
52 changes: 52 additions & 0 deletions Dockerfile.memebot
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM python:3.10 as tmp

WORKDIR /tmp

RUN curl -sSL https://install.python-poetry.org | python -

ENV PATH="${PATH}:/root/.local/bin"

COPY ./pyproject.toml ./poetry.lock* /tmp/

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

FROM python:3.10-slim as app

WORKDIR /app

EXPOSE 2233

VOLUME /data

ENV TZ=Asia/Shanghai \
LC_ALL=zh_CN.UTF-8 \
LOAD_BUILTIN_MEMES=true \
MEME_DIRS="[\"/data/memes\"]" \
MEME_DISABLED_LIST="[]" \
GIF_MAX_SIZE=10.0 \
GIF_MAX_FRAMES=100 \
BAIDU_TRANS_APPID="" \
BAIDU_TRANS_APIKEY="" \
LOG_LEVEL="INFO"

COPY --from=tmp /tmp/requirements.txt /app/requirements.txt

COPY ./resources/fonts/* /usr/share/fonts/meme-fonts/

RUN apt-get update \
&& apt-get install -y --no-install-recommends git locales fontconfig fonts-noto-color-emoji gettext \
&& localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8 \
&& fc-cache -fv \
&& apt-get purge -y --auto-remove \
&& rm -rf /var/lib/apt/lists/* \
&& pip install --no-cache-dir --upgrade -r /app/requirements.txt \
&& git clone --depth=1 https://github.com/MeetWq/github-meme-bot /app \
&& pip install --no-cache-dir --upgrade nonebot2 nonebot-adapter-github

COPY ./meme_generator /app/meme_generator
COPY ./docker/config.toml.template /app/config.toml.template
COPY ./docker/start_memebot.sh /app/start_memebot.sh
RUN chmod +x /app/start_memebot.sh
RUN python -m meme_generator.cli

CMD ["/app/start_memebot.sh"]
7 changes: 7 additions & 0 deletions docker/start_memebot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /usr/bin/env bash

mkdir -p ~/.config/meme_generator

envsubst < /app/config.toml.template > ~/.config/meme_generator/config.toml

exec python bot.py

0 comments on commit 8eb2c40

Please sign in to comment.