The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Allow npm publishing from protected release branches (#28677)
Félix Malfait4a04f788f5e4
diff --git a/.github/workflows/publish-npm-packages.yaml b/.github/workflows/publish-npm-packages.yamlindex 1d0f827bb83..5c34e5eb84f 100644--- a/.github/workflows/publish-npm-packages.yaml+++ b/.github/workflows/publish-npm-packages.yaml@@ -31,16 +31,6 @@ jobs:with:persist-credentials: false- - name: Require release source to be on main- env:- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}- run: |- status=$(gh api "repos/twentyhq/twenty/compare/main...$GITHUB_SHA" --jq .status)- case "$status" in- identical|behind) ;;- *) echo '::error::Release source must already be in main history'; exit 1 ;;- esac-- name: Read infra publishing planenv:RELEASE_REF: ${{ github.ref }}@@ -64,6 +54,69 @@ jobs:' plan.json > /dev/nulljq -r '"PACKAGES=\(.packages)\nVERSION=\(.version)\nDIST_TAG=\(.dist_tag)\nDRY_RUN=\(.dry_run)\nSTAGE_ONLY=\(.stage_only // false)"' plan.json >> "$GITHUB_ENV"+ - name: Require reviewed release source+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ run: |+ fail() {+ echo "::error::$*" >&2+ exit 1+ }++ resolve_protected_release_branch() {+ local branch=$1 branch_data branch_sha rules rule+ branch_data=$(gh api "repos/twentyhq/twenty/branches/$branch") ||+ fail "Could not read release branch $branch"+ branch_sha=$(jq -r '.commit.sha' <<< "$branch_data")+ [[ "$branch_sha" =~ ^[a-f0-9]{40}$ ]] ||+ fail "Invalid head commit for release branch $branch"++ rules=$(gh api --paginate --slurp "repos/twentyhq/twenty/rules/branches/$branch?per_page=100" | jq 'add') ||+ fail "Could not read effective protection rules for $branch"+ jq -e '+ any(.[]; .type == "pull_request"+ and .parameters.required_approving_review_count >= 1)+ ' <<< "$rules" > /dev/null ||+ fail "$branch requires at least one PR approval"+ for rule in creation non_fast_forward deletion; do+ jq -e --arg rule "$rule" 'any(.[]; .type == $rule)' <<< "$rules" > /dev/null ||+ fail "$branch is missing its $rule protection"+ done+ echo "$branch_sha"+ }++ verify_release_source() {+ local source_sha=$1 version=$2 stage_only=$3+ local branch branch_sha status+ [[ "$source_sha" =~ ^[a-f0-9]{40}$ ]] || fail 'Expected a full release commit SHA'+ if ! [[ "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\. ]]; then+ fail 'Invalid release version in publishing plan'+ fi+ branch="v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"++ status=$(gh api "repos/twentyhq/twenty/compare/main...$source_sha" --jq .status) ||+ fail 'Could not check release ancestry against main'+ case "$status" in+ identical|behind) return ;;+ ahead|diverged) ;;+ *) fail 'GitHub returned an unknown main ancestry status' ;;+ esac++ if [[ "$stage_only" == true ]]; then+ fail 'Staging validation requires main history'+ fi+ branch_sha=$(resolve_protected_release_branch "$branch") ||+ fail "Could not validate release branch $branch"+ status=$(gh api "repos/twentyhq/twenty/compare/$branch_sha...$source_sha" --jq .status) ||+ fail "Could not check release ancestry against $branch"+ case "$status" in+ identical|behind) ;;+ *) fail "Release source must belong to main or protected $branch history" ;;+ esac+ }++ verify_release_source "$GITHUB_SHA" "$VERSION" "$STAGE_ONLY"+- name: Free disk spacerun: sudo rm -rf /usr/local/lib/android /usr/share/dotnet