Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ updates:
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
- package-ecosystem: github-actions
directory: /
schedule:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: govulncheck

on:
schedule:
- cron: '2 2 * * 1' # Weekly on Monday
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

permissions: {}

jobs:
govulncheck:
runs-on: ubuntu-latest
steps:
- uses: golang/govulncheck-action@v1

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'govulncheck' step
Uses Step
uses 'golang/govulncheck-action' with ref 'v1', not a pinned commit hash
with:
go-version-file: 'go.mod'
go-package: ./...
45 changes: 30 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,20 @@
coverage: xdebug
- uses: ramsey/composer-install@v3

- run: composer pest:unit -- --coverage-clover coverage-unit.xml --ci --bail --stop-on-incomplete --fail-on-all-issues
- run: composer pest:unit -- --coverage-clover coverage-unit.xml --ci

- uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage-unit.xml

e2e:
needs: pest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none
- uses: ramsey/composer-install@v3

- run: composer pest:e2e -- --ci --bail --stop-on-incomplete --fail-on-all-issues

codecov:
needs: pest
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v5

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium test

Unpinned 3rd party Action 'Test' step
Uses Step
uses 'shivammathur/setup-php' with ref 'v2', not a pinned commit hash

- uses: actions/download-artifact@v5
with:
Expand All @@ -67,3 +53,32 @@
disable_search: true
files: coverage-unit.xml
flags: unit

bin:
runs-on: ubuntu-latest
env:
GOFLAGS: '-mod=mod'
steps:
- uses: actions/checkout@v5

- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none
- uses: ramsey/composer-install@v3
with:
composer-options: '--no-dev --prefer-dist'

- name: Add bin into PATH
run: echo "${WORKSPACE}/bin" >> "$GITHUB_PATH"
env:
WORKSPACE: ${{ github.workspace }}

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium test

Unpinned 3rd party Action 'Test' step
Uses Step
uses 'ramsey/composer-install' with ref 'v3', not a pinned commit hash

- uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'

- name: Print php-matrix binary path
run: go test -count=1 -v ./internal

- run: go test -count=1 ./...
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export GOFLAGS=-mod=mod

.PHONY: FORCE
FORCE:;

.PHONY: vendor
vendor:
composer install --no-dev --prefer-dist
composer reinstall --prefer-dist '*'

bin: vendor

test-%: %
PATH="$(shell pwd)/$*:$(shell echo $$PATH)" \
go test -count=1 ./...

tests/data/releases-%.json: FORCE
curl 'https://www.php.net/releases/index.php?json&max=1000&version=$*' | jq . > ./tests/data/releases-$*.json

resources/all-versions.json: bin tests/data/releases-5.json tests/data/releases-7.json tests/data/releases-8.json
./bin/update-all-versions

--go-generate:
go generate ./...

txtar: resources/all-versions.json --go-generate
$(MAKE) UPDATE_SCRIPTS=1 test-bin
8 changes: 0 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,11 @@
"sort-packages": true
},
"scripts": {
"data:update": [
"curl 'https://www.php.net/releases/index.php?json&max=1000&version=5' | jq . > ./tests/data/releases-5.json",
"curl 'https://www.php.net/releases/index.php?json&max=1000&version=7' | jq . > ./tests/data/releases-7.json",
"curl 'https://www.php.net/releases/index.php?json&max=1000&version=8' | jq . > ./tests/data/releases-8.json",
"@php ./bin/update-all-versions",
"XDEBUG_MODE=off pest --update-snapshots"
],
"lint": [
"pint --test",
"phpstan analyse"
],
"pest": "pest",
"pest:e2e": "XDEBUG_MODE=off pest --group=e2e",
"pest:unit": "pest --group=unit"
}
}
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/typisttech/php-matrix

go 1.25.2

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
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
18 changes: 18 additions & 0 deletions internal/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package internal

var Constraints = []string{
"^7",
"^7.1",
"^7.1.2",
"^7.1.2 || ~8.1.2",
"^7 ^7.2",
"*",
"@stable",
"^7@stable",
}

var Modes = []string{
"",
"--mode=minor-only",
"--mode=full",
}
98 changes: 98 additions & 0 deletions internal/composer/fail/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package main

import (
"os"
"text/template"

"github.com/typisttech/php-matrix/internal"
)

