Some checks failed
CI/CD Pipeline / Telegram Notify Success (push) Has been cancelled
CI/CD Pipeline / Run Tests (push) Has been cancelled
CI/CD Pipeline / Code Quality Checks (push) Has been cancelled
CI/CD Pipeline / Code Quality Checks (pull_request) Successful in 1m42s
CI/CD Pipeline / Run Tests (pull_request) Failing after 20m33s
CI/CD Pipeline / Telegram Notify Success (pull_request) Has been cancelled
206 lines
6.3 KiB
YAML
206 lines
6.3 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- dev
|
|
- "feature/**"
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- dev
|
|
|
|
env:
|
|
PYTHON_VERSION: "3.11"
|
|
|
|
jobs:
|
|
lint:
|
|
name: Code Quality Checks
|
|
runs-on: ubuntu-latest
|
|
if: ${{ !contains(github.event.head_commit.message, '#no_lint') }}
|
|
env:
|
|
TG_BOT_KEY: ${{ secrets.TG_BOT_KEY }}
|
|
TG_CHANNEL: ${{ secrets.TG_CHANNEL }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
REPO_URL=$(echo "${GITHUB_SERVER_URL}" | sed "s|://|://oauth2:${{ gitea.token }}@|")
|
|
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
|
|
git clone --depth=1 --branch="${BRANCH}" "${REPO_URL}/${GITHUB_REPOSITORY}.git" .
|
|
git checkout "${GITHUB_SHA}"
|
|
|
|
- name: Install Python and uv
|
|
run: |
|
|
set -euo pipefail
|
|
apt-get update
|
|
apt-get install -y software-properties-common
|
|
add-apt-repository -y ppa:deadsnakes/ppa
|
|
apt-get update
|
|
apt-get install -y python3.11 python3.11-venv
|
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
|
|
- name: Create virtual environment and install dependencies
|
|
run: |
|
|
set -euo pipefail
|
|
export PATH="$HOME/.local/bin:$PATH"
|
|
uv venv --python python3.11
|
|
. .venv/bin/activate
|
|
uv sync --dev --frozen
|
|
|
|
- name: Run Ruff linting
|
|
run: |
|
|
set -euo pipefail
|
|
. .venv/bin/activate
|
|
ruff check src
|
|
|
|
- name: Run Ruff formatting check
|
|
run: |
|
|
set -euo pipefail
|
|
. .venv/bin/activate
|
|
ruff format src --check
|
|
|
|
- name: Telegram notify (lint failed)
|
|
if: failure()
|
|
continue-on-error: true
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -z "${TG_BOT_KEY:-}" ] || [ -z "${TG_CHANNEL:-}" ]; then
|
|
echo "TG_BOT_KEY or TG_CHANNEL is not set; skip telegram notification"
|
|
exit 0
|
|
fi
|
|
|
|
COMMIT_MESSAGE=$(git log -1 --pretty=%s 2>/dev/null || echo "n/a")
|
|
|
|
MSG="❌ [mostovik-backend] lint failed
|
|
branch=${GITHUB_REF_NAME}
|
|
sha=${GITHUB_SHA}
|
|
actor=${GITHUB_ACTOR}
|
|
commit=${COMMIT_MESSAGE}"
|
|
|
|
curl -fsS \
|
|
--connect-timeout 5 \
|
|
--max-time 15 \
|
|
--retry 2 \
|
|
--retry-delay 2 \
|
|
--retry-all-errors \
|
|
-X POST "https://api.telegram.org/bot${TG_BOT_KEY}/sendMessage" \
|
|
-d "chat_id=${TG_CHANNEL}" \
|
|
--data-urlencode "text=${MSG}" \
|
|
|| echo "Telegram notification failed; continue pipeline"
|
|
|
|
test:
|
|
name: Run Tests
|
|
runs-on: ubuntu-latest
|
|
if: ${{ !contains(github.event.head_commit.message, '#no_test') }}
|
|
env:
|
|
TG_BOT_KEY: ${{ secrets.TG_BOT_KEY }}
|
|
TG_CHANNEL: ${{ secrets.TG_CHANNEL }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
REPO_URL=$(echo "${GITHUB_SERVER_URL}" | sed "s|://|://oauth2:${{ gitea.token }}@|")
|
|
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
|
|
git clone --depth=1 --branch="${BRANCH}" "${REPO_URL}/${GITHUB_REPOSITORY}.git" .
|
|
git checkout "${GITHUB_SHA}"
|
|
|
|
- name: Install Python and uv
|
|
run: |
|
|
set -euo pipefail
|
|
apt-get update
|
|
apt-get install -y software-properties-common
|
|
add-apt-repository -y ppa:deadsnakes/ppa
|
|
apt-get update
|
|
apt-get install -y python3.11 python3.11-venv
|
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
|
|
- name: Create virtual environment and install dependencies
|
|
run: |
|
|
set -euo pipefail
|
|
export PATH="$HOME/.local/bin:$PATH"
|
|
uv venv --python python3.11
|
|
. .venv/bin/activate
|
|
uv sync --dev --frozen
|
|
|
|
- name: Run Django tests
|
|
env:
|
|
DJANGO_SETTINGS_MODULE: settings.test
|
|
SECRET_KEY: test-secret-key-for-ci
|
|
run: |
|
|
set -euo pipefail
|
|
. .venv/bin/activate
|
|
export PYTHONPATH="${PWD}/src:${PYTHONPATH:-}"
|
|
python src/manage.py test tests --verbosity=2
|
|
|
|
- name: Telegram notify (test failed)
|
|
if: failure()
|
|
continue-on-error: true
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -z "${TG_BOT_KEY:-}" ] || [ -z "${TG_CHANNEL:-}" ]; then
|
|
echo "TG_BOT_KEY or TG_CHANNEL is not set; skip telegram notification"
|
|
exit 0
|
|
fi
|
|
|
|
COMMIT_MESSAGE=$(git log -1 --pretty=%s 2>/dev/null || echo "n/a")
|
|
|
|
MSG="❌ [mostovik-backend] test failed
|
|
branch=${GITHUB_REF_NAME}
|
|
sha=${GITHUB_SHA}
|
|
actor=${GITHUB_ACTOR}
|
|
commit=${COMMIT_MESSAGE}"
|
|
|
|
curl -fsS \
|
|
--connect-timeout 5 \
|
|
--max-time 15 \
|
|
--retry 2 \
|
|
--retry-delay 2 \
|
|
--retry-all-errors \
|
|
-X POST "https://api.telegram.org/bot${TG_BOT_KEY}/sendMessage" \
|
|
-d "chat_id=${TG_CHANNEL}" \
|
|
--data-urlencode "text=${MSG}" \
|
|
|| echo "Telegram notification failed; continue pipeline"
|
|
|
|
notify_success:
|
|
name: Telegram Notify Success
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 1
|
|
needs: [lint, test]
|
|
if: |
|
|
always() &&
|
|
needs.lint.result == 'success' &&
|
|
needs.test.result == 'success'
|
|
env:
|
|
TG_BOT_KEY: ${{ secrets.TG_BOT_KEY }}
|
|
TG_CHANNEL: ${{ secrets.TG_CHANNEL }}
|
|
steps:
|
|
- name: Telegram notify (lint+test success)
|
|
continue-on-error: true
|
|
env:
|
|
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -z "${TG_BOT_KEY:-}" ] || [ -z "${TG_CHANNEL:-}" ]; then
|
|
echo "TG_BOT_KEY or TG_CHANNEL is not set; skip telegram notification"
|
|
exit 0
|
|
fi
|
|
|
|
MSG="✅ [mostovik-backend] lint + tests passed
|
|
branch=${GITHUB_REF_NAME}
|
|
sha=${GITHUB_SHA}
|
|
actor=${GITHUB_ACTOR}
|
|
commit=${COMMIT_MESSAGE:-n/a}"
|
|
|
|
curl -fsS \
|
|
--connect-timeout 5 \
|
|
--max-time 15 \
|
|
--retry 2 \
|
|
--retry-delay 2 \
|
|
--retry-all-errors \
|
|
-X POST "https://api.telegram.org/bot${TG_BOT_KEY}/sendMessage" \
|
|
-d "chat_id=${TG_CHANNEL}" \
|
|
--data-urlencode "text=${MSG}" \
|
|
|| echo "Telegram notification failed; continue pipeline"
|