Skip to content

Commit

Permalink
Merge remote-tracking branch 'template/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Paillat-dev committed Feb 20, 2025
2 parents 9892f44 + 2d829aa commit 56e86a9
Show file tree
Hide file tree
Showing 87 changed files with 3,380 additions and 1,279 deletions.
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.github/
.gitignore
config.example.yaml
poetry.lock
pyproject.toml
readme.md
renovate.json
2 changes: 2 additions & 0 deletions .github/workflows/CI-CD.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#file: noinspection SpellCheckingInspection
name: CI/CD

on:
push:
branches: [ "main", "dev" ]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v4

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

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3.3.0
Expand All @@ -29,7 +29,7 @@ jobs:

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5.5.1
uses: docker/metadata-action@v5.6.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
Expand All @@ -39,7 +39,7 @@ jobs:
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v6.9.0
uses: docker/build-push-action@v6.14.0
with:
context: .
push: true
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/sync_template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Template Sync

on:
schedule:
- cron: "0 0 1 * *"
workflow_dispatch:

jobs:
repo-sync:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
if: github.repository != 'nicebots-xyz/botkit'
outputs:
pr_branch: ${{ steps.template-sync.outputs.pr_branch }}

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Template Sync
id: template-sync
uses: AndreasAugustin/actions-template-sync@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: nicebots-xyz/botkit
upstream_branch: dev
pr_commit_msg: "core: :twisted_rightwards_arrows: Merge remote template"
pr_title: "core: :twisted_rightwards_arrows: Merge remote template"

update-deps:
needs: repo-sync
if: needs.repo-sync.outputs.pr_branch
uses: ./.github/workflows/update_dependencies.yaml
with:
pr_branch: ${{ needs.repo-sync.outputs.pr_branch }}
permissions:
contents: write
pull-requests: write
109 changes: 98 additions & 11 deletions .github/workflows/update_dependencies.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,126 @@
name: Update Dependencies

name: Update dependencies
on:
schedule:
- cron: '0 0 * * 0' # Runs at 00:00 every Sunday
workflow_dispatch: # Allows manual triggering
workflow_dispatch:
inputs:
pr_branch:
description: 'Branch to push changes to (optional)'
required: false
type: string
workflow_call:
inputs:
pr_branch:
description: 'Branch to push changes to'
required: true
type: string

jobs:
update-dependencies:
update-deps:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
name: Checkout repository
with:
fetch-depth: 0 # Fetch all history for all branches
- name: Checkout target branch
if: inputs.pr_branch
run: |
BRANCH_NAME=$(echo ${{ inputs.pr_branch }} | sed 's|refs/heads/||')
git fetch origin $BRANCH_NAME
git checkout $BRANCH_NAME
git pull origin $BRANCH_NAME
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
with:
cache: true

- name: Lock dependencies
run: pdm lock
run: pdm lock -G :all

- name: Export requirements
run: pdm run export

