Skip to content

Commit b159ba9

Browse files
committed
feat: migrate from Earthly to Nix + Speakeasy for OpenAPI build pipeline
- Replace Earthly with Nix dev shell (flake.nix) and Just task runner - Use Speakeasy CLI v1.759.2 for OpenAPI spec merging with modelNamespace support, replacing openapi-merge-cli (npm) - Path prepending handled by yq-go instead of openapi-merge-cli - Consolidate overlays into shared.overlay.yaml (Speakeasy overlay format) - Fix Speakeasy registry publish: specs are now properly published and tagged (previously only tagging an old registry image) - Add LATEST_RELEASE tag alongside version tag on registry publish - Remove Earthly, Docker/QEMU setup action, and npm build dependencies - Add .envrc for direnv integration
1 parent 847ee9b commit b159ba9

17 files changed

Lines changed: 238 additions & 585 deletions

.earthlyignore

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

.envrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source_env_if_exists ".envrc.local"
2+
use flake . --impure
3+
dotenv_if_exists ".env"

.github/actions/env/action.yml

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

.github/workflows/releases.yml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,15 @@ permissions:
77
contents: write
88

99
jobs:
10-
OpenAPI:
10+
Release:
1111
runs-on: "ubuntu-latest"
1212
steps:
13-
- uses: earthly/actions-setup@v1
14-
with:
15-
github-token: ${{ secrets.GITHUB_TOKEN }}
16-
version: "latest"
1713
- uses: "actions/checkout@v4"
1814
with:
1915
fetch-depth: 0
20-
- name: Setup Env
21-
uses: ./.github/actions/env
22-
- name: Generate OpenAPI final specification
23-
run: >
24-
earthly +build-final-spec --version=${{github.ref_name}}
16+
- uses: cachix/install-nix-action@v31
17+
- name: Build OpenAPI spec and events
18+
run: nix develop --impure --command just build ${{github.ref_name}}
2519
- name: Create Release
2620
run: gh release create ${{github.ref_name}} --generate-notes
2721
env:
@@ -32,12 +26,7 @@ jobs:
3226
gh release upload ${{github.ref_name}} ./events/generated/all.json#events.json
3327
env:
3428
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35-
36-
publish-registry:
37-
needs: OpenAPI
38-
uses: speakeasy-api/sdk-generation-action/.github/workflows/tag.yaml@v15
39-
with:
40-
registry_tags: ${{ github.ref_name }}
41-
secrets:
42-
github_access_token: ${{ secrets.GITHUB_TOKEN }}
43-
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
29+
- name: Publish OpenAPI to Speakeasy Registry
30+
run: nix develop --impure --command speakeasy run -s all --registry-tags ${{github.ref_name}},LATEST_RELEASE
31+
env:
32+
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ worktrees
2727
.env
2828

2929

30-
# Earthly
31-
.tmp-earthly-out
30+
# Downloaded OpenAPI specs
31+
components/
3232
.DS_Store
33-
openapi/node_modules
33+
node_modules/
3434

3535

3636
.kubeconfig

.speakeasy/workflow.lock

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
1-
speakeasyVersion: 1.755.0
1+
speakeasyVersion: 1.759.2
22
sources:
33
stacks-source:
44
sourceNamespace: stacks-source
5-
sourceRevisionDigest: sha256:5f3efcd6d57a3d10c6117dc8652e196b181e1535d33294062cfb5f997c8abff0
6-
sourceBlobDigest: sha256:9e907dbdf2d4f42763a7a8d9e384a155be7a9443e612fa924108231587f827ad
5+
sourceRevisionDigest: sha256:55cacc53f19d56070c775a281f59a76932d9d24a1a20af46d16243cc2bef9fb1
6+
sourceBlobDigest: sha256:3b3e29bfb7abe6a0e8e1cb9c0601add2558863329b78c6b4759d77ecd5602db7
77
tags:
88
- latest
9-
- v0.0.0
9+
- RECONCILIATION_VERSION
1010
targets: {}
1111
workflow:
1212
workflowVersion: 1.0.0
1313
speakeasyVersion: latest
1414
sources:
1515
stacks-source:
1616
inputs:
17-
- location: ./releases/build/generate.json
17+
- location: ./releases/base.yaml
18+
- location: ./components/auth.openapi.yaml
19+
modelNamespace: auth
20+
- location: ./components/gateway.openapi.yaml
21+
modelNamespace: gateway
22+
- location: ./components/ledger.openapi.yaml
23+
modelNamespace: ledger
24+
- location: ./components/payments.openapi.yaml
25+
modelNamespace: payments
26+
- location: ./components/search.openapi.yaml
27+
modelNamespace: search
28+
- location: ./components/webhooks.openapi.yaml
29+
modelNamespace: webhooks
30+
- location: ./components/wallets.openapi.yaml
31+
modelNamespace: wallets
32+
- location: ./components/orchestration.openapi.yaml
33+
modelNamespace: orchestration
34+
- location: ./components/reconciliation.openapi.yaml
35+
modelNamespace: reconciliation
1836
overlays:
1937
- location: ./releases/overlays/shared.overlay.yaml
20-
output: ./releases/build/openapi-overlaid.yaml
38+
output: ./releases/build/generate.json
2139
registry:
2240
location: registry.speakeasyapi.dev/formance/formance/stacks-source
2341
targets: {}

