-
Notifications
You must be signed in to change notification settings - Fork 0
/
php.go
73 lines (64 loc) · 1.72 KB
/
php.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package internal
import (
"regexp"
"strings"
"github.com/CircleCI-Public/circleci-config/config"
"github.com/CircleCI-Public/circleci-config/labeling/labels"
)
func GeneratePHPJobs(ls labels.LabelSet) []*Job {
if !ls[labels.DepsPhp].Valid {
return nil
}
jobs := []*Job{}
if hasPhpLib(ls, "phpunit/phpunit") {
jobs = append(jobs, phpTestJob(ls))
}
return jobs
}
func hasPhpLib(ls labels.LabelSet, lib string) bool {
if ls[labels.DepsPhp].Dependencies[lib] != "" {
return true
}
return false
}
func initialPhpSteps(ls labels.LabelSet) []config.Step {
checkout := checkoutStep(ls[labels.DepsPhp])
installPackages := config.Step{
Type: config.OrbCommand,
Command: "php/install-packages",
}
return []config.Step{checkout, installPackages}
}
func phpImageVersion(composerVersion string) string {
version := "8.2.7"
if composerVersion != "" {
composerVersion = strings.TrimPrefix(composerVersion, "~")
composerVersion = strings.TrimPrefix(composerVersion, "^")
composerVersion = strings.TrimSuffix(composerVersion, ".*")
versionRegex := regexp.MustCompile(`^[0-9].[0-9]`)
versionMatch := versionRegex.FindString(composerVersion)
if versionMatch != "" {
version = versionMatch
}
}
return "cimg/php:" + version + "-node"
}
func phpTestJob(ls labels.LabelSet) *Job {
steps := initialPhpSteps(ls)
steps = append(steps, config.Step{
Type: config.Run,
Name: "run tests",
Command: "./vendor/bin/phpunit",
})
return &Job{
Job: config.Job{
Name: "test-php",
Comment: "Install php packages and run tests",
Steps: steps,
DockerImages: []string{phpImageVersion(ls[labels.DepsPhp].Dependencies["php"])},
},
Orbs: map[string]string{
"php": "circleci/php@1",
},
}
}