Skip to content

Commit 8d1f4f5

Browse files
authored
feat: add nightly tests (scaleway#2648)
1 parent a9b7a7b commit 8d1f4f5

File tree

3 files changed

+164
-1
lines changed

3 files changed

+164
-1
lines changed

.github/workflows/nightly.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Nightly Acceptance Tests
2+
3+
on:
4+
schedule:
5+
# Will run at 00:00 every day
6+
- cron: "0 0 * * *"
7+
8+
jobs:
9+
nightly:
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
products:
14+
- container/v1beta1
15+
- instance/v1
16+
- marketplace/v2
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
steps:
21+
# Checkout should always be before setup-go to ensure caching is working
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
- name: Install Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: 1.23.0
28+
- name: Run Acceptance Tests
29+
run: go test -v ./internal/services/${{ matrix.products }} -timeout=4h
30+
env:
31+
SDK_UPDATE_CASSETTES: true
32+
SCW_DEBUG: 1
33+
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
34+
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
35+
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
36+
SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
37+
- name: Ping on failure
38+
if: ${{ failure() }}
39+
run: |
40+
curl -X POST -H 'Content-type: application/json' \
41+
--data '{
42+
"blocks": [
43+
{
44+
"type": "section",
45+
"text": {
46+
"type": "mrkdwn",
47+
"text": "'"Scaleway Sdk-Go Nightly workflow failed: <https://github.com/scaleway/scaleway-sdk-go/actions/runs/${GITHUB_RUN_ID}|${FAILED_PRODUCT}>"'"
48+
}
49+
}
50+
]
51+
}' \
52+
${SLACK_WEBHOOK_NIGHTLY};
53+
env:
54+
SLACK_WEBHOOK_NIGHTLY: ${{ secrets.SLACK_WEBHOOK_NIGHTLY }}
55+
FAILED_PRODUCT: ${{ matrix.products }}
56+
57+
# sweeper needs to run after nightly completed
58+
# no matter what are the results of the jobs
59+
sweeper:
60+
runs-on: ubuntu-latest
61+
permissions:
62+
contents: read
63+
needs: nightly
64+
if: always()
65+
steps:
66+
# Checkout should always be before setup-go to ensure caching is working
67+
- name: Checkout
68+
uses: actions/checkout@v4
69+
- name: Install Go
70+
uses: actions/setup-go@v5
71+
with:
72+
go-version: 1.23.0
73+
- name: Run sweepers
74+
run: go run -v ./cmd/sdk-sweeper
75+
env:
76+
SCW_DEBUG: 1
77+
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
78+
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
79+
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
80+
SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
81+
- name: Ping on failure
82+
if: ${{ failure() }}
83+
run: |
84+
curl -X POST -H 'Content-type: application/json' \
85+
--data '{
86+
"blocks": [
87+
{
88+
"type": "section",
89+
"text": {
90+
"type": "mrkdwn",
91+
"text": "'"Scaleway Sdk-Go sweepers in Nightly workflow failed: <https://github.com/scaleway/scaleway-sdk-go/actions/runs/${GITHUB_RUN_ID}>"'"
92+
}
93+
}
94+
]
95+
}' \
96+
${SLACK_WEBHOOK_NIGHTLY};
97+
env:
98+
SLACK_WEBHOOK_NIGHTLY: ${{ secrets.SLACK_WEBHOOK_NIGHTLY }}

cmd/sdk-sweeper/main.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"log"
7+
"os"
8+
9+
containerSweeper "github.com/scaleway/scaleway-sdk-go/api/container/v1beta1/sweepers"
10+
instanceSweeper "github.com/scaleway/scaleway-sdk-go/api/instance/v1/sweepers"
11+
"github.com/scaleway/scaleway-sdk-go/scw"
12+
)
13+
14+
func main() {
15+
exitCode := mainNoExit()
16+
os.Exit(exitCode)
17+
}
18+
19+
func getConfigProfile() *scw.Profile {
20+
config, err := scw.LoadConfig()
21+
if err != nil {
22+
return &scw.Profile{}
23+
}
24+
profile, err := config.GetActiveProfile()
25+
if err != nil {
26+
return &scw.Profile{}
27+
}
28+
29+
return profile
30+
}
31+
32+
func mainNoExit() int {
33+
configProfile := getConfigProfile()
34+
envProfile := scw.LoadEnvProfile()
35+
profile := scw.MergeProfiles(configProfile, envProfile)
36+
37+
client, err := scw.NewClient(
38+
scw.WithProfile(profile),
39+
scw.WithUserAgent("sdk-sweeper"),
40+
scw.WithEnv(),
41+
)
42+
if err != nil {
43+
log.Fatalf("Cannot create Scaleway client: %v", err)
44+
}
45+
46+
errs := []error(nil)
47+
48+
err = containerSweeper.SweepAllLocalities(client)
49+
if err != nil {
50+
errs = append(errs, fmt.Errorf("error sweeping container: %w", err))
51+
}
52+
53+
err = instanceSweeper.SweepAllLocalities(client)
54+
if err != nil {
55+
errs = append(errs, fmt.Errorf("error sweeping instance: %w", err))
56+
}
57+
58+
if len(errs) > 0 {
59+
log.Fatal(errors.Join(errs...).Error())
60+
61+
return -1
62+
}
63+
64+
return 0
65+
}

internal/testhelpers/httprecorder/recorder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func CreateRecordedScwClient(cassetteName string) (*scw.Client, *recorder.Record
7272
var client *scw.Client
7373

7474
if UpdateCassette {
75-
// When updating the recoreded test requests, we need the access key and secret key.
75+
// When updating the recorded test requests, we need the access key and secret key.
7676
client, err = scw.NewClient(
7777
scw.WithHTTPClient(httpClient),
7878
scw.WithProfile(activeProfile),

0 commit comments

Comments
 (0)