Skip to content

Commit 7c09f0d

Browse files
rh-amarinclaude
andcommitted
HYPERFLEET-1103 - feat:restructure TypeSpec sources into core, gcp
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2b7675f commit 7c09f0d

36 files changed

Lines changed: 130 additions & 117 deletions

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ jobs:
4747
env:
4848
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4949
run: |
50-
CURRENT=$(grep -oP '(?<=version: ")[^"]+' main.tsp)
50+
CURRENT=$(grep -oP '(?<=version: ")[^"]+' core/main.tsp)
5151
if [ -z "$CURRENT" ]; then
52-
echo "::error::Failed to extract version from main.tsp — check the @info decorator format" >&2
52+
echo "::error::Failed to extract version from core/main.tsp — check the @info decorator format" >&2
5353
exit 1
5454
fi
5555
LATEST=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null | sed 's/^v//' || echo "")
@@ -59,10 +59,10 @@ jobs:
5959
fi
6060
HIGHEST=$(printf '%s\n%s\n' "$CURRENT" "$LATEST" | sort -V | tail -1)
6161
if [ "$CURRENT" = "$LATEST" ]; then
62-
echo "::error::Version '$CURRENT' matches latest release tag 'v$LATEST' — bump the version in main.tsp before merging."
62+
echo "::error::Version '$CURRENT' matches latest release tag 'v$LATEST' — bump the version in core/main.tsp before merging."
6363
exit 1
6464
elif [ "$HIGHEST" != "$CURRENT" ]; then
65-
echo "::error::Version '$CURRENT' is lower than latest release 'v$LATEST' — version in main.tsp must be strictly greater."
65+
echo "::error::Version '$CURRENT' is lower than latest release 'v$LATEST' — version in core/main.tsp must be strictly greater."
6666
exit 1
6767
fi
6868
echo "Version bump OK: $LATEST → $CURRENT"

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ jobs:
2828
- name: Extract version
2929
id: version
3030
run: |
31-
VERSION=$(grep -oP '(?<=version: ")[^"]+' main.tsp)
31+
VERSION=$(grep -oP '(?<=version: ")[^"]+' core/main.tsp)
3232
if [ -z "$VERSION" ]; then
33-
echo "::error::Failed to extract version from main.tsp — check the @info decorator format" >&2
33+
echo "::error::Failed to extract version from core/main.tsp — check the @info decorator format" >&2
3434
exit 1
3535
fi
3636
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

aliases-core.tsp

Lines changed: 0 additions & 9 deletions
This file was deleted.

aliases-gcp.tsp

Lines changed: 0 additions & 8 deletions
This file was deleted.

aliases.tsp

Lines changed: 0 additions & 1 deletion
This file was deleted.

build-schema.sh

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,20 @@ done
5858
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5959
cd "$SCRIPT_DIR"
6060

61-
# Define the aliases file for the provider
62-
ALIASES_FILE="aliases-${PROVIDER}.tsp"
63-
64-
# Check if the aliases file exists
65-
if [ ! -f "$ALIASES_FILE" ]; then
66-
echo -e "${RED}Error: Provider aliases file not found: ${ALIASES_FILE}${NC}"
61+
# Resolve the provider entry point
62+
PROVIDER_ENTRY="${PROVIDER}/main.tsp"
63+
if [ ! -f "$PROVIDER_ENTRY" ]; then
64+
echo -e "${RED}Error: Provider entry point not found: ${PROVIDER_ENTRY}${NC}"
6765
echo ""
6866
echo "Available providers:"
69-
for file in aliases-*.tsp; do
70-
if [ -f "$file" ]; then
71-
provider_name=$(echo "$file" | sed 's/aliases-\(.*\)\.tsp/\1/')
72-
echo " - $provider_name"
67+
for dir in */; do
68+
if [ -f "${dir}main.tsp" ]; then
69+
echo " - ${dir%/}"
7370
fi
7471
done
7572
exit 1
7673
fi
7774

78-
# Check if main.tsp exists
79-
if [ ! -f "main.tsp" ]; then
80-
echo -e "${RED}Error: main.tsp not found in current directory${NC}"
81-
exit 1
82-
fi
83-
8475
# Check if tsp command is available
8576
if [ ! -x "${SCRIPT_DIR}/node_modules/.bin/tsp" ]; then
8677
echo -e "${RED}Error: tsp not found in node_modules. Run 'npm install' first.${NC}"
@@ -105,24 +96,15 @@ else
10596
fi
10697
echo ""
10798

108-
# Step 1: Re-link aliases.tsp to the provider-specific aliases file
109-
echo -e "${YELLOW}Step 1: Linking aliases.tsp to ${ALIASES_FILE}${NC}"
110-
if [ -L "aliases.tsp" ] || [ -f "aliases.tsp" ]; then
111-
rm -f aliases.tsp
112-
fi
113-
ln -sf "$ALIASES_FILE" aliases.tsp
114-
echo -e "${GREEN}✓ Linked aliases.tsp → ${ALIASES_FILE}${NC}"
115-
echo ""
116-
117-
# Step 2: Create output directory for the provider
99+
# Step 1: Create output directory for the provider
118100
OUTPUT_DIR="schemas/${PROVIDER}"
119-
echo -e "${YELLOW}Step 2: Preparing output directory...${NC}"
101+
echo -e "${YELLOW}Step 1: Preparing output directory...${NC}"
120102
mkdir -p "$OUTPUT_DIR"
121103
echo -e "${GREEN}✓ Created output directory: ${OUTPUT_DIR}${NC}"
122104
echo ""
123105

