generated from nicebots-xyz/botkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'template/dev' into dev
- Loading branch information
Showing
87 changed files
with
3,380 additions
and
1,279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.copywrite.hcl | ||
requirements.txt | ||
pdm.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.