|
78 | 78 | tag: scope:backend |
79 | 79 | tasks: lint,typecheck |
80 | 80 |
|
| 81 | + server-previous-version-upgrade-mutation-guard: |
| 82 | + timeout-minutes: 5 |
| 83 | + runs-on: ubuntu-latest |
| 84 | + steps: |
| 85 | + - name: Fetch custom Github Actions and base branch history |
| 86 | + uses: actions/checkout@v4 |
| 87 | + with: |
| 88 | + fetch-depth: 10 |
| 89 | + - name: Get changed upgrade-version-command files |
| 90 | + id: changed-files |
| 91 | + uses: tj-actions/changed-files@v45 |
| 92 | + with: |
| 93 | + files: | |
| 94 | + packages/twenty-server/src/database/commands/upgrade-version-command/** |
| 95 | + - name: Check upgrade version commands are in current version only |
| 96 | + if: > |
| 97 | + steps.changed-files.outputs.any_changed == 'true' && |
| 98 | + !contains(github.event.pull_request.labels.*.name, 'ci:allow-previous-version-upgrade-mutation') |
| 99 | + run: | |
| 100 | + VERSION_CONSTANT_FILE="packages/twenty-server/src/engine/core-modules/upgrade/constants/twenty-current-version.constant.ts" |
| 101 | +
|
| 102 | + CURRENT_VERSION=$(sed -n "s/.*TWENTY_CURRENT_VERSION = '\([0-9.]*\)'.*/\1/p" "$VERSION_CONSTANT_FILE") |
| 103 | +
|
| 104 | + if [ -z "$CURRENT_VERSION" ]; then |
| 105 | + echo "::error::Could not extract TWENTY_CURRENT_VERSION from $VERSION_CONSTANT_FILE" |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | +
|
| 109 | + CURRENT_DIR=$(echo "$CURRENT_VERSION" | sed -E 's/^([0-9]+)\.([0-9]+)\..*/\1-\2/') |
| 110 | +
|
| 111 | + echo "Current version: $CURRENT_VERSION (directory: $CURRENT_DIR)" |
| 112 | +
|
| 113 | + ADDED_OFFENDERS="" |
| 114 | + MODIFIED_OFFENDERS="" |
| 115 | +
|
| 116 | + check_files() { |
| 117 | + local category="$1" |
| 118 | + shift |
| 119 | + for file in "$@"; do |
| 120 | + VERSION_DIR=$(echo "$file" | sed -n 's|.*upgrade-version-command/\([0-9]*-[0-9]*\)/.*|\1|p') |
| 121 | +
|
| 122 | + if [ -n "$VERSION_DIR" ] && [ "$VERSION_DIR" != "$CURRENT_DIR" ]; then |
| 123 | + if [ "$category" = "added" ]; then |
| 124 | + ADDED_OFFENDERS="$ADDED_OFFENDERS\n - $file (version directory: $VERSION_DIR)" |
| 125 | + else |
| 126 | + MODIFIED_OFFENDERS="$MODIFIED_OFFENDERS\n - $file (version directory: $VERSION_DIR)" |
| 127 | + fi |
| 128 | + fi |
| 129 | + done |
| 130 | + } |
| 131 | +
|
| 132 | + check_files "added" ${{ steps.changed-files.outputs.added_files }} |
| 133 | + check_files "modified" ${{ steps.changed-files.outputs.modified_files }} |
| 134 | +
|
| 135 | + if [ -n "$ADDED_OFFENDERS" ] || [ -n "$MODIFIED_OFFENDERS" ]; then |
| 136 | + echo "This PR touches upgrade command files outside the current version directory ($CURRENT_DIR / $CURRENT_VERSION)." |
| 137 | +
|
| 138 | + if [ -n "$ADDED_OFFENDERS" ]; then |
| 139 | + echo "" |
| 140 | + echo "New files added to non-current version directories:" |
| 141 | + echo -e "$ADDED_OFFENDERS" |
| 142 | + fi |
| 143 | +
|
| 144 | + if [ -n "$MODIFIED_OFFENDERS" ]; then |
| 145 | + echo "" |
| 146 | + echo "Existing files modified in non-current version directories:" |
| 147 | + echo -e "$MODIFIED_OFFENDERS" |
| 148 | + fi |
| 149 | +
|
| 150 | + echo "" |
| 151 | + echo "If this is intentional, add the label 'ci:allow-previous-version-upgrade-mutation' to this PR and re-run CI." |
| 152 | + echo "Otherwise, please move your changes to the current version directory ($CURRENT_DIR)." |
| 153 | +
|
| 154 | + echo "::error::Upgrade commands were added or modified in non-current version directories." |
| 155 | + exit 1 |
| 156 | + fi |
| 157 | +
|
81 | 158 | server-validation: |
82 | 159 | needs: server-build |
83 | 160 | timeout-minutes: 30 |
@@ -311,6 +388,7 @@ jobs: |
311 | 388 | changed-files-check, |
312 | 389 | server-build, |
313 | 390 | server-lint-typecheck, |
| 391 | + server-previous-version-upgrade-mutation-guard, |
314 | 392 | server-validation, |
315 | 393 | server-test, |
316 | 394 | server-integration-test, |
|
0 commit comments