Skip to content

Commit 3d0c09e

Browse files
committed
fix: implement automated version management and stabilize CI build process
This update introduces a unified versioning script and refactors the CI/CD workflows to ensure stable builds and consistent versions across core and SDK packages. It also adds a release management helper and local validation scripts.
1 parent 22bd012 commit 3d0c09e

File tree

9 files changed

+252
-28
lines changed

9 files changed

+252
-28
lines changed

.github/workflows/publish.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ jobs:
1919
with:
2020
node-version: '20'
2121
registry-url: 'https://registry.npmjs.org'
22+
23+
- name: Extract version from tag
24+
id: get_version
25+
run: |
26+
VERSION=${GITHUB_REF#refs/tags/v}
27+
echo "version=$VERSION" >> $GITHUB_OUTPUT
28+
echo "Publishing version: $VERSION"
29+
30+
- name: Update package versions
31+
run: node update-versions.js ${{ steps.get_version.outputs.version }}
2232

2333
- name: Install dependencies
2434
run: npm ci
@@ -63,6 +73,16 @@ jobs:
6373
- uses: actions/setup-python@v5
6474
with:
6575
python-version: '3.x'
76+
77+
- name: Extract version from tag
78+
id: get_version
79+
run: |
80+
VERSION=${GITHUB_REF#refs/tags/v}
81+
echo "version=$VERSION" >> $GITHUB_OUTPUT
82+
echo "Publishing version: $VERSION"
83+
84+
- name: Update package versions
85+
run: node update-versions.js ${{ steps.get_version.outputs.version }}
6686

6787
- name: Generate SDKs
6888
run: |

.github/workflows/test-publish.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
- name: Install dependencies (Root)
2424
run: npm ci
2525

26+
- name: Simulate Version Update (Dry Run)
27+
run: node update-versions.js 0.5.0-dryrun
28+
2629
- name: Generate SDKs
2730
run: npm run generate:sdk:all --workspace=pmxt-core
2831

@@ -67,9 +70,10 @@ jobs:
6770
with:
6871
node-version: '20'
6972

70-
- name: Install Node dependencies & Start Server
73+
- name: Install Node dependencies & Start Server & Simulate Version
7174
run: |
7275
npm ci
76+
node update-versions.js 0.5.0-dryrun
7377
npm run generate:sdk:all --workspace=pmxt-core
7478
npm run build --workspace=pmxt-core
7579
npm run server --workspace=pmxt-core &

core/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pmxt-core",
3-
"version": "0.4.4",
3+
"version": "0.5.0",
44
"description": "pmxt is a unified prediction market data API. The ccxt for prediction markets.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -24,8 +24,8 @@
2424
"test": "jest -c jest.config.js",
2525
"server": "tsx watch src/server/index.ts",
2626
"server:prod": "node dist/server/index.js",
27-
"generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=0.4.4,library=urllib3",
28-
"generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=0.0.2,supportsES6=true,typescriptThreePlus=true",
27+
"generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=0.5.0,library=urllib3",
28+
"generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=0.5.0,supportsES6=true,typescriptThreePlus=true",
2929
"generate:sdk:all": "npm run generate:sdk:python && npm run generate:sdk:typescript"
3030
},
3131
"keywords": [],
@@ -52,4 +52,4 @@
5252
"ts-jest": "^29.4.6",
5353
"typescript": "^5.9.3"
5454
}
55-
}
55+
}

