mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 06:39:03 +08:00
ci: build/test/lint GH workflows for Go (#7266)
build/test/lint GH workflows for Go
This commit is contained in:
parent
31fb6727c2
commit
494d2460a0
4
.github/workflows/build.yaml
vendored
4
.github/workflows/build.yaml
vendored
@ -65,10 +65,6 @@ jobs:
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: "1.21"
|
||||
- name: Run tests
|
||||
shell: bash
|
||||
run: |
|
||||
make test
|
||||
- name: Build query-service image
|
||||
shell: bash
|
||||
run: |
|
||||
|
36
.github/workflows/ci.yaml
vendored
Normal file
36
.github/workflows/ci.yaml
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
pull_request_target:
|
||||
types:
|
||||
- labeled
|
||||
|
||||
jobs:
|
||||
test:
|
||||
if: |
|
||||
(github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork && github.event.pull_request.user.login != 'dependabot[bot]' && ! contains(github.event.pull_request.labels.*.name, 'safe-to-test')) ||
|
||||
(github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'safe-to-test'))
|
||||
uses: signoz/primus.workflows/.github/workflows/go-test.yaml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
PRIMUS_REF: main
|
||||
GO_TEST_CONTEXT: ./...
|
||||
fmt:
|
||||
if: |
|
||||
(github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork && github.event.pull_request.user.login != 'dependabot[bot]' && ! contains(github.event.pull_request.labels.*.name, 'safe-to-test')) ||
|
||||
(github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'safe-to-test'))
|
||||
uses: signoz/primus.workflows/.github/workflows/go-fmt.yaml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
PRIMUS_REF: main
|
||||
lint:
|
||||
if: |
|
||||
(github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork && github.event.pull_request.user.login != 'dependabot[bot]' && ! contains(github.event.pull_request.labels.*.name, 'safe-to-test')) ||
|
||||
(github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'safe-to-test'))
|
||||
uses: signoz/primus.workflows/.github/workflows/go-lint.yaml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
PRIMUS_REF: main
|
18
.github/workflows/postci.yaml
vendored
Normal file
18
.github/workflows/postci.yaml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: postci
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
branches:
|
||||
- main
|
||||
types:
|
||||
- synchronize
|
||||
|
||||
jobs:
|
||||
remove:
|
||||
if: github.event.pull_request.head.repo.fork || github.event.pull_request.user.login == 'dependabot[bot]'
|
||||
uses: signoz/primus.workflows/.github/workflows/github-label.yaml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
PRIMUS_REF: main
|
||||
GITHUB_LABEL_ACTION: remove
|
||||
GITHUB_LABEL_NAME: safe-to-test
|
@ -121,7 +121,7 @@ func (ah *APIHandler) getOrCreateCloudIntegrationPAT(ctx context.Context, orgId
|
||||
allPats, err := ah.AppDao().ListPATs(ctx)
|
||||
if err != nil {
|
||||
return "", basemodel.InternalError(fmt.Errorf(
|
||||
"couldn't list PATs: %w", err.Error(),
|
||||
"couldn't list PATs: %w", err,
|
||||
))
|
||||
}
|
||||
for _, p := range allPats {
|
||||
@ -147,7 +147,7 @@ func (ah *APIHandler) getOrCreateCloudIntegrationPAT(ctx context.Context, orgId
|
||||
integrationPAT, err := ah.AppDao().CreatePAT(ctx, newPAT)
|
||||
if err != nil {
|
||||
return "", basemodel.InternalError(fmt.Errorf(
|
||||
"couldn't create cloud integration PAT: %w", err.Error(),
|
||||
"couldn't create cloud integration PAT: %w", err,
|
||||
))
|
||||
}
|
||||
return integrationPAT.Token, nil
|
||||
|
@ -47,7 +47,7 @@ func ValidateLicenseV3(licenseKey string) (*model.LicenseV3, *model.ApiError) {
|
||||
|
||||
req, err := http.NewRequest("GET", C.GatewayUrl+"/v2/licenses/me", nil)
|
||||
if err != nil {
|
||||
return nil, model.BadRequest(errors.Wrap(err, fmt.Sprintf("failed to create request: %w", err)))
|
||||
return nil, model.BadRequest(errors.Wrap(err, "failed to create request"))
|
||||
}
|
||||
|
||||
// Setting the custom header
|
||||
@ -55,7 +55,7 @@ func ValidateLicenseV3(licenseKey string) (*model.LicenseV3, *model.ApiError) {
|
||||
|
||||
response, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, model.BadRequest(errors.Wrap(err, fmt.Sprintf("failed to make post request: %w", err)))
|
||||
return nil, model.BadRequest(errors.Wrap(err, "failed to make post request"))
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(response.Body)
|
||||
|
@ -97,8 +97,8 @@ func TestNewLicenseV3(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Fallback to basic plan if license status is inactive",
|
||||
data: []byte(`{"id":"does-not-matter","key":"does-not-matter-key","category":"FREE","status":"INACTIVE","plan":{"name":"TEAMS"},"valid_from": 1730899309,"valid_until": -1}`),
|
||||
name: "Fallback to basic plan if license status is invalid",
|
||||
data: []byte(`{"id":"does-not-matter","key":"does-not-matter-key","category":"FREE","status":"INVALID","plan":{"name":"TEAMS"},"valid_from": 1730899309,"valid_until": -1}`),
|
||||
pass: true,
|
||||
expected: &LicenseV3{
|
||||
ID: "does-not-matter",
|
||||
@ -108,14 +108,14 @@ func TestNewLicenseV3(t *testing.T) {
|
||||
"name": "TEAMS",
|
||||
},
|
||||
"category": "FREE",
|
||||
"status": "INACTIVE",
|
||||
"status": "INVALID",
|
||||
"valid_from": float64(1730899309),
|
||||
"valid_until": float64(-1),
|
||||
},
|
||||
PlanName: PlanNameBasic,
|
||||
ValidFrom: 1730899309,
|
||||
ValidUntil: -1,
|
||||
Status: "INACTIVE",
|
||||
Status: "INVALID",
|
||||
IsCurrent: false,
|
||||
Features: model.FeatureSet{},
|
||||
},
|
||||
|
@ -17,7 +17,7 @@ func TestCreateRuleIDMatcher(t *testing.T) {
|
||||
name string
|
||||
orgID string
|
||||
receivers []config.Receiver
|
||||
ruleIDToReceivers map[string][]string
|
||||
ruleIDToReceivers []map[string][]string
|
||||
expectedRoutes []map[string]any
|
||||
}{
|
||||
{
|
||||
@ -34,7 +34,7 @@ func TestCreateRuleIDMatcher(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
ruleIDToReceivers: map[string][]string{"test-rule": {"slack-receiver"}},
|
||||
ruleIDToReceivers: []map[string][]string{{"test-rule": {"slack-receiver"}}},
|
||||
expectedRoutes: []map[string]any{{"receiver": "slack-receiver", "continue": true, "matchers": []any{"ruleId=~\"-1|test-rule\""}}},
|
||||
},
|
||||
{
|
||||
@ -59,7 +59,7 @@ func TestCreateRuleIDMatcher(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
ruleIDToReceivers: map[string][]string{"test-rule": {"slack-receiver", "email-receiver"}},
|
||||
ruleIDToReceivers: []map[string][]string{{"test-rule": {"slack-receiver", "email-receiver"}}},
|
||||
expectedRoutes: []map[string]any{{"receiver": "slack-receiver", "continue": true, "matchers": []any{"ruleId=~\"-1|test-rule\""}}, {"receiver": "email-receiver", "continue": true, "matchers": []any{"ruleId=~\"-1|test-rule\""}}},
|
||||
},
|
||||
{
|
||||
@ -76,7 +76,7 @@ func TestCreateRuleIDMatcher(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
ruleIDToReceivers: map[string][]string{"test-rule": {"does-not-exist"}},
|
||||
ruleIDToReceivers: []map[string][]string{{"test-rule": {"does-not-exist"}}},
|
||||
expectedRoutes: []map[string]any{{"receiver": "slack-receiver", "continue": true, "matchers": []any{"ruleId=~\"-1\""}}},
|
||||
},
|
||||
{
|
||||
@ -93,7 +93,7 @@ func TestCreateRuleIDMatcher(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
ruleIDToReceivers: map[string][]string{"test-rule-1": {"slack-receiver", "does-not-exist"}, "test-rule-2": {"slack-receiver"}},
|
||||
ruleIDToReceivers: []map[string][]string{{"test-rule-1": {"slack-receiver", "does-not-exist"}}, {"test-rule-2": {"slack-receiver"}}},
|
||||
expectedRoutes: []map[string]any{{"receiver": "slack-receiver", "continue": true, "matchers": []any{"ruleId=~\"-1|test-rule-1|test-rule-2\""}}},
|
||||
},
|
||||
}
|
||||
@ -112,9 +112,12 @@ func TestCreateRuleIDMatcher(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
for ruleID, receiverNames := range tc.ruleIDToReceivers {
|
||||
err = cfg.CreateRuleIDMatcher(ruleID, receiverNames)
|
||||
assert.NoError(t, err)
|
||||
for _, ruleIDToReceiversMap := range tc.ruleIDToReceivers {
|
||||
for ruleId, receiverNames := range ruleIDToReceiversMap {
|
||||
err = cfg.CreateRuleIDMatcher(ruleId, receiverNames)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
routes, err := json.Marshal(cfg.alertmanagerConfig.Route.Routes)
|
||||
|
Loading…
x
Reference in New Issue
Block a user