124-
# Step 3: Compile TypeSpec to generate OpenAPI schema
125-
echo -e "${YELLOW}Step 3: Compiling TypeSpec...${NC}"
106+
# Step 2: Compile TypeSpec to generate OpenAPI schema
107+
echo -e "${YELLOW}Step 2: Compiling TypeSpec from ${PROVIDER_ENTRY}...${NC}"
126108
TEMP_OUTPUT_DIR="tsp-output-${PROVIDER}"
127109

128110
# Cleanup function to remove temporary directory on exit
@@ -133,7 +115,7 @@ cleanup() {
133115
}
134116
trap cleanup EXIT
135117

136-
if "$TSP" compile main.tsp --output-dir "$TEMP_OUTPUT_DIR"; then
118+
if "$TSP" compile "$PROVIDER_ENTRY" --output-dir "$TEMP_OUTPUT_DIR"; then
137119
# Move the generated schema to the provider-specific directory
138120
if [ -f "${TEMP_OUTPUT_DIR}/schema/openapi.yaml" ]; then
139121
mv "${TEMP_OUTPUT_DIR}/schema/openapi.yaml" "${OUTPUT_DIR}/openapi.yaml"
@@ -152,10 +134,10 @@ else
152134
exit 1
153135
fi
154136

155-
# Step 4: Convert to OpenAPI 2.0 (Swagger) if requested
137+
# Step 3: Convert to OpenAPI 2.0 (Swagger) if requested
156138
if [ "$GENERATE_SWAGGER" = true ]; then
157139
echo ""
158-
echo -e "${YELLOW}Step 4: Converting to OpenAPI 2.0 (Swagger)...${NC}"
140+
echo -e "${YELLOW}Step 3: Converting to OpenAPI 2.0 (Swagger)...${NC}"
159141

160142
if npx api-spec-converter \
161143
--from=openapi_3 \

core/main.tsp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import "@typespec/http";
2+
import "@typespec/openapi";
3+
import "@typespec/openapi3";
4+
5+
import "./models/cluster/model.tsp";
6+
import "./models/cluster/example_cluster.tsp";
7+
import "./models/cluster/example_post.tsp";
8+
import "./models/cluster/example_patch.tsp";
9+
import "./models/nodepool/model.tsp";
10+
import "./models/nodepool/example_nodepool.tsp";
11+
import "./models/nodepool/example_post.tsp";
12+
import "./models/nodepool/example_patch.tsp";
13+
import "./services/statuses-internal.tsp";
14+
15+
import "../shared/services/clusters.tsp";
16+
import "../shared/services/statuses.tsp";
17+
import "../shared/services/nodepools.tsp";
18+
19+
using Http;
20+
using OpenAPI;
21+
22+
/**
23+
* HyperFleet API provides simple CRUD operations for managing cluster resources and their status history.
24+
*
25+
* **Architecture**: Simple CRUD only, no business logic, no event creation.
26+
* Sentinel operator handles all orchestration logic.
27+
* Adapters handle the specifics of managing spec
28+
*
29+
*/
30+
@service(#{ title: "HyperFleet API" })
31+
@info(#{
32+
version: "1.0.15",
33+
contact: #{
34+
name: "HyperFleet Team",
35+
url: "https://github.com/openshift-hyperfleet",
36+
},
37+
license: #{
38+
name: "Apache 2.0",
39+
url: "https://www.apache.org/licenses/LICENSE-2.0",
40+
},
41+
})
42+
@server("https://hyperfleet.redhat.com", "Production")
43+
@route("/api/hyperfleet/v1")
44+
namespace HyperFleet;
45+
46+
// Override BearerAuth to use lowercase "bearer" as required by kin-openapi
47+
model BearerAuth {
48+
type: AuthType.http;
49+
scheme: "bearer";
50+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import "../../aliases-core.tsp";
2-
import "../../models/clusters/model.tsp";
3-
import "../../models/common/model.tsp";
1+
import "./model.tsp";
2+
import "../../../shared/models/clusters/model.tsp";
3+
import "../../../shared/models/common/model.tsp";
44

55
const exampleCluster: Cluster = #{
66
kind: "Cluster",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import "../../aliases-core.tsp";
2-
import "../../models/clusters/model.tsp";
1+
import "./model.tsp";
2+
import "../../../shared/models/clusters/model.tsp";
33

44
const exampleClusterPatchRequest: ClusterPatchRequest = #{
55
spec: #{},
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import "../../aliases-core.tsp";
2-
import "../../models/clusters/model.tsp";
1+
import "./model.tsp";
2+
import "../../../shared/models/clusters/model.tsp";
33

44
const exampleClusterCreateRequest: ClusterCreateRequest = #{
55
kind: "Cluster",

0 commit comments

Comments
 (0)