Skip to content

Commit 0309f5c

Browse files
feat(ci): support service deletion, introduce build tool
STACKISDK-517 Co-authored-by: Jonas Schlecht <73650029+SerseusWasTaken@users.noreply.github.com>
1 parent 864a344 commit 0309f5c

18 files changed

Lines changed: 1312 additions & 494 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ jobs:
2020
with:
2121
distribution: "temurin"
2222
java-version: ${{ env.JAVA_VERSION }}
23-
23+
2424
- name: Checkout
2525
uses: actions/checkout@v4
26-
26+
2727
- name: Install Go
2828
uses: actions/setup-go@v5
2929
with:
@@ -32,11 +32,11 @@ jobs:
3232
- name: Install project tools and dependencies
3333
shell: bash
3434
run: make project-tools
35-
35+
3636
- name: Download OAS
3737
shell: bash
3838
run: make download-oas
39-
39+
4040
- name: Generate SDK
4141
shell: bash
4242
run: make generate-go-sdk
@@ -54,45 +54,50 @@ jobs:
5454
with:
5555
distribution: "temurin"
5656
java-version: ${{ env.JAVA_VERSION }}
57-
57+
58+
- name: Install Go
59+
uses: actions/setup-go@v5
60+
with:
61+
go-version: ${{ env.GO_VERSION_BUILD }}
62+
5863
- name: Checkout
5964
uses: actions/checkout@v4
60-
65+
6166
- name: install uv
6267
uses: astral-sh/setup-uv@v7
6368
with:
6469
version: "0.10.4"
65-
70+
6671
- name: Install project tools and dependencies
6772
shell: bash
6873
run: |
6974
python -m venv .venv
7075
. .venv/bin/activate
7176
python -m pip install --upgrade pip
7277
make project-tools LANGUAGE=python
73-
78+
7479
- name: Download OAS
7580
shell: bash
7681
run: make download-oas
77-
82+
7883
- name: Generate SDK
7984
shell: bash
8085
run: make generate-python-sdk
81-
86+
8287
- name: install uv
8388
uses: astral-sh/setup-uv@v7
8489
with:
8590
version: "0.10.4"
8691
python-version: ${{ matrix.python-version }}
87-
92+
8893
- name: Install SDK
8994
working-directory: ./sdk-repo-updated
9095
run: make install-dev
91-
96+
9297
- name: Lint
9398
working-directory: ./sdk-repo-updated
9499
run: make lint
95-
100+
96101
- name: Test
97102
working-directory: ./sdk-repo-updated
98103
run: make test
@@ -109,20 +114,25 @@ jobs:
109114
with:
110115
distribution: "temurin"
111116
java-version: ${{ matrix.java-version }}
112-
117+
118+
- name: Install Go
119+
uses: actions/setup-go@v5
120+
with:
121+
go-version: ${{ env.GO_VERSION_BUILD }}
122+
113123
- name: Checkout
114124
uses: actions/checkout@v5
115-
125+
116126
- name: Download OAS
117127
run: make download-oas
118-
128+
119129
- name: Generate SDK
120130
run: make generate-java-sdk
121-
131+
122132
- name: Lint
123133
working-directory: ./sdk-repo-updated
124134
run: make lint
125-
135+
126136
- name: Test
127137
working-directory: ./sdk-repo-updated
128138
run: make test