release.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
# Release script for PMXT
4+
# Usage: ./release.sh <version>
5+
# Example: ./release.sh 0.5.0
6+
7+
set -e
8+
9+
if [ -z "$1" ]; then
10+
echo "[ERROR] Error: Version number required"
11+
echo "Usage: ./release.sh <version>"
12+
echo "Example: ./release.sh 0.5.0"
13+
exit 1
14+
fi
15+
16+
VERSION=$1
17+
18+
# Validate version format (basic semver check)
19+
if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
20+
echo "[ERROR] Error: Invalid version format. Use semantic versioning (e.g., 0.5.0)"
21+
exit 1
22+
fi
23+
24+
echo "[RELEASE] Preparing release v$VERSION"
25+
echo ""
26+
27+
# Check if we're on the right branch
28+
CURRENT_BRANCH=$(git branch --show-current)
29+
echo "[INFO] Current branch: $CURRENT_BRANCH"
30+
31+
# Check for uncommitted changes
32+
if ! git diff-index --quiet HEAD --; then
33+
echo "[WARNING] Warning: You have uncommitted changes"
34+
read -p "Continue anyway? (y/n) " -n 1 -r
35+
echo
36+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
37+
exit 1
38+
fi
39+
fi
40+
41+
# Check if tag already exists
42+
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
43+
echo "[ERROR] Error: Tag v$VERSION already exists"
44+
exit 1
45+
fi
46+
47+
echo ""
48+
echo "[INFO] This will:"
49+
echo " 1. Create and push tag v$VERSION"
50+
echo " 2. Trigger GitHub Actions to:"
51+
echo " - Auto-update all package versions to $VERSION"
52+
echo " - Build and test all packages"
53+
echo " - Publish pmxt-core@$VERSION to npm"
54+
echo " - Publish pmxtjs@$VERSION to npm"
55+
echo " - Publish pmxt@$VERSION to PyPI"
56+
echo ""
57+
58+
read -p "Proceed with release? (y/n) " -n 1 -r
59+
echo
60+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
61+
echo "[CANCEL] Release cancelled"
62+
exit 1
63+
fi
64+
65+
echo ""
66+
echo "[TAG] Creating tag v$VERSION..."
67+
git tag -a "v$VERSION" -m "Release v$VERSION"
68+
69+
echo "[PUSH] Pushing tag to GitHub..."
70+
git push origin "v$VERSION"
71+
72+
echo ""
73+
echo "[SUCCESS] Tag v$VERSION pushed successfully!"
74+
echo ""
75+
echo "[LINK] Monitor the release at:"
76+
echo " https://github.com/qoery-com/pmxt/actions"
77+
echo ""
78+
echo "[INFO] Once published, packages will be available at:"
79+
echo " - npm: https://www.npmjs.com/package/pmxt-core"
80+
echo " - npm: https://www.npmjs.com/package/pmxtjs"
81+
echo " - PyPI: https://pypi.org/project/pmxt/"

sdks/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pmxt"
7-
version = "0.4.4"
7+
version = "0.5.0"
88
description = "Unified prediction market data API - The ccxt for prediction markets"
99
readme = "README.md"
1010
requires-python = ">=3.8"

sdks/typescript/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pmxtjs",
3-
"version": "0.0.2",
3+
"version": "0.5.0",
44
"description": "Unified prediction market data API - The ccxt for prediction markets",
55
"author": "PMXT Contributors",
66
"repository": {
@@ -49,4 +49,4 @@
4949
"ts-jest": "^29.4.6",
5050
"typescript": "^5.0.0"
5151
}
52-
}
52+
}

test-publish-local.sh

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
set -e # Exit on error
77

8-
echo "🧪 Starting local publish test..."
8+
echo "[TEST] Starting local publish test..."
99
echo ""
1010

