Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
test: add link check test (#9544)
h3n4ld0f9d674d25e
diff --git a/.github/workflows/test_link.yml b/.github/workflows/test_link.ymlnew file mode 100644index 0000000000..f2fe56e436--- /dev/null+++ b/.github/workflows/test_link.yml@@ -0,0 +1,20 @@+name: Release Test Link++on:+ pull_request:+ branches:+ - main+ paths:+ - "frontend/**"++ go-tests:+ runs-on: self-hosted+ timeout-minutes: 30+ steps:+ - uses: actions/checkout@v4+ - uses: actions/setup-go@v4+ with:+ go-version: 1.21.3+ cache: false+ - name: Test link in product is valid+ run: go test -timeout 600s -v ./scripts/... -p=10 | tee test.log; exit ${PIPESTATUS[0]}diff --git a/frontend/src/components/CreateDataSourceExample.vue b/frontend/src/components/CreateDataSourceExample.vueindex f1072f2b65..a6df99a4ab 100644--- a/frontend/src/components/CreateDataSourceExample.vue+++ b/frontend/src/components/CreateDataSourceExample.vue@@ -50,7 +50,7 @@</template></i18n-t><a- href="https://www.bytebase.com/docs/get-started/install/local-mysql-instance?source=console"+ href="https://www.bytebase.com/docs/tutorials/local-mysql-instance?source=console"target="_blank"class="normal-link">diff --git a/frontend/src/components/CustomApproval/Settings/components/RiskCenter/RiskDialog/RiskForm.vue b/frontend/src/components/CustomApproval/Settings/components/RiskCenter/RiskDialog/RiskForm.vueindex e2b980b1eb..d7c2378f32 100644--- a/frontend/src/components/CustomApproval/Settings/components/RiskCenter/RiskDialog/RiskForm.vue+++ b/frontend/src/components/CustomApproval/Settings/components/RiskCenter/RiskDialog/RiskForm.vue@@ -45,8 +45,7 @@<div class="text-sm text-control-light">{{ $t("custom-approval.risk-rule.condition.description-tips") }}<LearnMoreLink- v-if="false"- url="https://www.bytebase.com/404"+ url="https://www.bytebase.com/docs/administration/risk-center/#configuration?source=console"class="ml-1"/></div>diff --git a/frontend/src/components/DatabaseDetail/Settings/components/Secrets.vue b/frontend/src/components/DatabaseDetail/Settings/components/Secrets.vueindex a62310fc63..f56ae0d9ef 100644--- a/frontend/src/components/DatabaseDetail/Settings/components/Secrets.vue+++ b/frontend/src/components/DatabaseDetail/Settings/components/Secrets.vue@@ -16,7 +16,7 @@<i18n-t keypath="database.secret.description"><template #guide><a- href="https://www.bytebase.com/docs/change-database/secret?source=console"+ href="https://www.bytebase.com/docs/security/secret?source=console"target="_blank"class="normal-link">diff --git a/scripts/check_link_test.go b/scripts/check_link_test.gonew file mode 100644index 0000000000..a5fbe2a603--- /dev/null+++ b/scripts/check_link_test.go@@ -0,0 +1,106 @@+package tests++import (+ "net/http"+ "os"+ "path/filepath"+ "regexp"+ "testing"+ "time"++ "github.com/pkg/errors"+ "github.com/stretchr/testify/require"+)++var (+ // Extract all the links prefix with https://bytebase.com or https://www.bytebase.com in frontend code.+ linkMatcher = regexp.MustCompile(`(?m)https?:\/\/(www\.)?bytebase.com([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)`)++ ignores = map[string]bool{+ "node_modules": true,+ }++ extensions = map[string]bool{+ ".html": true,+ ".js": true,+ ".json": true,+ ".ts": true,+ ".vue": true,+ }++ frontendDirectory = "../frontend"+)++func TestLinkHealth(t *testing.T) {+ links, err := extractLinkRecursive()+ require.NoError(t, err)++ // Check all the links are reachable.+ for link := range links {+ if err := checkLinkWithRetry(link); err != nil {+ require.NoError(t, err)+ }+ }+}++func extractLinkRecursive() (map[string]bool, error) {+ // Initialize the result map+ links := make(map[string]bool)++ // Define the function to be used with os.Walk+ walkFn := func(path string, info os.FileInfo, err error) error {+ if err != nil {+ return err+ }++ if _, ok := ignores[info.Name()]; ok {+ return filepath.SkipDir+ }+ if info.IsDir() || (info.Mode()&os.ModeSymlink) == os.ModeSymlink {+ return nil+ }+ // Check if the file has a valid extension+ if _, ok := extensions[filepath.Ext(info.Name())]; !ok {+ return nil+ }++ // Read the file content+ content, err := os.ReadFile(path)+ if err != nil {+ return err+ }++ // Find all matches using the regular expression+ matches := linkMatcher.FindAllString(string(content), -1)+ // Add matches to the result map+ for _, match := range matches {+ links[match] = true+ }++ return nil+ }++ // Start the recursive traversal using os.Walk+ if err := filepath.Walk(frontendDirectory, walkFn); err != nil {+ return nil, errors.Wrapf(err, "failed to walk directory: %s", frontendDirectory)+ }++ return links, nil+}++func checkLinkWithRetry(link string) error {+ for i := 0; i < 3; i++ {+ // Request the link and check the response status code is 200.+ res, err := http.Get(link)+ if err != nil {+ return errors.Wrapf(err, "failed to request link: %s", link)+ }+ if res.StatusCode != http.StatusOK {+ time.Sleep(1 * time.Minute)+ continue+ }+ return nil+ }++ return errors.Errorf("Link %s is not reachable after %d retries", link, 3)+}