Skip to content

Commit

Permalink
Merge pull request #8 from Namgyu-Youn/04-GitHub_Action
Browse files Browse the repository at this point in the history
Update CI/CD, Ruff setting
  • Loading branch information
Namgyu-Youn authored Jan 10, 2025
2 parents 7e4290d + ecd73e5 commit 7b0690b
Show file tree
Hide file tree
Showing 21 changed files with 556 additions and 1,486 deletions.
35 changes: 27 additions & 8 deletions .github/conda/meta.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
{% set name = "topicgen" %}
{% set version = "0.1.2" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
path: ../../

build:
noarch: python
number: 0
script: {{ PYTHON }} -m pip install . -vv

requirements:
host:
- numpy
- torch
- transformers
- gradio
- aiohttp
- python-dotenv
- pip
- python >=3.10,<3.13
- poetry-core
run:
- python >=3.10,<3.13
- numpy
- torch
- transformers
- gradio
- aiohttp
- python-dotenv
- ruff
- tiktoken
- protobuf
- sentencepiece
- tokenizers

test:
imports:
- topicgen
- transformers

about:
home: https://github.com/Namgyu-Youn/github-topic-generator
home: https://github.com/Namgyu-Youn/topicgen
license: MIT
license_file: LICENSE
summary: "github-topic-generator : Generate related topics('#') by analyzing your source code."
summary: "topicgen: Generate related topics('#') by analyzing your source code."
doc_url: https://github.com/Namgyu-Youn/topicgen
dev_url: https://github.com/Namgyu-Youn/topicgen

extra:
recipe-maintainers:
- Namgyu-Youn
6 changes: 0 additions & 6 deletions .github/dependabot.yml

This file was deleted.

85 changes: 57 additions & 28 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,61 @@
name: CI
name: CI/CD Workflow

on: [push, pull_request]
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest
lint-and-test:
strategy:
matrix:
# os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.11']
# python-version: ['3.10', '3.11']

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Poetry
run: |
pipx install poetry
echo "/root/.local/bin" >> $GITHUB_PATH
- name: Configure Poetry
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Install dependencies
run: |
poetry install --no-root
- name: Lint with Ruff
run: |
poetry run ruff check .
- uses: actions/checkout@v4

- name: Hadolint
uses: hadolint/[email protected]
continue-on-error: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction

- name: Run linters
run: |
poetry run ruff check .
poetry run ruff format .
- name: ONNX Model Conversion
run: |
poetry run python -c "from scripts.analyzer import TopicAnalyzer; analyzer = TopicAnalyzer(); analyzer._convert_to_onnx()"
- name: Run tests
run: |
poetry run pytest tests/
poetry run pytest --cov=topicgen
35 changes: 35 additions & 0 deletions .github/workflows/conda-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Conda Package

on:
release:
types: [published]
workflow_dispatch: # Manual trigger option

jobs:
conda-build:
name: Build Conda Package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Conda
uses: conda-incubator/setup-miniconda@v3
with:
auto-activate-base: true
python-version: "3.12"

- name: Install conda-build
run: |
conda install conda-build anaconda-client conda-verify -y
- name: Build conda package
run: |
conda build .github/conda
- name: Upload to Anaconda.org
if: github.event_name == 'release'
env:
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
run: |
anaconda login --username ${{ secrets.ANACONDA_USERNAME }} --password ${{ secrets.ANACONDA_TOKEN }}
anaconda upload /usr/share/miniconda/conda-bld/noarch/topicgen-*.tar.bz2
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ flagged
.gradio

# Ruff
-unsafe-fixes
-unsafe-fixes
.ruff_cache
.coverage
8 changes: 1 addition & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ exclude: |
(?x)(
# 문서 파일
^.*\.md$|
^.*\.json$|
^docs/|
# 노트북 및 실험 파일
Expand Down Expand Up @@ -49,14 +48,9 @@ repos:
- id: check-added-large-files
args: ['--maxkb=1024']

- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
args: ["--config", "pyproject.toml"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [--fix, --exit-non-zero-on-fix]
23 changes: 16 additions & 7 deletions .vscode/setting.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{
"python.formatting.provider": "black",
// Global formatting settings
"editor.formatOnSave": true,
"editor.renderWhitespace": "trailing",
"editor.rulers": [120],
"python.linting.enabled": true,
"python.linting.ruffEnabled": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,

// Python-specific settings
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.rulers": [120],
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
},
"ruff.lint.run": "onSave"

// YAML settings (important for GitHub Actions)
"[yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml",
"editor.tabSize": 2
}
}
30 changes: 12 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,46 @@ FROM python:3.12.3-slim as builder

WORKDIR /app

# Install system dependencies required for building
# Install only necessary system dependencies
RUN apt-get update && apt-get install -y \

Check failure on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint-and-test (ubuntu-latest, 3.11)

DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`

Check failure on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint-and-test (ubuntu-latest, 3.11)

DL3015 info: Avoid additional packages by specifying `--no-install-recommends`
protobuf-compiler \
gcc \
g++ \
cmake \
pkg-config \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# Install poetry
RUN pip install poetry
# Install and configure Poetry
RUN pip install poetry && \

Check failure on line 12 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint-and-test (ubuntu-latest, 3.11)

DL3042 warning: Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>`

Check failure on line 12 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint-and-test (ubuntu-latest, 3.11)

DL3013 warning: Pin versions in pip. Instead of `pip install <package>` use `pip install <package>==<version>` or `pip install --requirement <requirements file>`
poetry config virtualenvs.create false

# Copy dependency files
# Copy dependency files and install
COPY pyproject.toml poetry.lock ./
RUN poetry install --no-interaction --no-ansi --no-root --without dev

# Configure poetry and install dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --no-root

# Second stage
# Runtime environment
FROM python:3.12.3-slim

WORKDIR /app

# Copy installed dependencies from builder
# Copy only necessary files from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages/ /usr/local/lib/python3.12/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/

# Install runtime system dependencies
# Install runtime dependencies
RUN apt-get update && apt-get install -y \

Check failure on line 29 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint-and-test (ubuntu-latest, 3.11)

DL3015 info: Avoid additional packages by specifying `--no-install-recommends`

Check failure on line 29 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint-and-test (ubuntu-latest, 3.11)

DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
protobuf-compiler \
curl \
&& rm -rf /var/lib/apt/lists/*

# Copy application code
COPY . .

# Create non-root user
# Security: Create non-root user and set permissions
RUN useradd -m appuser && \
chown -R appuser:appuser /app
USER appuser

EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1

CMD ["poetry", "run", "python", "app.py"]
CMD ["poetry", "run", "python", "app.py"]
7 changes: 3 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@


async def process_url(url: str, main_cat: str, sub_cat: str, use_gpu: bool) -> tuple[str, str, str]:
"""
Process GitHub URL and generate topics
"""Process GitHub URL and generate topics.
Args:
url: GitHub repository URL
Expand Down Expand Up @@ -44,7 +43,7 @@ async def process_url(url: str, main_cat: str, sub_cat: str, use_gpu: bool) -> t


def create_interface():
"""Create and configure the Gradio interface"""
"""Create and configure the Gradio interface."""
with gr.Blocks() as demo:
gr.Markdown("# Enhanced GitHub Topic Generator")

Expand All @@ -67,7 +66,7 @@ def create_interface():
dependencies = gr.Textbox(label="Dependencies")

def update_sub_category(main_cat):
"""Update sub-category choices based on main category selection"""
"""Update sub-category choices based on main category selection."""
return gr.Dropdown(choices=list(TOPIC_LIST[main_cat].keys()) if main_cat else [])

main_category.change(update_sub_category, inputs=main_category, outputs=sub_category)
Expand Down
7 changes: 0 additions & 7 deletions dependabot.yml

This file was deleted.

Loading

0 comments on commit 7b0690b

Please sign in to comment.