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
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI Map2Check Rust

on:
push:
branches: [ "master", "develop", "release/**" ]
branches: [ "main", "develop", "release/**" ]
pull_request:
branches: [ "master", "develop", "release/**" ]
branches: [ "main", "develop", "release/**" ]

jobs:
build_and_test:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ the C ABI or the JSON report must update them.
### Changed

- `develop` replaces `feature/rust` as the integration branch: CI runs on
pushes and pull requests to `master`, `develop` and `release/**`, and
pushes and pull requests to `main`, `develop` and `release/**`, and
`scripts/branch-protection.sh` protects `develop` instead of
`feature/rust`.
- The release branch `master` is renamed to `main`; CI, the
branch-protection script and the docs follow the new name.

## [1.0.0-rc1] - Unreleased

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![License](https://img.shields.io/badge/license-GPL--3-lighgreen)](../master/LICENSE)
[![Build Status](https://travis-ci.org/hbgit/map2check-library.svg?branch=master)](https://travis-ci.org/hbgit/map2check-library)
[![codecov](https://codecov.io/gh/hbgit/map2check-library/branch/master/graph/badge.svg)](https://codecov.io/gh/hbgit/map2check-library)
[![License](https://img.shields.io/badge/license-GPL--3-lighgreen)](../main/LICENSE)
[![Build Status](https://travis-ci.org/hbgit/map2check-library.svg?branch=main)](https://travis-ci.org/hbgit/map2check-library)
[![codecov](https://codecov.io/gh/hbgit/map2check-library/branch/main/graph/badge.svg)](https://codecov.io/gh/hbgit/map2check-library)

# Map2Check-Library

Expand Down Expand Up @@ -86,16 +86,16 @@ cargo deny check

### Proteção de branches

Fluxo: `develop` é a branch padrão do repositório. Branches de trabalho `<tipo>/issue-<N>-<slug>` (`tipo` ∈ feat, fix, docs, test, build, ci, chore) abrem PR para `develop`; releases sobem de `develop` para `master` por PR. `develop` e `master` exigem o check `build_and_test` (workflow "CI Map2Check Rust") e commits assinados; `master` exige também 1 review. A configuração está em `scripts/branch-protection.sh`:
Fluxo: `develop` é a branch padrão do repositório. Branches de trabalho `<tipo>/issue-<N>-<slug>` (`tipo` ∈ feat, fix, docs, test, build, ci, chore) abrem PR para `develop`; releases sobem de `develop` para `main` por PR. `develop` e `main` exigem o check `build_and_test` (workflow "CI Map2Check Rust") e commits assinados; `main` exige também 1 review. A configuração está em `scripts/branch-protection.sh`:

```sh
scripts/branch-protection.sh check develop # compara com o GitHub (exit 0/1)
scripts/branch-protection.sh apply master # requer permissão de admin
scripts/branch-protection.sh apply main # requer permissão de admin
```

Se o job `build_and_test` for renomeado, atualize `CI_CHECK` no script na mesma mudança; caso contrário, todo PR fica bloqueado esperando um check que nunca chega.

Como o check também é exigido em `master`, um PR para `master` cujo head não passe no CI fica bloqueado. Hoje o CI de `master` está vermelho, então PRs só de documentação vindos de `develop` podem ficar presos; o admin pode fazer bypass (`enforce_admins=false`). `apply` trata o script como fonte da verdade: regras adicionadas pela interface do GitHub e ausentes do payload são removidas.
Como o check também é exigido em `main`, um PR para `main` cujo head não passe no CI fica bloqueado. Hoje o CI de `main` está vermelho, então PRs só de documentação vindos de `develop` podem ficar presos; o admin pode fazer bypass (`enforce_admins=false`). `apply` trata o script como fonte da verdade: regras adicionadas pela interface do GitHub e ausentes do payload são removidas.

## Arquitetura

Expand Down
2 changes: 1 addition & 1 deletion docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ that symbol in the program, linking the `libfuzzer` library fails with
the last release. `cargo test --all-features --test compat_docs` must
pass.
4. **Pull request.** Open a PR to `develop` and merge it once
`build_and_test` is green, then open a PR from `develop` to `master`
`build_and_test` is green, then open a PR from `develop` to `main`
(1 review required).
5. **Package.** On the merged commit, run:

Expand Down
4 changes: 2 additions & 2 deletions scripts/branch-protection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ REPO="${REPO:-hbgit/map2check-library}"
CI_CHECK="${CI_CHECK:-build_and_test}"
CI_APP_ID="${CI_APP_ID:-15368}"

usage() { echo "uso: $0 {payload|check|apply|encode} {develop|master}" >&2; exit 2; }
usage() { echo "uso: $0 {payload|check|apply|encode} {develop|main}" >&2; exit 2; }
need() { command -v "$1" >/dev/null || { echo "erro: '$1' não encontrado" >&2; exit 2; }; }

encode() { jq -rn --arg b "$1" '$b|@uri'; }
Expand All @@ -20,7 +20,7 @@ payload() {
local reviews
case "$1" in
develop) reviews='null' ;;
master) reviews='{"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":1}' ;;
main) reviews='{"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":1}' ;;
*) echo "erro: branch sem proteção definida: $1" >&2; exit 2 ;;
esac
jq -n --arg ctx "$CI_CHECK" --argjson app "$CI_APP_ID" --argjson reviews "$reviews" '{
Expand Down
23 changes: 12 additions & 11 deletions scripts/test-branch-protection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ t() { local name="$1"; shift; if "$@" >/dev/null 2>&1; then ok "$name"; else b
# Codificação de nomes com barra (Review Focus 2)
t "encode release/1.0" test "$("$BP" encode release/1.0)" = "release%2F1.0"
t "encode develop" test "$("$BP" encode develop)" = "develop"
t "encode master" test "$("$BP" encode master)" = "master"
t "encode main" test "$("$BP" encode main)" = "main"

# develop (integração): check obrigatório, sem review, sem force push/deleção
dv="$("$BP" payload develop 2>/dev/null || true)"
Expand All @@ -25,28 +25,29 @@ t "develop: sem force push" jq -e '.allow_force_pushes == false and .allo
t "develop: restrictions null" jq -e 'has("restrictions") and .restrictions == null' <<<"$dv"


# master: mesmo check e preserva 1 review (Review Focus 1)
ms="$("$BP" payload master 2>/dev/null || true)"
t "master: check build_and_test" jq -e '.required_status_checks.checks == [{"context":"build_and_test","app_id":15368}]' <<<"$ms"
t "master: 1 review preservado" jq -e '.required_pull_request_reviews.required_approving_review_count == 1' <<<"$ms"
t "master: enforce_admins false" jq -e '.enforce_admins == false' <<<"$ms"
# main: mesmo check e preserva 1 review (Review Focus 1)
ms="$("$BP" payload main 2>/dev/null || true)"
t "main: check build_and_test" jq -e '.required_status_checks.checks == [{"context":"build_and_test","app_id":15368}]' <<<"$ms"
t "main: 1 review preservado" jq -e '.required_pull_request_reviews.required_approving_review_count == 1' <<<"$ms"
t "main: enforce_admins false" jq -e '.enforce_admins == false' <<<"$ms"

# Branch desconhecida (inclui a antiga integração) e subcomando inválido falham (Review Focus 5)
t "feature/rust aposentada -> exit 2" bash -c '"$0" payload feature/rust; test $? -eq 2' "$BP"
t "master renomeada -> exit 2" bash -c '"$0" payload master; test $? -eq 2' "$BP"
t "branch desconhecida -> exit 2" bash -c '"$0" payload feat/x; test $? -eq 2' "$BP"
t "subcomando inválido -> exit 2" bash -c '"$0" frobnicate master; test $? -eq 2' "$BP"
t "subcomando inválido -> exit 2" bash -c '"$0" frobnicate main; test $? -eq 2' "$BP"

# O check obrigatório existe como job no CI (Review Focus 3)
t "CI.yml tem job build_and_test" grep -qE '^ build_and_test:' "$ROOT/.github/workflows/CI.yml"

# CI dispara em push e PR para as branches protegidas; senão o check nunca chega
for ev in push pull_request; do
t "CI.yml: $ev cobre develop e master" bash -c \
t "CI.yml: $ev cobre develop e main" bash -c \
'sed -n "/^ $1:/,/branches:/p" "$0" | grep "branches:" | grep -q "\"develop\"" &&
sed -n "/^ $1:/,/branches:/p" "$0" | grep "branches:" | grep -q "\"master\""' \
sed -n "/^ $1:/,/branches:/p" "$0" | grep "branches:" | grep -q "\"main\""' \
"$ROOT/.github/workflows/CI.yml" "$ev"
t "CI.yml: $ev não cita feature/rust" bash -c \
'! sed -n "/^ $1:/,/branches:/p" "$0" | grep -q "feature/rust"' \
t "CI.yml: $ev não cita feature/rust nem master" bash -c \
'! sed -n "/^ $1:/,/branches:/p" "$0" | grep -qE "feature/rust|\"master\""' \
"$ROOT/.github/workflows/CI.yml" "$ev"
done

Expand Down
Loading