Skip to content

Commit

Permalink
ci: use php and phpstan modules
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <[email protected]>
  • Loading branch information
sagikazarmark committed Nov 18, 2024
1 parent d25e9a8 commit f4dff25
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
32 changes: 20 additions & 12 deletions .dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,29 @@ func (m *Twirp) generate(source *dagger.Directory) *dagger.Directory {

// Build the code generator plugin.
func (m *Twirp) Phpstan() *dagger.Container {
source := dag.Container().
From("php:"+defaultPhpVersion).
WithFile("/usr/local/bin/install-php-extensions", dag.HTTP("https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions"), dagger.ContainerWithFileOpts{
Permissions: 0755,
}).
WithExec([]string{"install-php-extensions", "bcmath", "zip"}).
WithFile("/usr/local/bin/composer", dag.Container().From("composer:"+composerVersion).File("/usr/bin/composer")).
source := phpBase(defaultPhpVersion).Container().
WithDirectory("/work", m.Source).
WithWorkdir("/work").
WithExec([]string{"composer", "install"}).
Directory("/work")

return dag.Container().
From("ghcr.io/phpstan/phpstan:2-php8.0").
WithWorkdir("/work").
WithMountedDirectory("/work", source).
WithExec([]string{"phpstan", "analyze", "--no-progress"})
return dag.Phpstan(dagger.PhpstanOpts{
Version: phpstanVersion,
PhpVersion: defaultPhpVersion,
}).Analyse(source)
}

func phpBase(phpVersion string) *dagger.Php {
return dag.Php(dagger.PhpOpts{
Version: phpVersion,
}).
WithExtension("bcmath").
WithComposer(dagger.PhpWithComposerOpts{
Version: composerVersion,
}).
WithComposerCache(cacheVolume("composer"))
}

func cacheVolume(name string) *dagger.CacheVolume {
return dag.CacheVolume(fmt.Sprintf("twirphp-%s", name))
}
8 changes: 1 addition & 7 deletions .dagger/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,8 @@ func (m *Test) container(name string, phpVersion string) *dagger.Container {
phpVersion = defaultPhpVersion
}

return dag.Container().
From("php:"+phpVersion).
WithFile("/usr/local/bin/install-php-extensions", dag.HTTP("https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions"), dagger.ContainerWithFileOpts{
Permissions: 0755,
}).
WithExec([]string{"install-php-extensions", "bcmath", "zip"}).
return phpBase(phpVersion).Container().
WithFile("/usr/local/bin/clientcompat", m.Main.Clientcompat("")).
WithFile("/usr/local/bin/composer", dag.Container().From("composer:"+composerVersion).File("/usr/bin/composer")).
WithDirectory("/work", m.fullSourceWithCodegen(name)).
WithWorkdir("/work").
WithExec([]string{"composer", "install"}).
Expand Down
3 changes: 2 additions & 1 deletion .dagger/versions_pinned.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package main
const (
goVersion = "1.23.0"

defaultPhpVersion = "8.3.13"
defaultPhpVersion = "8.3"
composerVersion = "2.2.24"
phpstanVersion = "2"

twirpVersion = "v8.1.3"

Expand Down
10 changes: 10 additions & 0 deletions dagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"go.work.sum"
],
"dependencies": [
{
"name": "phpstan",
"source": "github.com/sagikazarmark/daggerverse/phpstan@phpstan/v0.2.0",
"pin": "b3c06e7e75b592cce5de7eb6ea54565a7ffbf8aa"
},
{
"name": "arc",
"source": "github.com/sagikazarmark/daggerverse/arc@arc/v0.5.0",
Expand All @@ -18,6 +23,11 @@
"name": "go",
"source": "github.com/sagikazarmark/daggerverse/go@07f08ab95be76586c798bc55424c684ad6d41497",
"pin": "07f08ab95be76586c798bc55424c684ad6d41497"
},
{
"name": "php",
"source": "github.com/sagikazarmark/daggerverse/php@php/v0.1.0",
"pin": "0af084118b214771286c548a63742219cf95d398"
}
],
"source": ".dagger"
Expand Down

0 comments on commit f4dff25

Please sign in to comment.