|
| 1 | +name: Version Check |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + pull_request: |
| 7 | + branches: [main, develop] |
| 8 | + |
| 9 | +jobs: |
| 10 | + version-consistency: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + submodules: true |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: '3.12' |
| 24 | + - name: Install dependencies |
| 25 | + run: | |
| 26 | + sudo apt-get update |
| 27 | + sudo apt-get install -y jq |
| 28 | + npm install -g @openapitools/openapi-generator-cli @asyncapi/cli @asyncapi/modelina-cli |
| 29 | + pip install tomli |
| 30 | +
|
| 31 | + - name: Check specs submodule points to a tag |
| 32 | + run: | |
| 33 | + cd specs |
| 34 | + # Get the current commit hash |
| 35 | + CURRENT_COMMIT=$(git rev-parse HEAD) |
| 36 | + echo "Current specs commit: $CURRENT_COMMIT" |
| 37 | +
|
| 38 | + # Check if this commit is tagged |
| 39 | + TAGS=$(git tag --points-at $CURRENT_COMMIT) |
| 40 | + if [ -z "$TAGS" ]; then |
| 41 | + echo "❌ ERROR: specs submodule is not pointing to a tagged commit" |
| 42 | + echo "Current commit $CURRENT_COMMIT has no tags" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +
|
| 46 | + # Get the first tag (in case there are multiple) |
| 47 | + SPECS_TAG=$(echo "$TAGS" | head -n1) |
| 48 | + echo "Specs is pointing to tag: $SPECS_TAG" |
| 49 | + echo "SPECS_TAG=$SPECS_TAG" >> $GITHUB_ENV |
| 50 | +
|
| 51 | + - name: Extract version components |
| 52 | + run: | |
| 53 | + # Extract SDK_VERSION from _version.py |
| 54 | + SDK_VERSION=$(python -c " |
| 55 | + import sys |
| 56 | + sys.path.insert(0, 'sdk') |
| 57 | + from _version import SDK_VERSION |
| 58 | + print(SDK_VERSION) |
| 59 | + ") |
| 60 | + echo "SDK_VERSION: $SDK_VERSION" |
| 61 | + echo "SDK_VERSION=$SDK_VERSION" >> $GITHUB_ENV |
| 62 | +
|
| 63 | + # Extract version from pyproject.toml |
| 64 | + PYPROJECT_VERSION=$(python -c " |
| 65 | + import tomli |
| 66 | + with open('pyproject.toml', 'rb') as f: |
| 67 | + data = tomli.load(f) |
| 68 | + print(data['project']['version']) |
| 69 | + ") |
| 70 | + echo "PYPROJECT_VERSION: $PYPROJECT_VERSION" |
| 71 | + echo "PYPROJECT_VERSION=$PYPROJECT_VERSION" >> $GITHUB_ENV |
| 72 | +
|
| 73 | + # Extract first 3 components from specs tag (remove 'v' prefix if present) |
| 74 | + SPECS_TAG_CLEAN=$(echo "$SPECS_TAG" | sed 's/^v//') |
| 75 | + SPECS_VERSION_PREFIX=$(echo "$SPECS_TAG_CLEAN" | cut -d. -f1-3) |
| 76 | + echo "SPECS_VERSION_PREFIX: $SPECS_VERSION_PREFIX" |
| 77 | + echo "SPECS_VERSION_PREFIX=$SPECS_VERSION_PREFIX" >> $GITHUB_ENV |
| 78 | +
|
| 79 | + # Extract first 3 components from SDK_VERSION |
| 80 | + SDK_VERSION_PREFIX=$(echo "$SDK_VERSION" | cut -d. -f1-3) |
| 81 | + echo "SDK_VERSION_PREFIX: $SDK_VERSION_PREFIX" |
| 82 | + echo "SDK_VERSION_PREFIX=$SDK_VERSION_PREFIX" >> $GITHUB_ENV |
| 83 | +
|
| 84 | + - name: Check version consistency |
| 85 | + run: | |
| 86 | + echo "Checking version consistency..." |
| 87 | + echo "Specs tag: $SPECS_TAG" |
| 88 | + echo "Specs version prefix: $SPECS_VERSION_PREFIX" |
| 89 | + echo "SDK version: $SDK_VERSION" |
| 90 | + echo "SDK version prefix: $SDK_VERSION_PREFIX" |
| 91 | + echo "Pyproject version: $PYPROJECT_VERSION" |
| 92 | +
|
| 93 | + # Check 1: SDK_VERSION and pyproject.toml versions must match exactly |
| 94 | + if [ "$SDK_VERSION" != "$PYPROJECT_VERSION" ]; then |
| 95 | + echo "❌ ERROR: SDK_VERSION ($SDK_VERSION) does not match pyproject.toml version ($PYPROJECT_VERSION)" |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + echo "✅ SDK_VERSION and pyproject.toml versions match" |
| 99 | +
|
| 100 | + # Check 2: First 3 digits of SDK version must match specs tag |
| 101 | + if [ "$SDK_VERSION_PREFIX" != "$SPECS_VERSION_PREFIX" ]; then |
| 102 | + echo "❌ ERROR: First 3 digits of SDK_VERSION ($SDK_VERSION_PREFIX) do not match specs tag ($SPECS_VERSION_PREFIX)" |
| 103 | + echo "SDK version $SDK_VERSION should start with $SPECS_VERSION_PREFIX" |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | + echo "✅ SDK version prefix matches specs tag" |
| 107 | +
|
| 108 | + - name: Store initial git state |
| 109 | + run: | |
| 110 | + echo "Storing initial git state..." |
| 111 | + # Store the current state of tracked files |
| 112 | + git ls-files | sort > /tmp/files_before.txt |
| 113 | + git status --porcelain > /tmp/status_before.txt |
| 114 | +
|
| 115 | + # Create checksums for all tracked files (filter out directories) |
| 116 | + git ls-files -z | xargs -0 -I {} sh -c 'test -f "{}" && sha256sum "{}"' | sort > /tmp/checksums_before.txt |
| 117 | +
|
| 118 | + - name: Run API generation script |
| 119 | + run: | |
| 120 | + echo "Running API generation script..." |
| 121 | + chmod +x scripts/generate-api.sh |
| 122 | + scripts/generate-api.sh |
| 123 | +
|
| 124 | + - name: Run WS generation script |
| 125 | + run: | |
| 126 | + echo "Running WebSocket generation script..." |
| 127 | + chmod +x scripts/generate-ws.sh |
| 128 | + scripts/generate-ws.sh |
| 129 | +
|
| 130 | + - name: Check for changes after script execution |
| 131 | + run: | |
| 132 | + echo "Storing state after running scripts..." |
| 133 | + # Store the state after running scripts |
| 134 | + git ls-files | sort > /tmp/files_after.txt |
| 135 | + git status --porcelain > /tmp/status_after.txt |
| 136 | + git ls-files -z | xargs -0 -I {} sh -c 'test -f "{}" && sha256sum "{}"' | sort > /tmp/checksums_after.txt |
| 137 | +
|
| 138 | + echo "Checking for file changes..." |
| 139 | +
|
| 140 | + # Check if any tracked files were modified |
| 141 | + if ! cmp -s /tmp/status_before.txt /tmp/status_after.txt; then |
| 142 | + echo "❌ ERROR: Git status changed after running generation scripts" |
| 143 | + echo "Status before:" |
| 144 | + cat /tmp/status_before.txt |
| 145 | + echo "Status after:" |
| 146 | + cat /tmp/status_after.txt |
| 147 | + echo "" |
| 148 | + echo "Detailed changes:" |
| 149 | + git status |
| 150 | + git diff --name-only |
| 151 | + exit 1 |
| 152 | + fi |
| 153 | +
|
| 154 | + # Check if file list changed (new files created) |
| 155 | + if ! cmp -s /tmp/files_before.txt /tmp/files_after.txt; then |
| 156 | + echo "❌ ERROR: File list changed after running generation scripts" |
| 157 | + echo "New or removed files detected:" |
| 158 | + diff /tmp/files_before.txt /tmp/files_after.txt || true |
| 159 | + exit 1 |
| 160 | + fi |
| 161 | +
|
| 162 | + # Check if any file contents changed |
| 163 | + if ! cmp -s /tmp/checksums_before.txt /tmp/checksums_after.txt; then |
| 164 | + echo "❌ ERROR: File contents changed after running generation scripts" |
| 165 | + echo "Files with different checksums:" |
| 166 | + diff /tmp/checksums_before.txt /tmp/checksums_after.txt || true |
| 167 | + echo "" |
| 168 | + echo "Git diff:" |
| 169 | + git diff |
| 170 | + exit 1 |
| 171 | + fi |
| 172 | +
|
| 173 | + # Check for any untracked files that might have been created |
| 174 | + UNTRACKED_FILES=$(git ls-files --others --exclude-standard) |
| 175 | + if [ -n "$UNTRACKED_FILES" ]; then |
| 176 | + echo "❌ ERROR: Generation scripts created new untracked files:" |
| 177 | + echo "$UNTRACKED_FILES" |
| 178 | + exit 1 |
| 179 | + fi |
| 180 | +
|
| 181 | + echo "✅ No changes detected after running generation scripts" |
| 182 | +
|
| 183 | + - name: Summary |
| 184 | + run: | |
| 185 | + echo "🎉 All version consistency checks passed!" |
| 186 | + echo "✅ Specs submodule points to tag: $SPECS_TAG" |
| 187 | + echo "✅ SDK_VERSION and pyproject.toml versions match: $SDK_VERSION" |
| 188 | + echo "✅ First 3 digits match specs version: $SPECS_VERSION_PREFIX" |
| 189 | + echo "✅ Generation scripts produced no changes" |
0 commit comments