const fileTemplateRaw = `# DO NOT EDIT THIS FILE
# This file is generated by "internal/composer/fail/main.go"
# Test the "{{ .Name }}" case

! exec php-matrix composer {{ .Mode }}
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer {{ .Mode }} --source=auto
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer {{ .Mode }} --source=php.net
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer {{ .Mode }} --source=offline
! stdout .
cmp stderr stderr.golden

-- stderr.golden --

-- composer.json --
{{ .ComposerJSON }}
`

var rawCases = []rawData{
{`no "require.php" is set/1`, `{"require":{"some/package":"^1.0"}}`},
{`no "require.php" is set/2`, `{"require":{}}`},
{`no "require.php" is set/3`, `{"require":123}`},
{`no "require.php" is set/4`, `{"require-dev":{"php":"^1.0"}}`},
{`no "require.php" is set/5`, `{"php":"^1.0"}`},
{`no "require.php" is set/6`, `{}`},

{`"require.php" is not a string/null`, `{"require":{"php":null}}`},
{`"require.php" is not a string/object`, `{"require":{"php":{}}}`},
{`"require.php" is not a string/array`, `{"require":{"php":[]}}`},
{`"require.php" is not a string/integer`, `{"require":{"php":123}}`},
{`"require.php" is not a string/float`, `{"require":{"php":12.3}}`},
{`"require.php" is not a string/true`, `{"require":{"php":true}}`},
{`"require.php" is not a string/false`, `{"require":{"php":false}}`},

{`"require.php" is not a valid constraint/ruby`, `{"require":{"php":"~>1.0"}}`},
{`"require.php" is not a valid constraint/empty string`, `{"require":{"php":""}}`},
{`"require.php" is not a valid constraint/invalid string`, `{"require":{"php":"invalid constraint"}}`},

{`unsatisfiable/1`, `{"require":{"php":">8.0 <7.0"}}`},
{`unsatisfiable/2`, `{"require":{"php":">999"}}`},
{`unsatisfiable/3`, `{"require":{"php":"dev-master"}}`},

{`invalid json`, `{invalid json`},
}

var fileTemplate = template.Must(template.New("").Parse(fileTemplateRaw))

type rawData struct {
name string
ComposerJSON string
}

type data struct {
Mode string
rawData
}

func (d data) Name() string {
return d.name
}

func (d data) Write(f *os.File) error {
return fileTemplate.Execute(f, d)
}

func main() {
var cases []data
for _, mode := range internal.Modes {
for _, r := range rawCases {
cases = append(cases, data{
Mode: mode,
rawData: r,
})
}

err := internal.Generate("composer/fail", cases...)
if err != nil {
panic(err)
}
}
}
12 changes: 12 additions & 0 deletions internal/composer/fail/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main_test

import (
"testing"

"github.com/typisttech/php-matrix/internal"
)

//go:generate go run ./main.go
func Test(t *testing.T) {
internal.RunTestscript(t)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# DO NOT EDIT THIS FILE
# This file is generated by "internal/composer/fail/main.go"
# Test the ""require.php" is not a string/array" case

! exec php-matrix composer --mode=full
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer --mode=full --source=auto
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer --mode=full --source=php.net
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer --mode=full --source=offline
! stdout .
cmp stderr stderr.golden

-- stderr.golden --

[ERROR] The "require.php" field is not set or not a string.

-- composer.json --
{"require":{"php":[]}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# DO NOT EDIT THIS FILE
# This file is generated by "internal/composer/fail/main.go"
# Test the ""require.php" is not a string/false" case

! exec php-matrix composer --mode=full
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer --mode=full --source=auto
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer --mode=full --source=php.net
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer --mode=full --source=offline
! stdout .
cmp stderr stderr.golden

-- stderr.golden --

[ERROR] The "require.php" field is not set or not a string.

-- composer.json --
{"require":{"php":false}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# DO NOT EDIT THIS FILE
# This file is generated by "internal/composer/fail/main.go"
# Test the ""require.php" is not a string/float" case

! exec php-matrix composer --mode=full
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer --mode=full --source=auto
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer --mode=full --source=php.net
! stdout .
cmp stderr stderr.golden

! exec php-matrix composer --mode=full --source=offline
! stdout .
cmp stderr stderr.golden

-- stderr.golden --

[ERROR] The "require.php" field is not set or not a string.

-- composer.json --
{"require":{"php":12.3}}
Loading
Loading