diff --git a/.editorconfig b/.editorconfig index bc4951b6..a7b64197 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,3 +14,6 @@ indent_size = 4 [*.md] max_line_length = off insert_final_newline = false + +[*.yml] +trim_trailing_whitespace = true diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7b41d832..25d95971 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -39,7 +39,6 @@ jobs: uses: docker/build-push-action@v2 with: context: . - file: base.Dockerfile push: true tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e3f7f8c3..13143559 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,27 +14,17 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - name: Set up Python - uses: actions/setup-python@v2 + uses: he0119/setup-python@main with: python-version: 3.9 - - name: Install poetry - uses: Gr1N/setup-poetry@v7 - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ~/.cache/pypoetry/virtualenvs - key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }} + - name: Install prerequisites run: poetry install + - name: Run tests - run: poetry run pytest --cov=src --cov-report xml --junitxml=TEST-pytest.xml - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v2 - with: - name: Unit Test Results - path: | - **/TEST-*.xml + run: poetry run pytest --cov=src --cov-report xml + - name: Upload coverage to Codecov uses: codecov/codecov-action@v2 diff --git a/Dockerfile b/Dockerfile index 1bd6b11b..40946183 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,32 @@ -FROM ghcr.io/nonebot/nonebot2-publish-bot:sha-4e2681c +FROM python:3.9 as requirements-stage + +WORKDIR /tmp + +COPY ./pyproject.toml ./poetry.lock* /tmp/ + +RUN curl -sSL https://install.python-poetry.org -o install-poetry.py + +RUN python install-poetry.py --yes + +ENV PATH="${PATH}:/root/.local/bin" + +RUN poetry export -f requirements.txt --output requirements.txt --without-hashes + +FROM python:3.9-slim-bullseye WORKDIR /app +RUN apt-get update \ + && apt-get install -y --no-install-recommends git \ + && apt-get purge -y --auto-remove \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=requirements-stage /tmp/requirements.txt /app/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r requirements.txt + +RUN rm requirements.txt + COPY ./main.py /app/ COPY ./src /app/src diff --git a/base.Dockerfile b/base.Dockerfile deleted file mode 100644 index a8478c66..00000000 --- a/base.Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -FROM python:3.9 as requirements-stage - -WORKDIR /tmp - -COPY ./pyproject.toml ./poetry.lock* /tmp/ - -RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -o install-poetry.py - -RUN python install-poetry.py --yes - -ENV PATH="${PATH}:/root/.local/bin" - -RUN poetry export -f requirements.txt --output requirements.txt --without-hashes - -FROM python:3.9-slim-bullseye - -WORKDIR /app - -RUN apt-get update \ - && apt-get install -y --no-install-recommends git \ - && apt-get purge -y --auto-remove \ - && rm -rf /var/lib/apt/lists/* - -COPY --from=requirements-stage /tmp/requirements.txt /app/requirements.txt - -RUN pip install --no-cache-dir --upgrade -r requirements.txt - -RUN rm requirements.txt - -COPY ./main.py /app/ -COPY ./src /app/src - -CMD ["python", "/app/main.py"]