.github/workflows/sdk-pr.yaml

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
main-go:
1515
name: "[Go] Update SDK Repo"
1616
runs-on: ubuntu-latest
17-
permissions:
17+
permissions:
1818
pull-requests: write
1919
contents: write
2020
steps:
@@ -23,44 +23,44 @@ jobs:
2323
with:
2424
key: ${{ secrets.SSH_PRIVATE_KEY }}
2525
known_hosts: ${{ vars.SSH_KNOWN_HOSTS }}
26-
26+
2727
- name: Install Java
2828
uses: actions/setup-java@v4
2929
with:
3030
distribution: "temurin"
3131
java-version: ${{ env.JAVA_VERSION }}
32-
32+
3333
- name: Checkout
3434
uses: actions/checkout@v4
35-
35+
3636
- name: Install Go
3737
uses: actions/setup-go@v5
3838
with:
3939
go-version: ${{ env.GO_VERSION }}
40-
40+
4141
- name: Install project tools and dependencies
4242
shell: bash
4343
run: make project-tools
44-
44+
4545
- name: Download OAS
4646
shell: bash
4747
run: make download-oas
48-
48+
4949
- name: Generate SDK
5050
shell: bash
5151
run: make generate-sdk
52-
52+
5353
- name: Push SDK
5454
env:
5555
GH_REPO: "stackitcloud/stackit-sdk-go"
5656
GH_TOKEN: ${{ secrets.SDK_PR_TOKEN }}
5757
run: |
5858
scripts/sdk-create-pr.sh "generator-bot-${{ github.run_id }}" "Generated from GitHub run [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
59-
59+
6060
main-python:
6161
name: "[Python] Update SDK Repo"
6262
runs-on: ubuntu-latest
63-
permissions:
63+
permissions:
6464
pull-requests: write
6565
contents: write
6666
steps:
@@ -69,37 +69,42 @@ jobs:
6969
with:
7070
key: ${{ secrets.SSH_PRIVATE_KEY }}
7171
known_hosts: ${{ vars.SSH_KNOWN_HOSTS }}
72-
72+
7373
- name: Install Java
7474
uses: actions/setup-java@v4
7575
with:
7676
distribution: "temurin"
7777
java-version: ${{ env.JAVA_VERSION }}
78-
78+
79+
- name: Install Go
80+
uses: actions/setup-go@v5
81+
with:
82+
go-version: ${{ env.GO_VERSION }}
83+
7984
- name: Checkout
8085
uses: actions/checkout@v4
81-
86+
8287
- name: Install project tools and dependencies
8388
shell: bash
8489
run: |
8590
python -m venv .venv
8691
. .venv/bin/activate
8792
python -m pip install --upgrade pip
8893
make project-tools LANGUAGE=python
89-
94+
9095
- name: install uv
9196
uses: astral-sh/setup-uv@v7
9297
with:
9398
version: "0.10.4"
94-
99+
95100
- name: Download OAS
96101
shell: bash
97102
run: make download-oas
98-
103+
99104
- name: Generate SDK
100105
shell: bash
101106
run: make generate-sdk LANGUAGE=python
102-
107+
103108
- name: Push SDK
104109
env:
105110
GH_REPO: "stackitcloud/stackit-sdk-python"
@@ -111,7 +116,7 @@ jobs:
111116
main-java:
112117
name: "[Java] Update SDK Repo"
113118
runs-on: ubuntu-latest
114-
permissions:
119+
permissions:
115120
pull-requests: write
116121
contents: write
117122
steps:
@@ -120,24 +125,29 @@ jobs:
120125
with:
121126
key: ${{ secrets.SSH_PRIVATE_KEY }}
122127
known_hosts: ${{ vars.SSH_KNOWN_HOSTS }}
123-
128+
129+
- name: Install Go
130+
uses: actions/setup-go@v5
131+
with:
132+
go-version: ${{ env.GO_VERSION }}
133+
124134
- name: Install Java
125135
uses: actions/setup-java@v4
126136
with:
127137
distribution: "temurin"
128138
java-version: ${{ env.JAVA_VERSION }}
129-
139+
130140
- name: Checkout
131141
uses: actions/checkout@v5
132-
142+
133143
- name: Download OAS
134144
run: make download-oas
135-
145+
136146
- name: Generate SDK
137147
run: make generate-sdk
138148
env:
139149
LANGUAGE: java
140-
150+
141151
- name: Push SDK
142152
env:
143153
GH_REPO: "stackitcloud/stackit-sdk-java"

scripts/build/delete.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"fmt"
7+
"strings"
8+
)
9+
10+
func runDelete(ctx context.Context, args []string, env Environment) error {
11+
deleteFlags := flag.NewFlagSet("delete", flag.ContinueOnError)
12+
deleteFlags.SetOutput(env.Err)
13+
14+
var planPath string
15+
deleteFlags.StringVar(&planPath, "plan", "", "path to the generation plan")
16+
if err := deleteFlags.Parse(args); err != nil {
17+
return fmt.Errorf("parsing delete flags: %w", err)
18+
}
19+
if len(deleteFlags.Args()) != 0 {
20+
return fmt.Errorf("unexpected arguments: %s\n", strings.Join(deleteFlags.Args(), " "))
21+
}
22+
if planPath == "" {
23+
return fmt.Errorf("--plan is required")
24+
}
25+
26+
plan, err := readPlan(env.FS, planPath)
27+
if err != nil {
28+
return fmt.Errorf("read generation plan: %v\n", err)
29+
}
30+
31+
for _, service := range plan.Services {
32+
if service.Action == ActionDelete {
33+
fmt.Fprintln(env.Out, service.Service)
34+
}
35+
}
36+
return nil
37+
}

scripts/build/delete_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"testing"
7+
"testing/fstest"
8+
)
9+
10+
func TestRunDeletePrintsServicesMarkedForDeletion(t *testing.T) {
11+
filesystem := fstest.MapFS{
12+
"generation-plan.json": {Data: []byte(`{
13+
"services": [
14+
{"service": "blocked", "oas_service": "blocked", "action": "block"},
15+
{"service": "foo", "oas_service": "foo-bar", "action": "generate"},
16+
{"service": "obsolete", "action": "delete"},
17+
{"service": "service2", "action": "delete"}
18+
]
19+
}`)},
20+
}
21+
var stdout, stderr bytes.Buffer
22+
23+
err := runDelete(context.Background(), []string{"--plan", "generation-plan.json"}, Environment{
24+
Out: &stdout,
25+
Err: &stderr,
26+
FS: readOnlyFileSystem{FileSystem: filesystem},
27+
})
28+
if err != nil {
29+
t.Fatalf("runDelete failed: %v", err)
30+
}
31+
if got, want := stdout.String(), "obsolete\nservice2\n"; got != want {
32+
t.Errorf("stdout = %q, want %q", got, want)
33+
}
34+
}

0 commit comments

Comments
 (0)