From 1f3485cd15e0f48264aafab3f17f2ad98ab66bb1 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 4 Apr 2023 22:24:06 -0700 Subject: [PATCH] Rename project and add better user-focused docs --- .gitignore | 3 +-- .goreleaser.yml | 2 +- Makefile | 2 +- README.MD | 45 ++++++++++++++++++++++++++----------- cmd/root.go | 6 ++--- cmd/validators.go | 2 +- fixtures/sites/valid.yml | 20 +++++------------ go.mod | 2 +- main.go | 2 +- pkg/model/sites.go | 3 ++- pkg/validator/sites.go | 2 +- pkg/validator/sites_test.go | 2 +- 12 files changed, 50 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 1023ed2..d2b3ff0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -/pyml-validator -/pyml-validator.yml +/sites-yml-validator .DS_Store diff --git a/.goreleaser.yml b/.goreleaser.yml index b679fd3..f3edd14 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,5 @@ --- -project_name: pyml-validator +project_name: sites-yml-validator before: hooks: diff --git a/Makefile b/Makefile index 6092ce8..c7afa4e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -APP := pyml-validator +APP := sites-yml-validator include devops/make/common.mk include devops/make/common-go.mk diff --git a/README.MD b/README.MD index 2263207..8b244e8 100644 --- a/README.MD +++ b/README.MD @@ -1,46 +1,65 @@ # Pantheon YML Validator -A utility for validating a sites.yml file on a Pantheon site during WordPress multisites' search-replace tasks. Asprirationally to include pantheon.yml validation in the future. +[![Early Access](https://img.shields.io/badge/Pantheon-Early_Access-yellow?logo=pantheon&color=FFDC28)](https://docs.pantheon.io/oss-support-levels#early-access) + +A utility for validating a `sites.yml` file on a Pantheon site during a WordPress multisite's search and replace tasks. For more information, see [Pantheon's Multisite Docs](https://docs.pantheon.io/guides/multisite/search-replace/). ## Usage -### Sites.yml +### sites.yml +To validate the `sites.yml` file, run: ``` -$ pyml-validator sites path/to/sites.yml +$ sites-yml-validator sites path/to/sites.yml ``` -See [this annotated fixture](./fixtures/sites/valid.yml) for an example of a valid sites.yml file. +#### Valid File Example +See [this annotated fixture](./fixtures/sites/valid.yml) for an example of a valid `sites.yml` file. + +The basic format for the file is: +``` yml +api_version: 1 +domain_maps: + {env_name}: + {blog_id}: {site_url} +``` +A `sites.yml` file is valid if: +- the `api_version` is `1` +- the key for each item in `domain_maps` is a valid Pantheon environment name (`dev`, `test`, `multidev`, etc.) +- For each subsite listed for an environment: + - the key is an integer + - the value is a valid Pantheon hostname +- there are no more than 25 subsites listed for any environment ## Install -### [Download the latest binary](https://github.com/pantheon-systems/pyml-validator/releases/latest) +### [Download the latest binary](https://github.com/pantheon-systems/sites-yml-validator/releases/latest) Use wget to download, gzipped pre-compiled binaries: -For instance, VERSION=v0.0.11 and BINARY=pyml-validator_linux_amd64 +For instance, VERSION=v0.0.11 and BINARY=sites-yml-validator_linux_amd64 ### Compressed via tar.gz ```bash -wget https://github.com/pantheon-systems/pyml-validator/releases/download/${VERSION}/${BINARY}.tar.gz -O - |\ - tar xz && mv ${BINARY} /usr/bin/pyml-validator +wget https://github.com/pantheon-systems/sites-yml-validator/releases/download/${VERSION}/${BINARY}.tar.gz -O - |\ + tar xz && mv ${BINARY} /usr/bin/sites-yml-validator ``` ### Plain binary ```bash -wget https://github.com/pantheon-systems/pyml-validator/releases/download/${VERSION}/${BINARY} -O /usr/bin/pyml-validator &&\ - chmod +x /usr/bin/pyml-validator +wget https://github.com/pantheon-systems/sites-yml-validator/releases/download/${VERSION}/${BINARY} -O /usr/bin/sites-yml-validator &&\ + chmod +x /usr/bin/sites-yml-validator ``` ### Latest version ```bash -wget https://github.com/pantheon-systems/pyml-validator/releases/latest/download/pyml-validator_linux_amd64 -O /usr/bin/pyml-validator &&\ - chmod +x /usr/bin/pyml-validator +wget https://github.com/pantheon-systems/sites-yml-validator/releases/latest/download/sites-yml-validator_linux_amd64 -O /usr/bin/sites-yml-validator &&\ + chmod +x /usr/bin/sites-yml-validator ``` ## Testing -[![Coverage Status](https://coveralls.io/repos/github/pantheon-systems/pyml-validator/badge.svg?t=PGhafd)](https://coveralls.io/github/pantheon-systems/pyml-validator) +[![Coverage Status](https://coveralls.io/repos/github/pantheon-systems/sites-yml-validator/badge.svg?t=PGhafd)](https://coveralls.io/github/pantheon-systems/sites-yml-validator) `make test` runs linting and testing. diff --git a/cmd/root.go b/cmd/root.go index 9cb7ed3..a0e54d2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,9 +9,9 @@ import ( var FilePath string var rootCmd = &cobra.Command{ - Use: "pyml-validator", - Short: "Pyml-validator validates sites.yml", - Long: `Pyml-validator is a validator for sites.yml, used for WPMS search-replace. + Use: "sites-yml-validator", + Short: "sites-yml-validator validates sites.yml", + Long: `sites-yml-validator is a validator for sites.yml, used for WPMS search-replace. Ensures that the given config file can be used by the platform.`, } diff --git a/cmd/validators.go b/cmd/validators.go index 9c3a95e..93cc628 100644 --- a/cmd/validators.go +++ b/cmd/validators.go @@ -2,7 +2,7 @@ package cmd import ( "fmt" - "pyml-validator/pkg/validator" + "sites-yml-validator/pkg/validator" "github.com/spf13/cobra" ) diff --git a/fixtures/sites/valid.yml b/fixtures/sites/valid.yml index cf95d51..2d8cade 100644 --- a/fixtures/sites/valid.yml +++ b/fixtures/sites/valid.yml @@ -29,19 +29,9 @@ domain_maps: 4: staff-portal.searchreplacetest.com 5: customers.searchreplacetest.com 6: hr-department.searchreplacetest.com - autopilot: - 1: autopilot-srtest.pantheonsite.io - 2: about.autopilot-srtest.pantheonsite.io - 5: customers.autopilot-srtest.pantheonsite.io - 6: hr-department.autopilot-srtest.pantheonsite.io - nomatch: - 31: jobs.nomatch-srtest.pantheonsite.io - 32: legal.nomatch-srtest.pantheonsite.io - domains: - 1: searchreplace.com - 2: about-searchreplace.com - 3: employee-resources-searchreplace.com - 4: staff-portal-searchreplace.com - 5: customers-searchreplace.com - 6: hr-department-searchreplace.com + mdevname: + 1: mdevname-srtest.pantheonsite.io + 2: about.mdevname-srtest.pantheonsite.io + 5: customers.mdevname-srtest.pantheonsite.io + 6: hr-department.mdevname-srtest.pantheonsite.io # Anything else in the file will be ignored, but not rejected. \ No newline at end of file diff --git a/go.mod b/go.mod index de5a42d..dba3385 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module pyml-validator +module sites-yml-validator go 1.20 diff --git a/main.go b/main.go index 68348e0..a43ea28 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ package main -import "pyml-validator/cmd" +import "sites-yml-validator/cmd" func main() { cmd.Execute() diff --git a/pkg/model/sites.go b/pkg/model/sites.go index 01856c4..5d147e6 100644 --- a/pkg/model/sites.go +++ b/pkg/model/sites.go @@ -6,7 +6,8 @@ type SitesYml struct { DomainMaps DomainMaps `yaml:"domain_maps"` } +// DomainMaps is a collection of blog ID/blog domains keyed by environment name. type DomainMaps map[string]DomainMapByEnvironment -// DomainMapByEnvironment is a map of site (blog) domains keyed by blog ID. +// DomainMapByEnvironment is a collection of site (blog) domains keyed by blog ID. type DomainMapByEnvironment map[int]string diff --git a/pkg/validator/sites.go b/pkg/validator/sites.go index 17153bb..b3bb2f2 100644 --- a/pkg/validator/sites.go +++ b/pkg/validator/sites.go @@ -3,8 +3,8 @@ package validator import ( "fmt" "os" - "pyml-validator/pkg/model" "regexp" + "sites-yml-validator/pkg/model" "gopkg.in/yaml.v3" ) diff --git a/pkg/validator/sites_test.go b/pkg/validator/sites_test.go index 9b0304a..763e9b5 100644 --- a/pkg/validator/sites_test.go +++ b/pkg/validator/sites_test.go @@ -3,7 +3,7 @@ package validator import ( "errors" "fmt" - "pyml-validator/pkg/model" + "sites-yml-validator/pkg/model" "strings" "testing"