Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish migration to new PostgreSQL server pattern in go-bits/easypg #219

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ ci:
- ubuntu-latest
- windows-latest
coveralls: true
postgres: true
ignorePaths: []
```

Expand All @@ -419,13 +418,13 @@ successful on multiple operating systems. Default value for this is `ubuntu-late

If `coveralls` is `true` then your test coverage report will be uploaded to [Coveralls]. Make sure that you have enabled Coveralls for your GitHub repo beforehand.

If `postgres` is `true` then a PostgreSQL service container will be added for the `test` job.
You can connect to this PostgreSQL service at `localhost:54321` with `postgres` as username and password ([More info][postgres-service-container]).

`ignorePaths` specifies a list of filename patterns. Workflows will not trigger if a path
name matches a pattern in this list. [More info][ref-onpushpull] and [filter pattern cheat
sheet][ref-pattern-cheat-sheet]. This option is not defined by default.

If your application depends on `github.com/lib/pq`, the latest PostgreSQL server binaries will be available in the container when tests are executed.
This is intended for use with `github.com/sapcc/go-bits/easypg`, which can launch a PostgreSQL server during `func TestMain`; see documentation in package easypg for details.

### `githubWorkflow.pushContainerToGhcr`

If `enabled` is set to true, the generated `Dockerfile` is built for the platforms `linux/amd64` and `linux/arm64` and pushed to the repository path under `ghcr.io`.
Expand Down Expand Up @@ -496,7 +495,6 @@ license:
[doublestar-pattern]: https://github.com/bmatcuk/doublestar#patterns
[govulncheck]: https://github.com/golang/vuln
[misspell]: https://github.com/client9/misspell
[postgres-service-container]: https://docs.github.com/en/actions/guides/creating-postgresql-service-containers#testing-the-postgresql-service-container
[ref-onpushpull]: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpaths
[ref-pattern-cheat-sheet]: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
[ref-runs-on]: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
Expand Down
7 changes: 1 addition & 6 deletions internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ type CIWorkflowConfig struct {
IgnorePaths []string `yaml:"ignorePaths"`
RunnerType []string `yaml:"runOn"`
Coveralls bool `yaml:"coveralls"`
Postgres bool `yaml:"postgres"`
}

// LicenseWorkflowConfig appears in type Configuration.
Expand Down Expand Up @@ -242,11 +241,7 @@ func (c *Configuration) Validate() {
// Validate CI workflow configuration.
if ghwCfg.CI.Enabled {
if len(ghwCfg.CI.RunnerType) > 1 && !strings.HasPrefix(ghwCfg.CI.RunnerType[0], "ubuntu") {
logg.Fatal("githubWorkflow.ci.runOn must only define a single Ubuntu based runner when githubWorkflow.ci.postgres is enabled")
}
} else {
if ghwCfg.CI.Postgres {
logg.Fatal("githubWorkflow.ci.enabled must be set to 'true' when githubWorkflow.ci.postgres is enabled")
logg.Fatal("githubWorkflow.ci.runOn must only define a single Ubuntu based runner when githubWorkflow.ci.enabled is true")
}
}
}
Expand Down
17 changes: 2 additions & 15 deletions internal/ghworkflow/workflow_ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package ghworkflow

import (
"fmt"
"strings"

"github.com/sapcc/go-makefile-maker/internal/core"
"github.com/sapcc/go-makefile-maker/internal/golang"
Expand Down Expand Up @@ -41,30 +40,18 @@ func ciWorkflow(cfg core.Configuration, sr golang.ScanResult) {
testCmd := []string{
"make build/cover.out",
}
if ghwCfg.CI.Postgres || sr.UsesPostgres {
if sr.UsesPostgres {
testCmd = append([]string{
"sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y",
"sudo apt-get install --no-install-recommends postgresql-" + core.DefaultPostgresVersion,
fmt.Sprintf("export PATH=/usr/lib/postgresql/%s/bin:$PATH", core.DefaultPostgresVersion),
}, testCmd...)
// TODO remove this service once all users migrated to use github.com/sapcc/go-bits/easypg
testJob.Services = map[string]jobService{"postgres": {
Image: "postgres:" + core.DefaultPostgresVersion,
Env: map[string]string{"POSTGRES_PASSWORD": "postgres"},
Ports: []string{"54321:5432"},
Options: strings.Join([]string{
// Set health checks to wait until postgres has started
"--health-cmd pg_isready",
"--health-interval 10s",
"--health-timeout 5s",
"--health-retries 5",
}, " "),
}}
}
testJob.addStep(jobStep{
Name: "Run tests and generate coverage report",
Run: makeMultilineYAMLString(testCmd),
})

if ghwCfg.CI.Coveralls && !ghwCfg.IsSelfHostedRunner {
multipleOS := len(ghwCfg.CI.RunnerType) > 1
env := map[string]string{
Expand Down
10 changes: 6 additions & 4 deletions internal/makefile/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import (
"github.com/sapcc/go-makefile-maker/internal/golang"
)

//go:embed with-postgres-db.sh
var withPostgresDBScript []byte

// Render renders the Makefile.
func Render(cfg core.Configuration, sr golang.ScanResult) {
f := must.Return(os.Create("Makefile"))
Expand Down Expand Up @@ -62,7 +59,12 @@ func Render(cfg core.Configuration, sr golang.ScanResult) {

if sr.UsesPostgres {
must.Succeed(os.MkdirAll("testing", os.ModePerm))
must.Succeed(os.WriteFile("testing/with-postgres-db.sh", withPostgresDBScript, 0666))

// Cleanup obsolete helper script that was previously managed by this tool.
err := os.Remove("testing/with-postgres-db.sh")
if !os.IsNotExist(err) {
must.Succeed(err)
}
}
}

Expand Down
68 changes: 0 additions & 68 deletions internal/makefile/with-postgres-db.sh

This file was deleted.

Loading