diff --git a/.github/docs/README.md b/.github/docs/README.md index 5f1354c..c3e5455 100644 --- a/.github/docs/README.md +++ b/.github/docs/README.md @@ -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 diff --git a/.github/workflows/dispatch-tests.yml b/.github/workflows/dispatch-tests.yml index 2484771..ef0452f 100644 --- a/.github/workflows/dispatch-tests.yml +++ b/.github/workflows/dispatch-tests.yml @@ -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 diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml new file mode 100644 index 0000000..7c40473 --- /dev/null +++ b/.github/workflows/main-ci.yml @@ -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 diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index b5753e2..bc7bf75 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -2,7 +2,7 @@ name: Security checks on: push: - branches: ['**'] + branches-ignore: [main] pull_request: workflow_call: inputs: diff --git a/.github/workflows/tested-revision.yml b/.github/workflows/tested-revision.yml index 8aa8fbc..a12c11e 100644 --- a/.github/workflows/tested-revision.yml +++ b/.github/workflows/tested-revision.yml @@ -46,21 +46,24 @@ 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 @@ -68,11 +71,11 @@ jobs: 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" diff --git a/docs/content/contrib.md b/docs/content/contrib.md index c25f4de..db27219 100644 --- a/docs/content/contrib.md +++ b/docs/content/contrib.md @@ -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. diff --git a/docs/i18n/ru/docusaurus-plugin-content-docs/current/contrib.md b/docs/i18n/ru/docusaurus-plugin-content-docs/current/contrib.md index a3762bf..3fc1282 100644 --- a/docs/i18n/ru/docusaurus-plugin-content-docs/current/contrib.md +++ b/docs/i18n/ru/docusaurus-plugin-content-docs/current/contrib.md @@ -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. При ошибке проверки готовности скрипт восстанавливает прежний образ и порт.