From b638baa1df6ffd631560866f19d21a0352d456a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Fri, 8 Nov 2024 21:52:58 +0100 Subject: [PATCH] chore: no need to generate the ci.yml anymore --- .github/workflows/ci.yml | 2 - modulegen/_template/ci.yml.tmpl | 145 --------------------------- modulegen/internal/main.go | 6 +- modulegen/internal/workflow/main.go | 40 -------- modulegen/internal/workflow/types.go | 17 ---- modulegen/main_test.go | 34 ------- scripts/bump-go.sh | 1 - 7 files changed, 2 insertions(+), 243 deletions(-) delete mode 100644 modulegen/_template/ci.yml.tmpl delete mode 100644 modulegen/internal/workflow/main.go delete mode 100644 modulegen/internal/workflow/types.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 233b37aae7..04d995c31a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,3 @@ -# This file is autogenerated by the 'modulegen' tool. -# Please update the 'ci.yml' template instead. name: Main pipeline on: diff --git a/modulegen/_template/ci.yml.tmpl b/modulegen/_template/ci.yml.tmpl deleted file mode 100644 index 46fc3e3906..0000000000 --- a/modulegen/_template/ci.yml.tmpl +++ /dev/null @@ -1,145 +0,0 @@ -# This file is autogenerated by the 'modulegen' tool. -# Please update the 'ci.yml' template instead. -name: Main pipeline - -on: - push: - branches: - - main - paths-ignore: - - '.vscode/**' - - 'mkdocs.yml' - - 'docs/**' - - 'README.md' - pull_request: - paths-ignore: - - '.vscode/**' - - 'mkdocs.yml' - - 'docs/**' - - 'README.md' - -concurrency: - group: {{ "${{ github.workflow }}-${{ github.head_ref || github.sha }}" }} - cancel-in-progress: true - -jobs: - test: - strategy: - matrix: - go-version: [1.22.x, 1.x] - platform: [ubuntu-latest, macos-latest] - uses: ./.github/workflows/ci-test-go.yml - with: - go-version: {{ "${{ matrix.go-version }}" }} - fail-fast: true - platform: {{ "${{ matrix.platform }}" }} - project-directory: "." - rootless-docker: false - run-tests: {{ "${{ matrix.platform == 'ubuntu-latest' }}" }} - ryuk-disabled: false - - # The job below is a copy of the job above, but with ryuk disabled. - # It's executed in the first stage to avoid concurrency issues. - test-reaper-off: - name: "Test with reaper off" - strategy: - matrix: - go-version: [1.22.x, 1.x] - uses: ./.github/workflows/ci-test-go.yml - with: - go-version: {{ "${{ matrix.go-version }}" }} - fail-fast: false - platform: "ubuntu-latest" - project-directory: "." - rootless-docker: false - run-tests: true - ryuk-disabled: true - - # The job below is a copy of the job above, but with Docker rootless. - # It's executed in the first stage to avoid concurrency issues. - test-rootless-docker: - name: "Test with Rootless Docker" - strategy: - matrix: - go-version: [1.22.x, 1.x] - platform: [ubuntu-latest] - uses: ./.github/workflows/ci-test-go.yml - with: - go-version: {{ "${{ matrix.go-version }}" }} - fail-fast: false - platform: "ubuntu-latest" - project-directory: "." - rootless-docker: true - run-tests: true - ryuk-disabled: false - - test-module-generator: - strategy: - matrix: - go-version: [1.22.x, 1.x] - platform: [ubuntu-latest, macos-latest, windows-latest] - uses: ./.github/workflows/ci-test-go.yml - with: - go-version: {{ "${{ matrix.go-version }}" }} - fail-fast: true - platform: {{ "${{ matrix.platform }}" }} - project-directory: "modulegen" - rootless-docker: false - run-tests: true - ryuk-disabled: false - - test-modules: - needs: test - strategy: - matrix: - go-version: [1.22.x, 1.x] - platform: [ubuntu-latest] - module: [{{ .Modules }}] - uses: ./.github/workflows/ci-test-go.yml - with: - go-version: {{ "${{ matrix.go-version }}" }} - fail-fast: false - platform: {{ "${{ matrix.platform }}" }} - project-directory: {{ "modules/${{ matrix.module }}" }} - rootless-docker: false - run-tests: {{ "${{ matrix.platform == 'ubuntu-latest' }}" }} - ryuk-disabled: false - - test-examples: - needs: test-modules - strategy: - matrix: - module: [{{ .Examples }}] - uses: ./.github/workflows/ci-test-go.yml - with: - go-version: "1.22.x" - fail-fast: true - platform: 'ubuntu-latest' - project-directory: {{ "examples/${{ matrix.module }}" }} - rootless-docker: false - run-tests: true - ryuk-disabled: false - - sonarcloud: - permissions: - contents: read # for actions/checkout to fetch code - pull-requests: read # for sonarsource/sonarcloud-github-action to determine which PR to decorate - if: {{ "${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' }}" }} - needs: test-examples - runs-on: ubuntu-latest - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: sonarcloud - - - name: Analyze with SonarCloud - uses: sonarsource/sonarcloud-github-action@49e6cd3b187936a73b8280d59ffd9da69df63ec9 # v2.1.1 - env: - GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }} - SONAR_TOKEN: {{ "${{ secrets.SONAR_TOKEN }}" }} diff --git a/modulegen/internal/main.go b/modulegen/internal/main.go index 2f64c5836d..21084a5a52 100644 --- a/modulegen/internal/main.go +++ b/modulegen/internal/main.go @@ -11,7 +11,6 @@ import ( "github.com/testcontainers/testcontainers-go/modulegen/internal/sonar" "github.com/testcontainers/testcontainers-go/modulegen/internal/tools" "github.com/testcontainers/testcontainers-go/modulegen/internal/vscode" - "github.com/testcontainers/testcontainers-go/modulegen/internal/workflow" ) func Generate(moduleVar context.TestcontainersModuleVar, isModule bool) error { @@ -82,9 +81,8 @@ func GenerateFiles(ctx context.Context, tcModule context.TestcontainersModule) e // not in the new module to be added, that's why they happen after the actual // module generation projectGenerators := []ProjectGenerator{ - workflow.Generator{}, // update github ci workflow - vscode.Generator{}, // update vscode workspace - sonar.Generator{}, // update sonar-project.properties + vscode.Generator{}, // update vscode workspace + sonar.Generator{}, // update sonar-project.properties } for _, generator := range projectGenerators { diff --git a/modulegen/internal/workflow/main.go b/modulegen/internal/workflow/main.go deleted file mode 100644 index 9cf75d259c..0000000000 --- a/modulegen/internal/workflow/main.go +++ /dev/null @@ -1,40 +0,0 @@ -package workflow - -import ( - "path/filepath" - "text/template" - - "github.com/testcontainers/testcontainers-go/modulegen/internal/context" - internal_template "github.com/testcontainers/testcontainers-go/modulegen/internal/template" -) - -type Generator struct{} - -// Generate updates github ci workflow -func (g Generator) Generate(ctx context.Context) error { - rootCtx, err := context.GetRootContext() - if err != nil { - return err - } - examples, err := rootCtx.GetExamples() - if err != nil { - return err - } - modules, err := rootCtx.GetModules() - if err != nil { - return err - } - - githubWorkflowsDir := ctx.GithubWorkflowsDir() - - projectDirectories := newProjectDirectories(examples, modules) - name := "ci.yml.tmpl" - t, err := template.New(name).ParseFiles(filepath.Join("_template", name)) - if err != nil { - return err - } - - exampleFilePath := filepath.Join(githubWorkflowsDir, "ci.yml") - - return internal_template.GenerateFile(t, exampleFilePath, name, projectDirectories) -} diff --git a/modulegen/internal/workflow/types.go b/modulegen/internal/workflow/types.go deleted file mode 100644 index 77433613fb..0000000000 --- a/modulegen/internal/workflow/types.go +++ /dev/null @@ -1,17 +0,0 @@ -package workflow - -import ( - "strings" -) - -type ProjectDirectories struct { - Examples string - Modules string -} - -func newProjectDirectories(examples []string, modules []string) *ProjectDirectories { - return &ProjectDirectories{ - Examples: strings.Join(examples, ", "), - Modules: strings.Join(modules, ", "), - } -} diff --git a/modulegen/main_test.go b/modulegen/main_test.go index d90c0da5be..9147626804 100644 --- a/modulegen/main_test.go +++ b/modulegen/main_test.go @@ -247,14 +247,11 @@ func TestGenerate(t *testing.T) { tmpCtx := context.New(t.TempDir()) examplesTmp := filepath.Join(tmpCtx.RootDir, "examples") examplesDocTmp := filepath.Join(tmpCtx.DocsDir(), "examples") - githubWorkflowsTmp := tmpCtx.GithubWorkflowsDir() err := os.MkdirAll(examplesTmp, 0o777) require.NoError(t, err) err = os.MkdirAll(examplesDocTmp, 0o777) require.NoError(t, err) - err = os.MkdirAll(githubWorkflowsTmp, 0o777) - require.NoError(t, err) err = copyInitialMkdocsConfig(t, tmpCtx) require.NoError(t, err) @@ -283,12 +280,7 @@ func TestGenerate(t *testing.T) { _, err = os.Stat(moduleDocFile) require.NoError(t, err) // error nil implies the file exist - mainWorkflowFile := filepath.Join(githubWorkflowsTmp, "ci.yml") - _, err = os.Stat(mainWorkflowFile) - require.NoError(t, err) // error nil implies the file exist - assertModuleDocContent(t, module, moduleDocFile) - assertModuleGithubWorkflowContent(t, mainWorkflowFile) generatedTemplatesDir := filepath.Join(examplesTmp, moduleNameLower) // do not generate examples_test.go for examples @@ -303,14 +295,11 @@ func TestGenerateModule(t *testing.T) { tmpCtx := context.New(t.TempDir()) modulesTmp := filepath.Join(tmpCtx.RootDir, "modules") modulesDocTmp := filepath.Join(tmpCtx.DocsDir(), "modules") - githubWorkflowsTmp := tmpCtx.GithubWorkflowsDir() err := os.MkdirAll(modulesTmp, 0o777) require.NoError(t, err) err = os.MkdirAll(modulesDocTmp, 0o777) require.NoError(t, err) - err = os.MkdirAll(githubWorkflowsTmp, 0o777) - require.NoError(t, err) err = copyInitialMkdocsConfig(t, tmpCtx) require.NoError(t, err) @@ -339,12 +328,7 @@ func TestGenerateModule(t *testing.T) { _, err = os.Stat(moduleDocFile) require.NoError(t, err) // error nil implies the file exist - mainWorkflowFile := filepath.Join(githubWorkflowsTmp, "ci.yml") - _, err = os.Stat(mainWorkflowFile) - require.NoError(t, err) // error nil implies the file exist - assertModuleDocContent(t, module, moduleDocFile) - assertModuleGithubWorkflowContent(t, mainWorkflowFile) generatedTemplatesDir := filepath.Join(modulesTmp, moduleNameLower) assertExamplesTestContent(t, module, filepath.Join(generatedTemplatesDir, "examples_test.go")) @@ -439,24 +423,6 @@ func assertModuleContent(t *testing.T, module context.TestcontainersModule, exam require.Equal(t, "\treturn c, nil", data[41]) } -// assert content GitHub workflow for the module -func assertModuleGithubWorkflowContent(t *testing.T, moduleWorkflowFile string) { - t.Helper() - content, err := os.ReadFile(moduleWorkflowFile) - require.NoError(t, err) - - data := sanitiseContent(content) - ctx := getTestRootContext(t) - - modulesList, err := ctx.GetModules() - require.NoError(t, err) - assert.Equal(t, " module: ["+strings.Join(modulesList, ", ")+"]", data[96]) - - examplesList, err := ctx.GetExamples() - require.NoError(t, err) - assert.Equal(t, " module: ["+strings.Join(examplesList, ", ")+"]", data[111]) -} - // assert content go.mod func assertGoModContent(t *testing.T, module context.TestcontainersModule, tcVersion string, goModFile string) { t.Helper() diff --git a/scripts/bump-go.sh b/scripts/bump-go.sh index 5ff33a5e6e..5f65e5aada 100755 --- a/scripts/bump-go.sh +++ b/scripts/bump-go.sh @@ -48,7 +48,6 @@ function main() { for f in $(find "${ROOT_DIR}/.github/workflows" -name "*.yml"); do bumpCIMatrix "${f}" "${escapedCurrentGoVersion}" "${escapedGoVersion}" done - bumpCIMatrix "${ROOT_DIR}/modulegen/_template/ci.yml.tmpl" "${escapedCurrentGoVersion}" "${escapedGoVersion}" # bump devcontainer file bumpDevcontainer "${ROOT_DIR}/.devcontainer/devcontainer.json" "${escapedCurrentGoVersion}" "${escapedGoVersion}"