Skip to content

Commit c2b6cc8

Browse files
authored
Rename platform to requires (#137)
1 parent d1100b9 commit c2b6cc8

4 files changed

Lines changed: 20 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161

6262
build:
6363
needs: prepare
64-
runs-on: ubuntu-latest
64+
runs-on: blacksmith-4vcpu-ubuntu-2404
6565
strategy:
6666
matrix:
6767
platform: ${{fromJson(needs.prepare.outputs.platforms)}}
@@ -82,7 +82,7 @@ jobs:
8282
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
8383

8484
- name: setup buildx
85-
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
85+
uses: useblacksmith/setup-docker-builder@33fed32c1ba8775f20366ec9e8d0cd9fe8fc1dd3 # v1.3.0
8686

8787
- name: build binaries
8888
uses: docker/bake-action@5be5f02ff8819ecd3092ea6b2e6261c31774f2b4 # v6.10.0
@@ -91,8 +91,6 @@ jobs:
9191
targets: binary-cross
9292
set: |
9393
*.platform=${{ matrix.platform }}
94-
*.cache-from=type=gha,scope=binary-${{ steps.platform.outputs.pair }}
95-
*.cache-to=type=gha,scope=binary-${{ steps.platform.outputs.pair }},mode=max
9694
9795
- name: list artifacts
9896
run: ls -alh ./build
@@ -212,9 +210,6 @@ jobs:
212210
${{ steps.meta.outputs.bake-file }}
213211
targets: image-cross
214212
push: true
215-
set: |
216-
*.cache-from=type=gha,scope=wpm-image
217-
*.cache-to=type=gha,scope=wpm-image,mode=max
218213

219214
- name: download artifacts
220215
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 #v7.0.0

cli/command/init/init.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,12 @@ func buildWPMConfig(opts initOptions, pkgType string, mainFileHeaders any, readm
522522
cfg.Tags = tags
523523
}
524524

525-
platform := &wpmjson.Platform{}
525+
requires := &wpmjson.Requires{}
526526
dependencies := make(wpmjson.Dependencies)
527527
cfg.Team = getMetaStringSlice(readmeMeta, "contributors")
528528
wpRequires := getMetaString(readmeMeta, "requires", "")
529529
phpRequires := getMetaString(readmeMeta, "requires_php", "")
530+
testedUpTo := getMetaString(readmeMeta, "tested", "")
530531

531532
switch h := mainFileHeaders.(type) {
532533
case parser.ThemeFileHeaders:
@@ -654,22 +655,28 @@ func buildWPMConfig(opts initOptions, pkgType string, mainFileHeaders any, readm
654655
if wpRequires != "" {
655656
_, err := semver.NewConstraint(wpRequires)
656657
if err == nil {
657-
platform.WP = "^" + wpRequires
658+
requires.WP = ">=" + wpRequires
659+
}
660+
661+
_, err = semver.NewVersion(testedUpTo)
662+
if err == nil && wpRequires != testedUpTo {
663+
requires.WP += " <=" + testedUpTo
664+
requires.WP = strings.TrimSpace(requires.WP)
658665
}
659666
}
660667
if phpRequires != "" {
661668
_, err := semver.NewConstraint(phpRequires)
662669
if err == nil {
663-
platform.PHP = "^" + phpRequires
670+
requires.PHP = ">=" + phpRequires
664671
}
665672
}
666673

667674
if len(dependencies) > 0 {
668675
cfg.Dependencies = &dependencies
669676
}
670677

671-
if platform.PHP != "" || platform.WP != "" {
672-
cfg.Platform = platform
678+
if requires.PHP != "" || requires.WP != "" {
679+
cfg.Requires = requires
673680
}
674681

675682
return cfg

cli/command/publish/publish.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func runPublish(ctx context.Context, wpmCli command.Cli, opts publishOptions) er
219219
Description: wpmJson.Description,
220220
Type: wpmJson.Type,
221221
Version: wpmJson.Version,
222-
Platform: wpmJson.Platform,
222+
Requires: wpmJson.Requires,
223223
License: wpmJson.License,
224224
Homepage: wpmJson.Homepage,
225225
Tags: wpmJson.Tags,

pkg/pm/wpmjson/package.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ type PackageConfig struct {
5454
PlatformStrict *bool `json:"platform-strict,omitempty"` // If set to true, wpm will refuse to install the package if the platform requirements are not met.
5555
}
5656

57-
// Platform holds the php and wp version constraints for a package.
58-
type Platform struct {
57+
// Requires holds wp and php version constraints for a package
58+
type Requires struct {
5959
WP string `json:"wp,omitempty" validate:"omitempty,wpm_semver_constraint"`
6060
PHP string `json:"php,omitempty" validate:"omitempty,wpm_semver_constraint"`
6161
}
@@ -69,7 +69,7 @@ type Config struct {
6969
Private bool `json:"private,omitempty"`
7070
Type PackageType `json:"type" validate:"required,oneof=theme plugin mu-plugin"`
7171
Version string `json:"version" validate:"required,wpm_semver"`
72-
Platform *Platform `json:"platform,omitempty" validate:"omitempty"`
72+
Requires *Requires `json:"requires,omitempty" validate:"omitempty"`
7373
License string `json:"license,omitempty" validate:"omitempty,min=3,max=100"`
7474
Homepage string `json:"homepage,omitempty" validate:"omitempty,url,wpm_http_url,min=10,max=200"`
7575
Tags []string `json:"tags,omitempty" validate:"omitempty,max=5,dive,min=2,max=64"`
@@ -88,7 +88,7 @@ var PackageFieldDescriptions = map[string]string{
8888
"Private": "must be a boolean. (optional)",
8989
"Type": "must be one of: 'plugin', 'theme', or 'mu-plugin'. (required)",
9090
"Version": "must be a valid semantic version (semver) and less than 64 characters. (required)",
91-
"Platform": "must be an object with 'php' and 'wp' fields, both of which must be valid semantic version constraints. (optional)",
91+
"Requires": "must be an object with 'php' and 'wp' fields, both of which must be valid semantic version constraints. (optional)",
9292
"License": "must be a string. (optional)",
9393
"Homepage": "must be a valid http url. (optional)",
9494
"Tags": "must be an array of strings with a maximum of 5 tags. (optional)",
@@ -107,7 +107,7 @@ type PackageManifest struct {
107107
Description string `json:"description,omitempty"`
108108
Type PackageType `json:"type"`
109109
Version string `json:"version"`
110-
Platform *Platform `json:"platform,omitempty"`
110+
Requires *Requires `json:"requires,omitempty"`
111111
License string `json:"license,omitempty"`
112112
Homepage string `json:"homepage,omitempty"`
113113
Tags []string `json:"tags,omitempty"`

0 commit comments

Comments
 (0)