Skip to content

add github actions

add github actions #32

Workflow file for this run

name: CI
on:
push:
branches: ["**"]
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
ci:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Show Docker versions (debug)
run: |
docker version
docker compose version
- name: Build containers
env:
DOCKER_BUILDKIT: 1
HOST_UID: "1000"
HOST_GID: "1000"
DISPLAY: ":1"
HOST_USERNAME: ${{ secrets.HOST_USERNAME }}
HOST_GROUPNAME: ${{ secrets.HOST_GROUPNAME }}
run: |
docker compose --env-file ./service/.env build --pull
# ----- Code style / lint -----
- name: Black (format check)
env:
DOCKER_BUILDKIT: 1
HOST_UID: "1000"
HOST_GID: "1000"
DISPLAY: ":1"
HOST_USERNAME: ${{ secrets.HOST_USERNAME }}
HOST_GROUPNAME: ${{ secrets.HOST_GROUPNAME }}
run: |
docker compose --env-file ./service/.env run --rm service black --check --diff .
- name: Ruff (lint)
env:
DOCKER_BUILDKIT: 1
HOST_UID: "1000"
HOST_GID: "1000"
DISPLAY: ":1"
HOST_USERNAME: ${{ secrets.HOST_USERNAME }}
HOST_GROUPNAME: ${{ secrets.HOST_GROUPNAME }}
run: |
docker compose --env-file ./service/.env run --rm service ruff check .
# ----- Tests -----
- name: Pytest
env:
DOCKER_BUILDKIT: 1
HOST_UID: "1000"
HOST_GID: "1000"
DISPLAY: ":1"
HOST_USERNAME: ${{ secrets.HOST_USERNAME }}
HOST_GROUPNAME: ${{ secrets.HOST_GROUPNAME }}
run: |
docker compose --env-file ./service/.env run --rm service pytest -q
# 後始末(Compose v2 は down しなくても CI エージェントが片付けますが、明示的に消す場合)
- name: Cleanup
env:
DOCKER_BUILDKIT: 1
HOST_UID: "1000"
HOST_GID: "1000"
DISPLAY: ":1"
HOST_USERNAME: ${{ secrets.HOST_USERNAME }}
HOST_GROUPNAME: ${{ secrets.HOST_GROUPNAME }}
if: always()
run: |
docker compose --env-file ./service/.env down -v --remove-orphans
# name: CI
# on:
# push:
# branches: ["**"]
# pull_request:
# workflow_dispatch:
# jobs:
# lint:
# name: Lint (ruff + black)
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - name: Set up Python
# uses: actions/setup-python@v5
# with:
# python-version: "3.11"
# - name: Install dev tools
# run: |
# python -m pip install --upgrade pip
# pip install -r service/requirements.txt
# - name: Ruff (lint)
# run: ruff check .
# - name: Black (format check)
# run: black --check --diff .
# test:
# name: Tests (pytest)
# runs-on: ubuntu-latest
# needs: lint
# strategy:
# matrix:
# python-version: ["3.11"]
# steps:
# - uses: actions/checkout@v4
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python-version }}
# - name: Cache pip
# uses: actions/cache@v4
# with:
# path: ~/.cache/pip
# key: ${{ runner.os }}-pip-${{ hashFiles('service/requirements.txt') }}
# restore-keys: |
# ${{ runner.os }}-pip-
# - name: Install deps
# run: |
# python -m pip install --upgrade pip
# pip install -r service/requirements.txt;
# - name: Run pytest
# run: pytest -q