.speakeasy/workflow.yaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,28 @@ speakeasyVersion: latest
33
sources:
44
stacks-source:
55
inputs:
6-
- location: ./releases/build/generate.json
6+
- location: ./releases/base.yaml
7+
- location: ./components/auth.openapi.yaml
8+
modelNamespace: auth
9+
- location: ./components/gateway.openapi.yaml
10+
modelNamespace: gateway
11+
- location: ./components/ledger.openapi.yaml
12+
modelNamespace: ledger
13+
- location: ./components/payments.openapi.yaml
14+
modelNamespace: payments
15+
- location: ./components/search.openapi.yaml
16+
modelNamespace: search
17+
- location: ./components/webhooks.openapi.yaml
18+
modelNamespace: webhooks
19+
- location: ./components/wallets.openapi.yaml
20+
modelNamespace: wallets
21+
- location: ./components/orchestration.openapi.yaml
22+
modelNamespace: orchestration
23+
- location: ./components/reconciliation.openapi.yaml
24+
modelNamespace: reconciliation
725
overlays:
826
- location: ./releases/overlays/shared.overlay.yaml
9-
output: ./releases/build/openapi-overlaid.yaml
27+
output: ./releases/build/generate.json
1028
registry:
1129
location: registry.speakeasyapi.dev/formance/formance/stacks-source
1230
targets: {}

Earthfile

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

Justfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Component versions
2+
LEDGER_VERSION := "v2.4.0"
3+
PAYMENTS_VERSION := "v3.2.0"
4+
WALLETS_VERSION := "v2.1.5"
5+
WEBHOOKS_VERSION := "v2.2.0"
6+
AUTH_VERSION := "v2.4.3"
7+
SEARCH_VERSION := "v2.1.0"
8+
ORCHESTRATION_VERSION := "v2.4.1"
9+
RECONCILIATION_VERSION := "v2.2.2"
10+
GATEWAY_VERSION := "v2.2.0"
11+
12+
# Download all component OpenAPI specs from GitHub releases
13+
download-specs:
14+
mkdir -p components
15+
wget -q https://github.com/formancehq/ledger/releases/download/{{LEDGER_VERSION}}/openapi.yaml -O components/ledger.openapi.yaml
16+
wget -q https://github.com/formancehq/payments/releases/download/{{PAYMENTS_VERSION}}/openapi.yaml -O components/payments.openapi.yaml
17+
wget -q https://github.com/formancehq/gateway/releases/download/{{GATEWAY_VERSION}}/openapi.yaml -O components/gateway.openapi.yaml
18+
wget -q https://github.com/formancehq/auth/releases/download/{{AUTH_VERSION}}/openapi.yaml -O components/auth.openapi.yaml
19+
wget -q https://github.com/formancehq/search/releases/download/{{SEARCH_VERSION}}/openapi.yaml -O components/search.openapi.yaml
20+
wget -q https://github.com/formancehq/webhooks/releases/download/{{WEBHOOKS_VERSION}}/openapi.yaml -O components/webhooks.openapi.yaml
21+
wget -q https://github.com/formancehq/wallets/releases/download/{{WALLETS_VERSION}}/openapi.yaml -O components/wallets.openapi.yaml
22+
wget -q https://github.com/formancehq/reconciliation/releases/download/{{RECONCILIATION_VERSION}}/openapi.yaml -O components/reconciliation.openapi.yaml
23+
wget -q https://github.com/formancehq/flows/releases/download/{{ORCHESTRATION_VERSION}}/openapi.yaml -O components/orchestration.openapi.yaml
24+
25+
# Prepend API path prefix to each component spec
26+
prepend-paths: download-specs
27+
yq -i '.paths |= (to_entries | map(select(.key == "/*").key = "/api/auth" + .key) | from_entries)' components/auth.openapi.yaml
28+
yq -i '.paths |= (to_entries | map(select(.key == "/*").key = "/api/ledger" + .key) | from_entries)' components/ledger.openapi.yaml
29+
yq -i '.paths |= (to_entries | map(select(.key == "/*").key = "/api/payments" + .key) | from_entries)' components/payments.openapi.yaml
30+
yq -i '.paths |= (to_entries | map(select(.key == "/*").key = "/api/search" + .key) | from_entries)' components/search.openapi.yaml
31+
yq -i '.paths |= (to_entries | map(select(.key == "/*").key = "/api/webhooks" + .key) | from_entries)' components/webhooks.openapi.yaml
32+
yq -i '.paths |= (to_entries | map(select(.key == "/*").key = "/api/wallets" + .key) | from_entries)' components/wallets.openapi.yaml
33+
yq -i '.paths |= (to_entries | map(select(.key == "/*").key = "/api/orchestration" + .key) | from_entries)' components/orchestration.openapi.yaml
34+
yq -i '.paths |= (to_entries | map(select(.key == "/*").key = "/api/reconciliation" + .key) | from_entries)' components/reconciliation.openapi.yaml
35+
36+
# Build the merged OpenAPI spec using Speakeasy
37+
build-openapi version="v0.0.0": prepend-paths
38+
mkdir -p releases/build
39+
speakeasy run -s all
40+
cd releases && sed -i'' -e 's/SDK_VERSION/{{version}}/g' build/generate.json
41+
42+
# Generate event schemas
43+
generate-events:
44+
cd events && npm install
45+
cd events && node index.js
46+
47+
# Build everything (OpenAPI spec + events)
48+
build version="v0.0.0": (build-openapi version) generate-events
49+
50+
# Publish OpenAPI spec to Speakeasy Registry
51+
publish-speakeasy version: prepend-paths
52+
speakeasy run -s all --registry-tags {{version}},LATEST_RELEASE
53+
54+
# Pre-commit: build spec and generate events
55+
pre-commit: (build-openapi) generate-events

0 commit comments

Comments
 (0)