1111
# Colors for output
@@ -23,25 +23,25 @@ rm -rf sdks/python/generated
2323
rm -rf sdks/python/dist
2424
rm -rf sdks/python/build
2525
rm -rf sdks/python/*.egg-info
26-
echo -e "${GREEN} Clean complete${NC}"
26+
echo -e "${GREEN}[OK] Clean complete${NC}"
2727
echo ""
2828

2929
# Step 2: Install dependencies
3030
echo -e "${BLUE}Step 2: Installing dependencies...${NC}"
3131
npm ci
32-
echo -e "${GREEN} Dependencies installed${NC}"
32+
echo -e "${GREEN}[OK] Dependencies installed${NC}"
3333
echo ""
3434

3535
# Step 3: Generate SDKs
3636
echo -e "${BLUE}Step 3: Generating SDKs...${NC}"
3737
npm run generate:sdk:all --workspace=pmxt-core
38-
echo -e "${GREEN} SDKs generated${NC}"
38+
echo -e "${GREEN}[OK] SDKs generated${NC}"
3939
echo ""
4040

4141
# Step 4: Build all workspaces
4242
echo -e "${BLUE}Step 4: Building all workspaces...${NC}"
4343
npm run build --workspaces
44-
echo -e "${GREEN} All workspaces built${NC}"
44+
echo -e "${GREEN}[OK] All workspaces built${NC}"
4545
echo ""
4646

4747
# Step 5: Start server and run tests
@@ -57,31 +57,31 @@ until curl -s http://localhost:3847/health > /dev/null 2>&1; do
5757
sleep 1
5858
ELAPSED=$((ELAPSED + 1))
5959
if [ $ELAPSED -ge $TIMEOUT ]; then
60-
echo -e "${RED} Server failed to start within ${TIMEOUT} seconds${NC}"
60+
echo -e "${RED}[FAIL] Server failed to start within ${TIMEOUT} seconds${NC}"
6161
kill $SERVER_PID 2>/dev/null || true
6262
exit 1
6363
fi
6464
done
65-
echo -e "${GREEN} Server is ready!${NC}"
65+
echo -e "${GREEN}[OK] Server is ready!${NC}"
6666
echo ""
6767

6868
# Step 6: Run tests
6969
echo -e "${BLUE}Step 6: Running tests...${NC}"
7070
npm test --workspaces || {
71-
echo -e "${RED} Tests failed${NC}"
71+
echo -e "${RED}[FAIL] Tests failed${NC}"
7272
kill $SERVER_PID 2>/dev/null || true
7373
exit 1
7474
}
75-
echo -e "${GREEN} All tests passed${NC}"
75+
echo -e "${GREEN}[OK] All tests passed${NC}"
7676
echo ""
7777

7878
# Step 7: Dry run publish
7979
echo -e "${BLUE}Step 7: Dry run publish (pmxt-core)...${NC}"
8080
npm publish --workspace=pmxt-core --dry-run 2>&1 | tee /tmp/pmxt-core-publish.log || {
8181
if grep -q "cannot publish over the previously published versions" /tmp/pmxt-core-publish.log; then
82-
echo -e "${GREEN} pmxt-core package is valid (version already published - expected)${NC}"
82+
echo -e "${GREEN}[OK] pmxt-core package is valid (version already published - expected)${NC}"
8383
else
84-
echo -e "${RED} Dry run publish failed for pmxt-core${NC}"
84+
echo -e "${RED}[FAIL] Dry run publish failed for pmxt-core${NC}"
8585
kill $SERVER_PID 2>/dev/null || true
8686
exit 1
8787
fi
@@ -91,9 +91,9 @@ echo ""
9191
echo -e "${BLUE}Step 8: Dry run publish (pmxtjs)...${NC}"
9292
npm publish --workspace=pmxtjs --dry-run 2>&1 | tee /tmp/pmxtjs-publish.log || {
9393
if grep -q "cannot publish over the previously published versions" /tmp/pmxtjs-publish.log; then
94-
echo -e "${GREEN} pmxtjs package is valid (version already published - expected)${NC}"
94+
echo -e "${GREEN}[OK] pmxtjs package is valid (version already published - expected)${NC}"
9595
else
96-
echo -e "${RED} Dry run publish failed for pmxtjs${NC}"
96+
echo -e "${RED}[FAIL] Dry run publish failed for pmxtjs${NC}"
9797
kill $SERVER_PID 2>/dev/null || true
9898
exit 1
9999
fi
@@ -111,31 +111,31 @@ pip install . > /dev/null 2>&1
111111

112112
# Run Python tests
113113
pytest || {
114-
echo -e "${RED} Python tests failed${NC}"
114+
echo -e "${RED}[FAIL] Python tests failed${NC}"
115115
kill $SERVER_PID 2>/dev/null || true
116116
exit 1
117117
}
118-
echo -e "${GREEN} Python tests passed${NC}"
118+
echo -e "${GREEN}[OK] Python tests passed${NC}"
119119
echo ""
120120

121121
# Build Python package
122122
echo -e "${BLUE}Step 10: Building Python package...${NC}"
123123
python3 -m build || {
124-
echo -e "${RED} Python build failed${NC}"
124+
echo -e "${RED}[FAIL] Python build failed${NC}"
125125
kill $SERVER_PID 2>/dev/null || true
126126
exit 1
127127
}
128-
echo -e "${GREEN} Python package built${NC}"
128+
echo -e "${GREEN}[OK] Python package built${NC}"
129129
echo ""
130130

131131
# Verify package metadata
132132
echo -e "${BLUE}Step 11: Verifying Python package metadata...${NC}"
133133
twine check dist/* || {
134-
echo -e "${RED} Python package metadata verification failed${NC}"
134+
echo -e "${RED}[FAIL] Python package metadata verification failed${NC}"
135135
kill $SERVER_PID 2>/dev/null || true
136136
exit 1
137137
}
138-
echo -e "${GREEN} Python package metadata verified${NC}"
138+
echo -e "${GREEN}[OK] Python package metadata verified${NC}"
139139
echo ""
140140

141141
cd ../..
@@ -145,7 +145,7 @@ kill $SERVER_PID 2>/dev/null || true
145145

146146
echo ""
147147
echo -e "${GREEN}========================================${NC}"
148-
echo -e "${GREEN} All tests passed successfully!${NC}"
148+
echo -e "${GREEN}[OK] All tests passed successfully!${NC}"
149149
echo -e "${GREEN}========================================${NC}"
150150
echo ""
151151
echo "You can now safely push to GitHub."

test-version-update.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
# Test script to verify version update logic works correctly
4+
# This simulates what the GitHub Actions workflow will do
5+
6+
set -e
7+
8+
echo "[TEST] Testing version update logic..."
9+
echo ""
10+
11+
# Simulate a version
12+
TEST_VERSION="0.5.0"
13+
echo "Test version: $TEST_VERSION"
14+
echo ""
15+
16+
# Create temporary copies of package files
17+
cp core/package.json /tmp/test-core-package.json
18+
cp sdks/typescript/package.json /tmp/test-ts-package.json
19+
cp sdks/python/pyproject.toml /tmp/test-pyproject.toml
20+
21+
echo "[DEBUG] Testing sed commands..."
22+
echo ""
23+
24+
# Test core package.json update
25+
sed -i.bak "s/\"version\": \".*\"/\"version\": \"$TEST_VERSION\"/" /tmp/test-core-package.json
26+
CORE_VERSION=$(grep '"version":' /tmp/test-core-package.json | head -1 | sed 's/.*"version": "\(.*\)".*/\1/')
27+
echo "[OK] core/package.json version: $CORE_VERSION"
28+
29+
# Test TypeScript SDK package.json update
30+
sed -i.bak "s/\"version\": \".*\"/\"version\": \"$TEST_VERSION\"/" /tmp/test-ts-package.json
31+
TS_VERSION=$(grep '"version":' /tmp/test-ts-package.json | head -1 | sed 's/.*"version": "\(.*\)".*/\1/')
32+
echo "[OK] sdks/typescript/package.json version: $TS_VERSION"
33+
34+
# Test Python pyproject.toml update
35+
sed -i.bak "s/^version = \".*\"/version = \"$TEST_VERSION\"/" /tmp/test-pyproject.toml
36+
PY_VERSION=$(grep '^version = ' /tmp/test-pyproject.toml | sed 's/version = "\(.*\)"/\1/')
37+
echo "[OK] sdks/python/pyproject.toml version: $PY_VERSION"
38+
39+
# Test generator command updates
40+
sed -i.bak "s/packageVersion=[0-9.]\+/packageVersion=$TEST_VERSION/" /tmp/test-core-package.json
41+
GENERATOR_VERSION=$(grep 'packageVersion=' /tmp/test-core-package.json | sed 's/.*packageVersion=\([0-9.]\+\).*/\1/')
42+
echo "[OK] Python generator packageVersion: $GENERATOR_VERSION"
43+
44+
sed -i.bak "s/npmVersion=[0-9.]\+/npmVersion=$TEST_VERSION/" /tmp/test-core-package.json
45+
NPM_VERSION=$(grep 'npmVersion=' /tmp/test-core-package.json | sed 's/.*npmVersion=\([0-9.]\+\).*/\1/')
46+
echo "[OK] TypeScript generator npmVersion: $NPM_VERSION"
47+
48+
echo ""
49+
50+
# Verify all versions match
51+
if [ "$CORE_VERSION" = "$TEST_VERSION" ] && \
52+
[ "$TS_VERSION" = "$TEST_VERSION" ] && \
53+
[ "$PY_VERSION" = "$TEST_VERSION" ] && \
54+
[ "$GENERATOR_VERSION" = "$TEST_VERSION" ] && \
55+
[ "$NPM_VERSION" = "$TEST_VERSION" ]; then
56+
echo "[SUCCESS] All version updates successful!"
57+
echo ""
58+
echo "The workflow will correctly update versions from git tags."
59+
else
60+
echo "[ERROR] Version mismatch detected!"
61+
echo "Expected: $TEST_VERSION"
62+
echo "Core: $CORE_VERSION"
63+
echo "TS: $TS_VERSION"
64+
echo "Python: $PY_VERSION"
65+
echo "Generator (Python): $GENERATOR_VERSION"
66+
echo "Generator (TS): $NPM_VERSION"
67+
exit 1
68+
fi
69+
70+
# Cleanup
71+
rm /tmp/test-*.json /tmp/test-*.toml /tmp/test-*.bak 2>/dev/null || true

0 commit comments

Comments
 (0)