- name: Check for changes
id: git-check
run: |
git diff --exit-code --quiet requirements.txt || echo "changed=true" >> $GITHUB_OUTPUT
- name: Create Pull Request
- name: Create required label if not exists
run: |
# Check if label exists
LABEL_EXISTS=$(gh label list | grep "automated-dependencies-update" || true)
if [ -z "$LABEL_EXISTS" ]; then
echo "Creating automated-dependencies-update label..."
gh label create "automated-dependencies-update" \
--color "2DA44E" \
--description "Automated PR for updating project dependencies"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Handle dependency updates
if: steps.git-check.outputs.changed == 'true'
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git checkout -b update-dependencies-${{ github.run_id }}
git add requirements.txt pyproject.toml pdm.lock
git commit -m "Update dependencies"
git push origin update-dependencies-${{ github.run_id }}
gh pr create --title "Update dependencies" --body "This PR updates the project dependencies. Please review the changes and merge if everything looks good." --base ${{ github.ref_name }} --head update-dependencies-${{ github.run_id }}
# Function to commit changes
commit_changes() {
git add requirements.txt pyproject.toml pdm.lock
git commit -m "Update dependencies"
}
# Function to create PR
create_pr() {
local BRANCH=$1
gh pr create \
--title "Update dependencies" \
--body "This PR updates the project dependencies. Please review the changes and merge if everything looks good." \
--base ${{ github.ref_name }} \
--head $BRANCH \
--label "automated-dependencies-update"
}
if [ -n "${{ inputs.pr_branch }}" ]; then
# Push to existing branch
BRANCH_NAME=$(echo ${{ inputs.pr_branch }} | cut -d'/' -f 3)
git checkout $BRANCH_NAME
commit_changes
git push origin $BRANCH_NAME
else
# Check for existing PR - strict search for exact title and our specific branch pattern
EXISTING_PR=$(gh pr list --search "in:title Update dependencies is:open label:automated-dependencies-update" --json headRefName,number,author -q '.[0]')
if [ -n "$EXISTING_PR" ]; then
# Check if PR has our automation label
BRANCH_NAME=$(echo $EXISTING_PR | jq -r .headRefName)
if [[ "$BRANCH_NAME" == update-dependencies-* ]]; then
echo "Found valid automated PR with branch $BRANCH_NAME. Updating it."
git checkout -B $BRANCH_NAME
commit_changes
git push -f origin $BRANCH_NAME
else
echo "Found PR but wrong branch pattern. Creating new branch."
NEW_BRANCH="update-dependencies-${{ github.run_id }}"
git checkout -b $NEW_BRANCH
commit_changes
git push origin $NEW_BRANCH
create_pr $NEW_BRANCH
fi
else
echo "No existing PR found. Creating new branch and PR."
NEW_BRANCH="update-dependencies-${{ github.run_id }}"
git checkout -b $NEW_BRANCH
commit_changes
git push origin $NEW_BRANCH
create_pr $NEW_BRANCH
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 38 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) NiceBots
# SPDX-License-Identifier: MIT

ci:
autoupdate_commit_msg: "chore(pre-commit): pre-commit autoupdate"
autofix_commit_msg: "style(pre-commit): auto fixes from pre-commit.com hooks"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: \.(po|pot|yml|yaml)$
- id: end-of-file-fixer
exclude: \.(po|pot|yml|yaml)$
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
exclude: \.(po|pot|yml|yaml)$
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.4
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: local
hooks:
- id: copywrite
name: copywrite
entry: copywrite headers
language: system
pass_filenames: false
files: .
3 changes: 3 additions & 0 deletions .templatesyncignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.copywrite.hcl
requirements.txt
pdm.lock
38 changes: 20 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
# Copyright (c) NiceBots.xyz
# SPDX-License-Identifier: MIT

# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.12-slim-bookworm
ARG PYTHON_VERSION=3.12
ARG NODE_VERSION=20
FROM python:${PYTHON_VERSION}-slim-bookworm AS python-base

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

# we move to the app folder and run the pip install command
RUN pip install -U pdm
ENV PDM_CHECK_UPDATE=false

WORKDIR /app
COPY src pyproject.toml pdm.lock ./

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
RUN pdm export --prod -o requirements.txt

# we copy just the requirements.txt first to leverage Docker cache
COPY requirements.txt .
FROM python:${PYTHON_VERSION}-slim-bookworm AS app

# Install pip requirements
RUN pip install -r requirements.txt
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
RUN adduser -u 6392 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

# We copy the rest of the codebase into the image
COPY ./ /app/
COPY --from=python-base --chown=appuser /app/requirements.txt ./
COPY src/ ./src
COPY LICENSE ./

RUN pip install -r requirements.txt --require-hashes
USER appuser

# We run the application
CMD ["python", "src"]
CMD ["python", "src"]
9 changes: 9 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) NiceBots
# SPDX-License-Identifier: MIT

services:
redis:
image: redis:alpine
ports:
- "6379:6379"
command: --loglevel debug
10 changes: 8 additions & 2 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ extensions:
every: 300 # 300 seconds = 5 minutes
bot:
token: "bot token here" # Your bot token
cache:
type: "memory" # Cache type. Possible values: "memory" or "redis"
redis: # Redis configuration (only used if type is "redis")
host: "localhost" # Redis server host
port: 6379 # Redis server port
db: 0 # Redis database number
password: null # Redis password (optional)
ssl: false # Whether to use SSL for Redis connection
logging:
level: "INFO" # The logging level. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL
use:
bot: true # Whether to run the bot
backend: false # Whether to run the backend


Loading

0 comments on commit 56e86a9

Please sign in to comment.