Skip to content

Commit

Permalink
ci: update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
datvodinh committed Oct 11, 2024
1 parent 7d5355a commit 66a50c9
Show file tree
Hide file tree
Showing 12 changed files with 2,924 additions and 2,707 deletions.
38 changes: 0 additions & 38 deletions .circleci/config.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/actions/build-python/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "build-python"
description: "Action to build a Python and poetry environment."

inputs:
python-version:
required: false
description: "The python version to use"
default: "3.11"

context-directory:
required: true
description: "The context directory to use"
default: "."

runs:
using: "composite"
steps:
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}

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

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

- name: Install dependencies
working-directory: ${{ inputs.context-directory }}
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction
shell: bash

- name: Make Check
working-directory: ${{ inputs.context-directory }}
run: make check
shell: bash

- name: Make Build
working-directory: ${{ inputs.context-directory }}
run: make build
shell: bash
65 changes: 65 additions & 0 deletions .github/actions/package-container/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "package-container"
description: "Composite action to to build a docker image."

inputs:
IMAGE_NAME:
required: true
description: "The name of the image"
FOLDER_PATH:
required: true
description: "The context path to build the docker"
TOKEN:
description: "A Github PAT"
required: true
USERNAME:
description: "A Github PAT username"
required: true
ORGANIZATION_NAME:
description: "The organization name"
required: true

runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create a new tag
id: tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ inputs.TOKEN }}
WITH_V: "true"
DEFAULT_BUMP: patch

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{inputs.ORGANIZATION_NAME}}/${{inputs.IMAGE_NAME}}
tags: |
type=sha
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ inputs.USERNAME }}
password: ${{ inputs.TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: ${{ inputs.FOLDER_PATH }}
push: true
tags: ${{ steps.meta.outputs.tags }},ghcr.io/${{inputs.ORGANIZATION_NAME}}/${{inputs.IMAGE_NAME}}:${{ steps.tag.outputs.new_tag }}
labels: ${{ steps.meta.outputs.labels }}
28 changes: 28 additions & 0 deletions .github/actions/setup-poetry-env/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "setup-poetry-env"
description: "Composite action to setup the Python and poetry environment."

inputs:
python-version:
required: false
description: "The python version to use"
default: "3.11"

runs:
using: "composite"
steps:
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}

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

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('poetry.lock') }}
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
time: "07:00"
timezone: "Asia/Ho_Chi_Minh"
groups:
github:
patterns:
- "*"
labels:
- "ci"
- "dependencies"
33 changes: 33 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Build"

on:
push:
branches:
- "main"
workflow_dispatch:

concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }} - CI"
cancel-in-progress: true

jobs:
docker-build:
name: Chatbot Image
environment: dev
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
if: github.event.pull_request.draft == false
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4

- name: Build Chatbot
uses: ./.github/actions/package-container
with:
FOLDER_PATH: ./app
IMAGE_NAME: chatbot
TOKEN: ${{ secrets.GITHUB_TOKEN }}
USERNAME: ${{ github.actor }}
ORGANIZATION_NAME: datvodinh
64 changes: 64 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "CI"

on:
pull_request:
push:
branches:
- "main"
workflow_dispatch:

concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }} - CI"
cancel-in-progress: true

jobs:
lint:
name: Ruff Lint
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
# Update output format to enable automatic inline annotations.
- name: Run Ruff
run: ruff check --output-format=github .

build:
name: Build Package
runs-on: self-hosted
strategy:
matrix:
python-version: ["3.11"]
fail-fast: false
steps:
- name: Check out
uses: actions/checkout@v4

- name: Build Chatbot
uses: ./.github/actions/build-python
with:
context-directory: ./app/

test:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry pytest
# Update output format to enable automatic inline annotations.
- name: Run Pytest
run: |
cd app
poetry run pytest
39 changes: 0 additions & 39 deletions .github/workflows/python-app.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ junit.xml
harry_potter_dataset
storage
result
.conda_config
Loading

0 comments on commit 66a50c9

Please sign in to comment.