Skip to content

Commit e845cef

Browse files
committed
Add API model publishing and validation workflows
1 parent 84a3da8 commit e845cef

File tree

172 files changed

+15233
-524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+15233
-524
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Publish API Models
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- 'api-models/**'
8+
- 'schemas/**'
9+
- '.github/workflows/publish-api-models.yml'
10+
workflow_dispatch:
11+
inputs:
12+
version:
13+
description: 'API specification version to publish (e.g., v1, v2)'
14+
required: true
15+
default: 'v1'
16+
publish_java:
17+
description: 'Publish Java models'
18+
required: false
19+
default: true
20+
type: boolean
21+
publish_typescript:
22+
description: 'Publish TypeScript models'
23+
required: false
24+
default: true
25+
type: boolean
26+
27+
jobs:
28+
publish-models:
29+
runs-on: ubuntu-latest
30+
permissions:
31+
contents: read
32+
packages: write
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
38+
- name: Set up JDK 21
39+
uses: actions/setup-java@v4
40+
with:
41+
java-version: '21'
42+
distribution: 'temurin'
43+
44+
- name: Set up Node.js
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version: '20'
48+
registry-url: 'https://npm.pkg.github.com'
49+
scope: '@trustification'
50+
51+
- name: Cache Maven packages
52+
uses: actions/cache@v4
53+
with:
54+
path: ~/.m2
55+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
56+
restore-keys: ${{ runner.os }}-m2
57+
58+
- name: Cache npm dependencies
59+
uses: actions/cache@v4
60+
with:
61+
path: ~/.npm
62+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
63+
restore-keys: |
64+
${{ runner.os }}-node-
65+
66+
- name: Get API version
67+
id: api-version
68+
run: |
69+
if [ "${{ github.event.inputs.version }}" != "" ]; then
70+
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
71+
else
72+
echo "version=v1" >> $GITHUB_OUTPUT
73+
fi
74+
75+
- name: Build and Publish Java Models
76+
if: ${{ github.event.inputs.publish_java != 'false' }}
77+
run: |
78+
echo "📦 Building and publishing Java models..."
79+
cd api-models/java
80+
mvn clean generate-sources compile -Dapi.version=${{ steps.api-version.outputs.version }}
81+
mvn deploy -Dapi.version=${{ steps.api-version.outputs.version }} \
82+
-Dmaven.repo.url=https://maven.pkg.github.com/${{ github.repository }} \
83+
-Dmaven.repo.username=${{ github.actor }} \
84+
-Dmaven.repo.password=${{ secrets.GITHUB_TOKEN }} \
85+
-Dmaven.repo.id=github
86+
echo "✅ Java models published successfully"
87+
88+
- name: Build and Publish TypeScript Models
89+
if: ${{ github.event.inputs.publish_typescript != 'false' }}
90+
run: |
91+
echo "📦 Building and publishing TypeScript models..."
92+
cd api-models/typescript
93+
npm ci
94+
npm run generate -- --version ${{ steps.api-version.outputs.version }}
95+
npm run build
96+
npm publish
97+
echo "✅ TypeScript models published successfully"
98+
env:
99+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
101+
- name: Summary
102+
run: |
103+
echo "🎉 API Models publishing completed!"
104+
echo "Version: ${{ steps.api-version.outputs.version }}"
105+
echo "Java models: ${{ github.event.inputs.publish_java != 'false' && '✅ Published' || '⏭️ Skipped' }}"
106+
echo "TypeScript models: ${{ github.event.inputs.publish_typescript != 'false' && '✅ Published' || '⏭️ Skipped' }}"
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: Validate API Models
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: 'API specification version to validate (e.g., v1, v2)'
12+
required: true
13+
default: 'v1'
14+
15+
jobs:
16+
validate:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Set up JDK 21
26+
uses: actions/setup-java@v4
27+
with:
28+
java-version: '21'
29+
distribution: 'temurin'
30+
31+
- name: Set up Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: '20'
35+
36+
- name: Cache Maven packages
37+
uses: actions/cache@v4
38+
with:
39+
path: ~/.m2
40+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
41+
restore-keys: ${{ runner.os }}-m2
42+
43+
- name: Cache npm dependencies
44+
uses: actions/cache@v4
45+
with:
46+
path: ~/.npm
47+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
48+
restore-keys: |
49+
${{ runner.os }}-node-
50+
51+
- name: Get API version
52+
id: api-version
53+
run: |
54+
if [ "${{ github.event.inputs.version }}" != "" ]; then
55+
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
56+
else
57+
echo "version=v1" >> $GITHUB_OUTPUT
58+
fi
59+
60+
- name: Check Git repository state
61+
run: |
62+
echo "🔍 Checking Git repository state..."
63+
64+
# Check if repository is clean
65+
if [ -n "$(git status --porcelain)" ]; then
66+
echo "⚠️ Warning: Repository has uncommitted changes:"
67+
git status --porcelain
68+
echo ""
69+
echo "This might affect the validation results."
70+
else
71+
echo "✅ Repository is clean"
72+
fi
73+
74+
# Show current branch and commit
75+
echo "📋 Current branch: $(git branch --show-current)"
76+
echo "📋 Current commit: $(git rev-parse --short HEAD)"
77+
echo "📋 Commit message: $(git log -1 --pretty=format:'%s')"
78+
79+
- name: Test Java model generation
80+
run: |
81+
echo "🔨 Testing Java model generation..."
82+
cd api-models/java
83+
mvn clean generate-sources compile -Dapi.version=${{ steps.api-version.outputs.version }} -q
84+
echo "✅ Java models generated successfully"
85+
86+
- name: Test TypeScript model generation
87+
run: |
88+
echo "🔨 Testing TypeScript model generation..."
89+
cd api-models/typescript
90+
npm ci --silent
91+
npm run generate -- --version ${{ steps.api-version.outputs.version }}
92+
npm run build --silent
93+
echo "✅ TypeScript models generated successfully"
94+
95+
- name: Validate tools configuration
96+
run: |
97+
echo "🔍 Validating tools configuration..."
98+
cd tools
99+
npm ci --silent
100+
npm run build --silent
101+
node dist/index.js validate
102+
echo "✅ Tools configuration validated"
103+
104+
- name: Test make generate (no unintended file changes)
105+
run: |
106+
echo "🔍 Testing make generate doesn't create/modify unintended files..."
107+
108+
# Store current Git state
109+
echo "📸 Storing current Git state..."
110+
git status --porcelain > /tmp/before_generate.txt
111+
git diff --name-only > /tmp/before_generate_diff.txt
112+
113+
# Clean generated files to start fresh
114+
echo "🧹 Cleaning previously generated files..."
115+
rm -rf api-models/typescript/dist api-models/typescript/src/generated
116+
rm -rf api-models/java/target
117+
118+
# Run make validate-generate
119+
echo "🔨 Running make validate-generate..."
120+
cd tools
121+
make validate-generate version=${{ steps.api-version.outputs.version }}
122+
cd ..
123+
124+
# The make validate-generate target handles all the validation logic
125+
echo "✅ make validate-generate completed successfully"
126+
127+
- name: Validate generated files
128+
run: |
129+
echo "🔍 Validating generated files..."
130+
131+
# Check Java generated files
132+
if [ -d "api-models/java/target/generated-sources/openapi" ]; then
133+
echo "✅ Java models generated in target/generated-sources/openapi"
134+
find api-models/java/target/generated-sources/openapi -name "*.java" | head -5
135+
else
136+
echo "❌ Java models not generated"
137+
exit 1
138+
fi
139+
140+
# Check TypeScript generated files
141+
if [ -d "api-models/typescript/src/generated" ]; then
142+
echo "✅ TypeScript models generated in src/generated"
143+
find api-models/typescript/src/generated -name "*.ts" | head -5
144+
else
145+
echo "❌ TypeScript models not generated"
146+
exit 1
147+
fi
148+
149+
echo "✅ All generated files validated"
150+
151+
- name: Summary
152+
run: |
153+
echo "🎉 API Models validation completed successfully!"
154+
echo "Version: ${{ steps.api-version.outputs.version }}"
155+
echo "✅ Configurations validated"
156+
echo "✅ Java models generated and compiled"
157+
echo "✅ TypeScript models generated and built"
158+
echo "✅ Tools configuration validated"
159+
echo "✅ make generate doesn't create unintended files"
160+
echo "✅ Generated files validated"

0 commit comments

Comments
 (0)