Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/docs/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Deploy the Django-GC documentation

Pushes to any branch and pull requests run **Security checks**.
The branch protection check dispatches testing for the current head of a protected branch.
Pushes to unprotected branches create no testing jobs. To deploy,
Pushes to any branch and pull requests run security checks. On `main`, a single
push workflow runs security checks followed by testing. Other protected branches
start testing for the current branch head after a successful push scan. To deploy,
run **Documentation** on `main` or dispatch it from another workflow.
The release workflow dispatches it after PyPI accepts the package. It
passes the release commit, which must belong to `main`. A manual run
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/dispatch-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ name: Dispatch tests for protected branches
on:
workflow_run:
workflows: [Security checks]
types: [requested]
types: [completed]
branches-ignore: [main]

permissions: {}

jobs:
dispatch:
name: Dispatch testing for the protected branch head
if: github.event.workflow_run.event == 'push' && github.event.workflow_run.head_repository.full_name == github.repository
if: >-
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_repository.full_name == github.repository
permissions:
actions: write
contents: read
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/main-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI on main

on:
push:
branches: [main]

permissions:
contents: read

jobs:
security:
name: Security checks
uses: ./.github/workflows/security.yml

testing:
name: Tests and build
needs: security
uses: ./.github/workflows/testing.yml
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Security checks

on:
push:
branches: ['**']
branches-ignore: [main]
pull_request:
workflow_call:
inputs:
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/tested-revision.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,36 @@ jobs:
fi
fi

runs=$(gh api --paginate --method GET "repos/$GITHUB_REPOSITORY/actions/workflows/testing.yml/runs" \
runs=$(gh api --paginate --method GET "repos/$GITHUB_REPOSITORY/actions/runs" \
-f branch=main -f head_sha="$SOURCE_SHA" -F per_page=100)
run=$(jq -cs --arg sha "$SOURCE_SHA" '
[.[] | .workflow_runs[] | select(
.head_branch == "main" and .head_sha == $sha and (.event == "push" or .event == "workflow_dispatch")
.head_branch == "main" and .head_sha == $sha and (
(.path == ".github/workflows/main-ci.yml" and .event == "push") or
(.path == ".github/workflows/testing.yml" and (.event == "push" or .event == "workflow_dispatch"))
)
)] | sort_by(.created_at, .id) | last // empty
' <<< "$runs")
if [[ -z "$run" ]]; then
echo "::error::No testing.yml run on main was found for $SOURCE_SHA."
echo "::error::No CI run with tests on main was found for $SOURCE_SHA."
exit 1
fi

run_url=$(jq -r '.html_url' <<< "$run")
if ! jq -e '.status == "completed" and .conclusion == "success"' <<< "$run" > /dev/null; then
echo "::error::The latest testing.yml run for $SOURCE_SHA has not succeeded. $run_url"
echo "::error::The latest CI run with tests for $SOURCE_SHA has not succeeded. $run_url"
exit 1
fi

run_id=$(jq -r '.id' <<< "$run")
jobs=$(gh api --paginate --method GET "repos/$GITHUB_REPOSITORY/actions/runs/$run_id/jobs" \
-f filter=all -F per_page=100)
if ! jq -es '
[.[] | .jobs[] | select(.name | startswith("Pytest (Python "))]
[.[] | .jobs[] | .name |= (split(" / ") | last) | select(.name | startswith("Pytest (Python "))]
| group_by(.name) | map(max_by(.id))
| length > 0 and all(.[]; .conclusion == "success")
' <<< "$jobs" > /dev/null; then
echo "::error::No successful Pytest matrix for $SOURCE_SHA. $run_url"
exit 1
fi
echo "Verified testing.yml for $SOURCE_SHA: $run_url"
echo "Verified tests for $SOURCE_SHA: $run_url"
4 changes: 3 additions & 1 deletion docs/content/contrib.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ npm run docs:serve

## CI, releases and deployment

Pushes to any branch and pull requests run Security checks. The branch protection check dispatches the test pipeline for the current head of a protected branch. Pushes to unprotected branches create no testing jobs. Manual test runs are available under **Actions**. The test pipeline uses the dependency lock, verifies the Django migration state, runs the Python and Django matrix, builds both Python distributions and verifies the English and Russian documentation. The security workflow scans secrets, Python, Django templates, documentation JavaScript and TypeScript, and workflow files. It audits locked Python and npm dependencies.
Pushes to any branch and pull requests run security checks. On a push to `main`, security checks and tests appear in a single CI run, with tests starting after the scans pass. For other branches, a successful push scan starts testing only for the current head of a protected branch. Manual test runs are available under **Actions**.

The test pipeline uses the dependency lock, verifies the Django migration state, runs the Python and Django matrix, builds both Python distributions and verifies the English and Russian documentation. The security workflow scans secrets, Python, Django templates, documentation JavaScript and TypeScript, and workflow files. It audits locked Python and npm dependencies.

The release workflow scans the release revision, verifies it matches the current head of `main` and requires a successful `testing.yml` run for that exact SHA on `main`. Publish only after the test run finishes. Run manual publishing from `main`. After uploading wheel and sdist to PyPI, the workflow dispatches the documentation workflow for the published commit. The documentation workflow checks ancestry and reuses the test result for the selected revision before deploying over SSH. The preparation workflow installs the deployment files in the SSH user’s home directory. The deploy job streams the selected source archive to the server, and the SSH account builds it with Docker. If the container fails its health check, the deployment script restores the previous image and port.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ npm run docs:serve

## CI, публикация и деплой

Push в любую ветку и pull request запускают проверки безопасности. При push в защищённую ветку тесты запускаются для её актуального коммита. Push в обычную ветку не создаёт тестовых задач. Тесты можно запустить вручную во вкладке **Actions**. Тестовый workflow проверяет lock-файл и состояние миграций Django, прогоняет матрицу Python и Django, собирает wheel и sdist, а также проверяет и собирает обе языковые версии документации. Workflow безопасности проверяет секреты, Python, шаблоны Django, JavaScript и TypeScript документации и файлы GitHub Actions. Отдельно выполняется аудит закреплённых зависимостей Python и npm.
Push в любую ветку и pull request запускают проверки безопасности. При push в `main` сканирование и тесты отображаются в одном запуске CI. Тесты начинаются после успешного сканирования. Для остальных веток после успешного сканирования push тесты запускаются только для актуального коммита защищённой ветки. Тесты можно запустить вручную во вкладке **Actions**.

Тестовый workflow проверяет lock-файл и состояние миграций Django, прогоняет матрицу Python и Django, собирает wheel и sdist, а также проверяет и собирает обе языковые версии документации. Workflow безопасности проверяет секреты, Python, шаблоны Django, JavaScript и TypeScript документации и файлы GitHub Actions. Отдельно выполняется аудит закреплённых зависимостей Python и npm.

Релизный workflow сканирует коммит, сверяет его с текущей вершиной `main` и требует успешный запуск `testing.yml` для этого SHA в `main`. Дождитесь завершения тестов перед публикацией. Ручную публикацию запускайте из `main`. После загрузки wheel и sdist в PyPI запускается деплой документации для опубликованного коммита. Workflow документации проверяет принадлежность коммита ветке и использует результат уже пройденных тестов перед деплоем по SSH. Workflow подготовки устанавливает файлы деплоя в домашний каталог SSH-пользователя. Деплой передаёт на сервер архив выбранного коммита, и SSH-пользователь собирает его через Docker. При ошибке проверки готовности скрипт восстанавливает прежний образ и порт.

Expand Down