diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 498e046..7c0f6ed 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,6 +5,10 @@ updates: directory: / schedule: interval: weekly + - package-ecosystem: gomod + directory: / + schedule: + interval: weekly - package-ecosystem: github-actions directory: / schedule: diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 07bcfd1..4f71c44 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -21,3 +21,6 @@ permissions: jobs: php: uses: typisttech/.github/.github/workflows/audit-php.yml@v3 + + go: + uses: typisttech/.github/.github/workflows/audit-go.yml@v3 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e70f431..bd18ad9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,9 +20,13 @@ jobs: php: uses: typisttech/.github/.github/workflows/lint-php.yml@v3 + go: + uses: typisttech/.github/.github/workflows/lint-go.yml@v3 + wait-for-all-lint: needs: - php + - go runs-on: ubuntu-latest steps: - run: exit 0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 86d7b71..fd72d25 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -95,3 +95,36 @@ jobs: disable_search: true files: coverage-feature.xml flags: feature + + e2e: + name: e2e (PHP ${{ matrix.php-version }}, Composer ${{ matrix.composer-version }}) + needs: php-matrix + strategy: + matrix: + php-version: ${{ fromJSON(needs.php-matrix.outputs.versions) }} + composer-version: ['2.6', '2.7', '2.8'] + runs-on: ubuntu-latest + env: + GOFLAGS: '-mod=mod' + steps: + - uses: actions/checkout@v5 + + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer:${{ matrix.composer-version }} + coverage: 'none' + + - uses: actions/setup-go@v6 + with: + go-version-file: 'go.mod' + + - run: go test -count=1 ./... + + wait-for-all-tests: + needs: + - pest + - e2e + runs-on: ubuntu-latest + steps: + - run: exit 0 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f9546e0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +ARG composer=latest +ARG php=8 + +FROM composer:${composer} AS composer-bin + +FROM php:${php}-cli-alpine + +ENV PATH="/usr/local/go/bin:$PATH" +ENV GOROOT=/usr/local/go +ENV GOTOOLCHAIN=local +ENV GOFLAGS=-mod=mod + +COPY --from=composer-bin --link /usr/bin/composer /usr/bin/composer +COPY --from=golang:1-alpine --link /usr/local/go /usr/local/go + +COPY go.mod go.sum /tmp-app/ +WORKDIR /tmp-app +RUN go mod download && rm -rf /tmp-app + +WORKDIR /app + +CMD ["go", "test", "./..."] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..081483a --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +export GOFLAGS=-mod=mod + +combos := php-8-composer-latest \ + php-8.4-composer-2.8 \ + php-8.4-composer-2.7 \ + php-8.4-composer-2.6 + +buildflags ?= --quiet + +define GEN_RULE +build-php-$(1)-composer-$(2): + docker build $(buildflags) --build-arg php=$(1) --build-arg composer=$(2) --tag wp-org-closed-plugin:php-$(1)-composer-$(2) . + +test-php-$(1)-composer-$(2): build-php-$(1)-composer-$(2) + docker run --volume $(shell pwd):/app --rm wp-org-closed-plugin:php-$(1)-composer-$(2) $(testcmd) +endef + +$(foreach combo,$(combos), $(eval $(call GEN_RULE,$(word 2,$(subst -, ,$(combo))),$(word 4,$(subst -, ,$(combo)))))) + +test: $(foreach c,$(combos), test-$(c)) + +build-latest: build-php-8-composer-latest +test-latest: test-php-8-composer-latest + +test-local: + go test ./... + +update-scripts: + UPDATE_SCRIPTS=1 $(MAKE) test-local + +clean: + @IMAGE_IDS="$(shell docker images -q wp-org-closed-plugin)"; \ + if test -z "$${IMAGE_IDS}"; then \ + echo "Skip: No wp-org-closed-plugin images found."; \ + else \ + docker rmi $${IMAGE_IDS}; \ + fi diff --git a/composer.json b/composer.json index 754b1c1..d0a64fa 100644 --- a/composer.json +++ b/composer.json @@ -1,71 +1,71 @@ { - "name": "typisttech/wp-org-closed-plugin", - "description": "TODO", - "license": "MIT", - "type": "composer-plugin", - "keywords": [ - "TODO" - ], - "authors": [ - { - "name": "Typist Tech", - "homepage": "https://typist.tech" + "name": "typisttech/wp-org-closed-plugin", + "description": "TODO", + "license": "MIT", + "type": "composer-plugin", + "keywords": [ + "TODO" + ], + "authors": [ + { + "name": "Typist Tech", + "homepage": "https://typist.tech" + }, + { + "name": "Tang Rufus", + "email": "tangrufus@gmail.com", + "homepage": "https://tangrufus.com", + "role": "Developer" + } + ], + "homepage": "https://github.com/typisttech/wp-org-closed-plugin", + "support": { + "issues": "https://github.com/typisttech/wp-org-closed-plugin/issues", + "source": "https://github.com/typisttech/wp-org-closed-plugin", + "security": "https://github.com/typisttech/wp-org-closed-plugin/security" }, - { - "name": "Tang Rufus", - "email": "tangrufus@gmail.com", - "homepage": "https://tangrufus.com", - "role": "Developer" - } - ], - "homepage": "https://github.com/typisttech/wp-org-closed-plugin", - "support": { - "issues": "https://github.com/typisttech/wp-org-closed-plugin/issues", - "source": "https://github.com/typisttech/wp-org-closed-plugin", - "security": "https://github.com/typisttech/wp-org-closed-plugin/security" - }, - "require": { - "php": "^8.4", - "composer-plugin-api": "^2.6" - }, - "require-dev": { - "composer/composer": "^2.8", - "pestphp/pest": "^4.1", - "phpstan/extension-installer": "^1.4", - "phpstan/phpstan": "^2.1", - "phpstan/phpstan-deprecation-rules": "^2.0", - "phpstan/phpstan-strict-rules": "^2.0" - }, - "autoload": { - "psr-4": { - "TypistTech\\WpOrgClosedPlugin\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests/" - } - }, - "config": { - "allow-plugins": { - "pestphp/pest-plugin": true, - "phpstan/extension-installer": true + "require": { + "php": "^8.4", + "composer-plugin-api": "^2.6" }, - "sort-packages": true - }, - "extra": { - "class": "TypistTech\\WpOrgClosedPlugin\\Main", - "plugin-modifies-downloads": true, - "plugin-optional": true - }, - "scripts": { - "lint": [ - "@composer normalize --dry-run", - "pint --test", - "phpstan analyse" - ], - "pest": "pest", - "pest:feature": "pest --group=feature", - "pest:unit": "pest --group=unit" - } + "require-dev": { + "composer/composer": "^2.8", + "pestphp/pest": "^4.1", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0" + }, + "autoload": { + "psr-4": { + "TypistTech\\WpOrgClosedPlugin\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, + "config": { + "allow-plugins": { + "pestphp/pest-plugin": true, + "phpstan/extension-installer": true + }, + "sort-packages": true + }, + "extra": { + "class": "TypistTech\\WpOrgClosedPlugin\\Main", + "plugin-modifies-downloads": true, + "plugin-optional": true + }, + "scripts": { + "lint": [ + "@composer normalize --dry-run", + "pint --test", + "phpstan analyse" + ], + "pest": "pest", + "pest:feature": "pest --group=feature", + "pest:unit": "pest --group=unit" + } } diff --git a/composer.lock b/composer.lock index 0bc73c2..08c6354 100644 --- a/composer.lock +++ b/composer.lock @@ -5357,28 +5357,28 @@ }, { "name": "webmozart/assert", - "version": "1.11.0", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/webmozarts/assert.git", - "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" + "reference": "541057574806f942c94662b817a50f63f7345360" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", - "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/541057574806f942c94662b817a50f63f7345360", + "reference": "541057574806f942c94662b817a50f63f7345360", "shasum": "" }, "require": { "ext-ctype": "*", + "ext-date": "*", + "ext-filter": "*", "php": "^7.2 || ^8.0" }, - "conflict": { - "phpstan/phpstan": "<0.12.20", - "vimeo/psalm": "<4.6.1 || 4.6.2" - }, - "require-dev": { - "phpunit/phpunit": "^8.5.13" + "suggest": { + "ext-intl": "", + "ext-simplexml": "", + "ext-spl": "" }, "type": "library", "extra": { @@ -5409,9 +5409,9 @@ ], "support": { "issues": "https://github.com/webmozarts/assert/issues", - "source": "https://github.com/webmozarts/assert/tree/1.11.0" + "source": "https://github.com/webmozarts/assert/tree/1.12.0" }, - "time": "2022-06-03T18:03:27+00:00" + "time": "2025-10-20T12:43:39+00:00" } ], "aliases": [], diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0970a8a --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/typisttech/wp-org-closed-plugin + +go 1.25.3 + +require github.com/rogpeppe/go-internal v1.14.1 + +require ( + golang.org/x/sys v0.26.0 // indirect + golang.org/x/tools v0.26.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..51f07c4 --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= +golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..7c57668 --- /dev/null +++ b/main_test.go @@ -0,0 +1,24 @@ +package main_test + +import ( + "os" + "testing" + + "github.com/rogpeppe/go-internal/testscript" +) + +func Test(t *testing.T) { + testscript.Run(t, testscript.Params{ + Dir: "testdata/script", + Setup: func(env *testscript.Env) error { + wd, err := os.Getwd() + if err != nil { + return err + } + env.Setenv("PWD", wd) + env.Setenv("COMPOSER_CACHE_DIR", "/dev/null") + return nil + }, + UpdateScripts: os.Getenv("UPDATE_SCRIPTS") == "1", + }) +} diff --git a/testdata/script/closed-wpackagist.txtar b/testdata/script/closed-wpackagist.txtar index e42f153..cf72744 100644 --- a/testdata/script/closed-wpackagist.txtar +++ b/testdata/script/closed-wpackagist.txtar @@ -1,13 +1,9 @@ -env COMPOSER_NO_INTERACTION=1 -env COMPOSER_CACHE_DIR=/dev/null - exec composer config --quiet repositories.wp-org-closed-plugin path $PWD exec composer install --quiet -! exec composer audit +! exec composer audit --format=json cmp stdout golden.out -cmp stderr golden.err -- composer.json -- { @@ -19,24 +15,25 @@ cmp stderr golden.err }, "repositories": { "wpackagist": { - "type":"composer", - "url":"https://wpackagist.org" + "type": "composer", + "url": "https://wpackagist.org" } }, "config": { "allow-plugins": { "composer/installers": true, "typisttech/wp-org-closed-plugin": true + }, + "audit": { + "abandoned": "fail" } } } -- golden.out -- -+-------------------------+----------------------------------------------------------------------------------+ -| Abandoned Package | Suggested Replacement | -+-------------------------+----------------------------------------------------------------------------------+ -| wpackagist-plugin/moody | none | -+-------------------------+----------------------------------------------------------------------------------+ --- golden.err -- -No security vulnerability advisories found. -Found 1 abandoned package: +{ + "advisories": [], + "abandoned": { + "wpackagist-plugin/moody": null + } +} diff --git a/testdata/script/open-wpackagist.txtar b/testdata/script/open-wpackagist.txtar index 2ca456e..ad3c55f 100644 --- a/testdata/script/open-wpackagist.txtar +++ b/testdata/script/open-wpackagist.txtar @@ -1,13 +1,9 @@ -env COMPOSER_NO_INTERACTION=1 -env COMPOSER_CACHE_DIR=/dev/null - exec composer config --quiet repositories.wp-org-closed-plugin path $PWD exec composer install --quiet -exec composer audit +exec composer audit --format=json cmp stdout golden.out -cmp stderr golden.err -- composer.json -- { @@ -19,18 +15,24 @@ cmp stderr golden.err }, "repositories": { "wpackagist": { - "type":"composer", - "url":"https://wpackagist.org" + "type": "composer", + "url": "https://wpackagist.org" } }, "config": { "allow-plugins": { "composer/installers": true, "typisttech/wp-org-closed-plugin": true + }, + "audit": { + "abandoned": "fail" } } } + -- golden.out -- --- golden.err -- -No security vulnerability advisories found. +{ + "advisories": [], + "abandoned": [] +}