The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Require a label for upgrade commands in next version directories (#27319)
Félix Malfait8f44e9855661
diff --git a/.github/actions/upgrade-mutation-guard/action.yaml b/.github/actions/upgrade-mutation-guard/action.yamlindex 8198399803c..ea119d04188 100644--- a/.github/actions/upgrade-mutation-guard/action.yaml+++ b/.github/actions/upgrade-mutation-guard/action.yaml@@ -2,7 +2,8 @@ name: Upgrade Mutation Guarddescription: >Validates that added/modified upgrade commands stay in the current versiondirectory (frozen as well once its tag exists) and keep timestamps real and- append-only, diffed against a given base. Shared by the PR-level guard+ append-only, diffed against a given base. Previous and next version+ directories each have their own label bypass. Shared by the PR-level guard(base = PR base) and the merge-queue guard (base = merge candidate's base,i.e. the current tip of main).@@ -11,7 +12,11 @@ inputs:description: Commit to diff the working tree against.required: trueallow_previous_version_mutation:- description: Skip the version-directory check (PR label bypass).+ description: Allow changes to previous (or released) version directories (PR label bypass).+ required: false+ default: 'false'+ allow_next_version_mutation:+ description: Allow changes to next version directories (PR label bypass).required: falsedefault: 'false'@@ -31,11 +36,12 @@ runs:git fetch --no-tags --depth=1 origin "$BASE_SHA"- name: Check upgrade version commands are in current version only- if: ${{ inputs.allow_previous_version_mutation != 'true' }}shell: bashenv:BASE_SHA: ${{ inputs.base_sha }}COMMANDS_ROOT: packages/twenty-server/src/database/commands/upgrade-version-command+ ALLOW_PREVIOUS_VERSION_MUTATION: ${{ inputs.allow_previous_version_mutation }}+ ALLOW_NEXT_VERSION_MUTATION: ${{ inputs.allow_next_version_mutation }}run: |set -euo pipefailVERSION_CONSTANT_FILE="packages/twenty-server/src/engine/core-modules/upgrade/constants/twenty-current-version.constant.ts"@@ -55,6 +61,7 @@ runs:ADDED_FILES=$(echo "$DIFF" | awk '$1 == "A" { print $2 } $1 ~ /^[RC]/ { print $3 }')MODIFIED_FILES=$(echo "$DIFF" | awk '$1 == "M" { print $2 }')+ REMOVED_FILES=$(echo "$DIFF" | awk '$1 == "D" { print $2 } $1 ~ /^R/ { print $2 }')# Between the tag push and the version bump PR, TWENTY_CURRENT_VERSION# still names the released version. Once its tag exists, its directory@@ -63,7 +70,7 @@ runs:# lookup that cannot answer fails the check instead of passing it.IS_CURRENT_VERSION_RELEASED=false- if echo "$ADDED_FILES $MODIFIED_FILES" | grep -qF "upgrade-version-command/${CURRENT_DIR}/"; then+ if echo "$ADDED_FILES $MODIFIED_FILES $REMOVED_FILES" | grep -qF "upgrade-version-command/${CURRENT_DIR}/"; thenLS_REMOTE_STATUS=0git ls-remote --exit-code --tags origin "refs/tags/twenty/v${CURRENT_VERSION}" >/dev/null || LS_REMOTE_STATUS=$?@@ -82,47 +89,45 @@ runs:esacfi- ADDED_OFFENDERS=""- MODIFIED_OFFENDERS=""+ is_next_version_dir() {+ [ "$1" != "$CURRENT_DIR" ] && [ "$(printf '%s\n%s\n' "$1" "$CURRENT_DIR" | sort -V | tail -n 1)" = "$1" ]+ }++ PREVIOUS_VERSION_OFFENDERS=""+ NEXT_VERSION_OFFENDERS=""check_files() {- local category="$1"+ local change="$1"shiftfor file in "$@"; doVERSION_DIR=$(echo "$file" | sed -n 's|.*upgrade-version-command/\([0-9]*-[0-9]*\)/.*|\1|p')- if [ -n "$VERSION_DIR" ] && { [ "$VERSION_DIR" != "$CURRENT_DIR" ] || [ "$IS_CURRENT_VERSION_RELEASED" = "true" ]; }; then- if [ "$category" = "added" ]; then- ADDED_OFFENDERS="$ADDED_OFFENDERS\n - $file (version directory: $VERSION_DIR)"- else- MODIFIED_OFFENDERS="$MODIFIED_OFFENDERS\n - $file (version directory: $VERSION_DIR)"- fi+ if [ -z "$VERSION_DIR" ]; then+ continue+ fi++ if is_next_version_dir "$VERSION_DIR"; then+ NEXT_VERSION_OFFENDERS="$NEXT_VERSION_OFFENDERS\n - $file ($change, version directory: $VERSION_DIR)"+ elif [ "$VERSION_DIR" != "$CURRENT_DIR" ] || [ "$IS_CURRENT_VERSION_RELEASED" = "true" ]; then+ PREVIOUS_VERSION_OFFENDERS="$PREVIOUS_VERSION_OFFENDERS\n - $file ($change, version directory: $VERSION_DIR)"fidone}check_files "added" $ADDED_FILEScheck_files "modified" $MODIFIED_FILES+ check_files "removed" $REMOVED_FILES++ FAILED=false- if [ -n "$ADDED_OFFENDERS" ] || [ -n "$MODIFIED_OFFENDERS" ]; then+ if [ -n "$PREVIOUS_VERSION_OFFENDERS" ] && [ "$ALLOW_PREVIOUS_VERSION_MUTATION" != "true" ]; then+ FAILED=trueif [ "$IS_CURRENT_VERSION_RELEASED" = "true" ]; thenecho "This change touches upgrade command files of a released version: twenty/v${CURRENT_VERSION} is already tagged, so ${CURRENT_DIR} is frozen."else- echo "This change touches upgrade command files outside the current version directory ($CURRENT_DIR / $CURRENT_VERSION)."- fi-- if [ -n "$ADDED_OFFENDERS" ]; then- echo ""- echo "New files added to non-current version directories:"- echo -e "$ADDED_OFFENDERS"+ echo "This change touches upgrade command files of previous version directories (current: $CURRENT_DIR / $CURRENT_VERSION)."fi-- if [ -n "$MODIFIED_OFFENDERS" ]; then- echo ""- echo "Existing files modified in non-current version directories:"- echo -e "$MODIFIED_OFFENDERS"- fi-+ echo -e "$PREVIOUS_VERSION_OFFENDERS"echo ""echo "If this is intentional, add the label 'ci:allow-previous-version-upgrade-mutation' to the PR and re-run CI."if [ "$IS_CURRENT_VERSION_RELEASED" = "true" ]; then@@ -130,8 +135,22 @@ runs:elseecho "Otherwise, move your changes to the current version directory ($CURRENT_DIR)."fi+ echo ""+ fi++ if [ -n "$NEXT_VERSION_OFFENDERS" ] && [ "$ALLOW_NEXT_VERSION_MUTATION" != "true" ]; then+ FAILED=true+ echo "This change touches upgrade command files of next version directories (current: $CURRENT_DIR / $CURRENT_VERSION)."+ echo "These commands stay dormant until their version becomes current."+ echo -e "$NEXT_VERSION_OFFENDERS"+ echo ""+ echo "If this is intentional (e.g. a deferred drop), add the label 'ci:allow-next-version-upgrade-mutation' to the PR and re-run CI."+ echo "Otherwise, move your changes to the current version directory ($CURRENT_DIR)."+ echo ""+ fi- echo "::error::Upgrade commands were added or modified in non-current version directories."+ if [ "$FAILED" = "true" ]; then+ echo "::error::Upgrade commands were added, modified or removed outside the current version directory."exit 1fidiff --git a/.github/workflows/ci-merge-queue.yaml b/.github/workflows/ci-merge-queue.yamlindex 519544f0aa7..9620710a40d 100644--- a/.github/workflows/ci-merge-queue.yaml+++ b/.github/workflows/ci-merge-queue.yaml@@ -16,8 +16,8 @@ permissions:jobs:# merge_group carries no PR labels, so resolve them from the queued PR (its- # number is in the merge-queue ref) and pass the version-mutation bypass to the- # guard as an input, which skips only the version-directory step. The job+ # number is in the merge-queue ref) and pass the version-mutation bypasses to+ # the guard as inputs, which relax only the version-directory step. The job# always runs and reports a real success/failure, so the required check never# resolves to a skipped state and a label-lookup failure fails closed. The# timestamp / append-only check has no bypass and always runs: violating it@@ -30,7 +30,7 @@ jobs:uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1with:fetch-depth: 2- - name: Resolve version-mutation bypass label from the queued PR+ - name: Resolve version-mutation bypass labels from the queued PRid: labelsenv:GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}@@ -39,22 +39,29 @@ jobs:set -euo pipefailPR_NUMBER=$(echo "$HEAD_REF" | sed -n -E 's|.*/pr-([0-9]+)-[0-9a-f]+$|\1|p')- skip=false+ allow_previous=false+ allow_next=falseif [ -n "$PR_NUMBER" ]; thenLABELS=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json labels --jq '.labels[].name')echo "Queued PR #$PR_NUMBER labels:"echo "$LABELS"if echo "$LABELS" | grep -qxF 'ci:allow-previous-version-upgrade-mutation'; then- skip=true+ allow_previous=true+ fi++ if echo "$LABELS" | grep -qxF 'ci:allow-next-version-upgrade-mutation'; then+ allow_next=truefielseecho "Could not parse a PR number from '$HEAD_REF'; enforcing strictly."fi- echo "skip=$skip" >> "$GITHUB_OUTPUT"+ echo "allow_previous=$allow_previous" >> "$GITHUB_OUTPUT"+ echo "allow_next=$allow_next" >> "$GITHUB_OUTPUT"- name: Validate upgrade command mutations against mainuses: ./.github/actions/upgrade-mutation-guardwith:base_sha: ${{ github.event.merge_group.base_sha }}- allow_previous_version_mutation: ${{ steps.labels.outputs.skip }}+ allow_previous_version_mutation: ${{ steps.labels.outputs.allow_previous }}+ allow_next_version_mutation: ${{ steps.labels.outputs.allow_next }}diff --git a/.github/workflows/ci-server.yaml b/.github/workflows/ci-server.yamlindex 3615d1f6ce6..a2bb48b7cd4 100644--- a/.github/workflows/ci-server.yaml+++ b/.github/workflows/ci-server.yaml@@ -92,7 +92,7 @@ jobs:tag: scope:backendtasks: lingui:compile- server-previous-version-upgrade-mutation-guard:+ server-upgrade-mutation-guard:if: github.event_name != 'merge_group'timeout-minutes: 5runs-on: ubuntu-latest@@ -119,6 +119,7 @@ jobs:with:base_sha: ${{ steps.merged-base.outputs.sha }}allow_previous_version_mutation: ${{ contains(github.event.pull_request.labels.*.name, 'ci:allow-previous-version-upgrade-mutation') }}+ allow_next_version_mutation: ${{ contains(github.event.pull_request.labels.*.name, 'ci:allow-next-version-upgrade-mutation') }}server-validation:needs: server-build@@ -405,7 +406,7 @@ jobs:changed-files-check,server-build,server-lint-typecheck,- server-previous-version-upgrade-mutation-guard,+ server-upgrade-mutation-guard,server-validation,server-test,server-integration-test,diff --git a/packages/twenty-server/docs/UPGRADE_COMMANDS.md b/packages/twenty-server/docs/UPGRADE_COMMANDS.mdindex 9914396c910..5acea2a7176 100644--- a/packages/twenty-server/docs/UPGRADE_COMMANDS.md+++ b/packages/twenty-server/docs/UPGRADE_COMMANDS.md@@ -212,6 +212,8 @@ npx nx run twenty-server:database:migrate:generate --name <name> --type fast --vIt registers and boots (versions are validated against `TWENTY_ALL_VERSIONS`) but stays **dormant** — the sequence only runs `TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS` (previous + current). It activates automatically when `nx version:bump` promotes the version to current.+CI rejects changes to next version directories by default, so add the `ci:allow-next-version-upgrade-mutation` label to the PR to confirm the command is meant for a future version.+**Caveat:** `@WasRemovedInUpgrade` / `@WasIntroducedInUpgrade` are validated against the active sequence, so a decorator pointing at a still-dormant next-version command fails boot with `unknown-step-name`. For a deferred drop, keep the entity's `WasRemovedInUpgrade<T>` type wrapper now and add the decorator only once the version is current.See the CI workflows for how upgrade commands are exercised in continuous integration.