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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Export white-listed production code only.
/bin -export-ignore
/resources -export-ignore
/data -export-ignore
/src -export-ignore
/composer.json -export-ignore
/composer.lock -export-ignore
Expand Down
35 changes: 0 additions & 35 deletions .github/workflows/update-data.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/update-version-data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Update Version Data

on:
workflow_dispatch:
schedule:
- cron: 13 3 * * 1 # Weekly on Monday
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

permissions: {}

jobs:
update-data:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- uses: shivammathur/setup-php@v2

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Update Version Data' step
Uses Step
uses 'shivammathur/setup-php' with ref 'v2', not a pinned commit hash
with:
php-version: '8.4'
coverage: none

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

- run: make version-data
env:
MAKEFLAGS: "--jobs=4 --output-sync=target"

- uses: typisttech/.github/.github/actions/create-auto-merged-pull-request@v2

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Update Version Data' step
Uses Step
uses 'typisttech/.github/.github/actions/create-auto-merged-pull-request' with ref 'v2', not a pinned commit hash
with:
app-id: ${{ vars.TASTENDRUCK_APP_ID }}
private-key: ${{ secrets.TASTENDRUCK_PRIVATE_KEY }}
branch: "tastendruck/github_actions/update-data/${{ github.ref_name }}"
title: ":robot: `make version-data`"
labels: update_data
27 changes: 19 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,27 @@ bin: vendor

test-%: %
PATH="$(shell pwd)/$*:$(shell echo $$PATH)" \
go test -count=1 ./...
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
.PHONY: tests/data/versions
tests/data/versions: MAJORS := 5 7 8
tests/data/versions:
rm -rf tests/data/versions
mkdir -p tests/data/versions
$(MAKE) $(foreach MAJOR,$(MAJORS),tests/data/versions/v$(MAJOR).json)

resources/all-versions.json: bin tests/data/releases-5.json tests/data/releases-7.json tests/data/releases-8.json
tests/data/versions/v%.json: FORCE
curl 'https://www.php.net/releases/index.php?json&max=1000&version=$*' | \
jq . > tests/data/versions/v$*.json

.PHONY: data/all-versions.json
data/all-versions.json: bin
./bin/update-all-versions

--go-generate:
go generate ./...
.PHONY: version-data
version-data: data/all-versions.json tests/data/versions

txtar: resources/all-versions.json --go-generate
$(MAKE) UPDATE_SCRIPTS=1 test-bin
.PHONY: txtar
txtar: data/all-versions.json
go generate ./...
UPDATE_SCRIPTS=1 $(MAKE) test-bin
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Available modes:
Available sources:
- `auto` *(default)*: Use `offline` in `minor-only` mode. Otherwise, fetch from [php.net](https://www.php.net/releases/index.php)
- `php.net`: Fetch releases information from [php.net](https://www.php.net/releases/index.php)
- `offline`: Use [hardcoded releases](resources/all-versions.json) information
- `offline`: Use [hardcoded releases](data/all-versions.json) information

## Installation

Expand Down
7 changes: 6 additions & 1 deletion bin/update-all-versions
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ $releases = new PhpNetReleases;
$data = $releases->all();
$data = Semver::rsort($data);

$dir = __DIR__.'/../data';
@mkdir($dir, 0755);

$content = json_encode($data, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
file_put_contents(__DIR__.'/../resources/all-versions.json', $content);
file_put_contents($dir .'/all-versions.json', $content);

echo "Done: '{$dir}/all-versions.json' updated".PHP_EOL;
File renamed without changes.
19 changes: 15 additions & 4 deletions internal/common.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package internal

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

var SupportedConstraints = []string{
"^8",
"^8.2",
"^8.3.4",
"^8.2 || ~8.4.0",
"^8.2 <= 8.4.1",
"^7.4 || ^8.4",
">=7.4",
"*",
"@stable",
"^7@stable",
"^8@rc",
}

var Modes = []string{
Expand Down
4 changes: 3 additions & 1 deletion internal/composer/fail/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ func (d data) Write(f *os.File) error {
}

func main() {
var cases []data
num := len(internal.Modes) * len(rawCases)
cases := make([]data, 0, num)

for _, mode := range internal.Modes {
for _, r := range rawCases {
cases = append(cases, data{
Expand Down
55 changes: 46 additions & 9 deletions internal/composer/success/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/typisttech/php-matrix/internal"
)

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

Expand All @@ -34,28 +34,65 @@ cmp stdout stdout.golden
-- stdout.golden --
`

var fileTemplate = template.Must(template.New("").Parse(fileTemplateRaw))
const supportedTemplateRaw = `# DO NOT EDIT THIS FILE
# This file is generated by "internal/composer/success/main.go"
# Test the '{{ .Name }}' case

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

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

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

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

-- composer.json --
{"require":{"php":"{{ .Constraint }}"}}
`

var eolFileTemplate = template.Must(template.New("").Parse(eolTemplateRaw))
var supportedFileTemplate = template.Must(template.New("").Parse(supportedTemplateRaw))

type data struct {
Mode string
Constraint string
Mode string
Constraint string
fileTemplate *template.Template
}

func (d data) Name() string {
return fmt.Sprintf("%q__%q", d.Mode, d.Constraint)
}

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

func main() {
var cases []data
num := len(internal.Modes) * (len(internal.EOLConstraints) + len(internal.SupportedConstraints))
cases := make([]data, 0, num)

for _, mode := range internal.Modes {
for _, constraint := range internal.Constraints {
for _, constraint := range internal.EOLConstraints {
cases = append(cases, data{
Mode: mode,
Constraint: constraint,
fileTemplate: eolFileTemplate,
})
}

for _, constraint := range internal.SupportedConstraints {
cases = append(cases, data{
Mode: mode,
Constraint: constraint,
Mode: mode,
Constraint: constraint,
fileTemplate: supportedFileTemplate,
})
}
}
Expand Down
32 changes: 32 additions & 0 deletions internal/composer/success/testdata/_--mode_full____7_stable_.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# DO NOT EDIT THIS FILE
# This file is generated by "internal/composer/success/main.go"
# Test the '"--mode=full"__"7@stable"' case

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

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

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

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

-- composer.json --
{"require":{"php":"7@stable"}}

-- stdout.golden --
{
"constraint": "7@stable",
"versions": [
"7.0.0"
],
"lowest": "7.0.0",
"highest": "7.0.0"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DO NOT EDIT THIS FILE
# This file is generated by "internal/composer/success/main.go"
# Test the '"--mode=full"__"^7.1.2 || ~8.1.2"' case
# Test the '"--mode=full"__"^7.1.2 || ~8.0.3"' case

exec php-matrix composer --mode=full
cmp stdout stdout.golden
Expand All @@ -19,11 +19,11 @@ cmp stdout stdout.golden
! stderr .

-- composer.json --
{"require":{"php":"^7.1.2 || ~8.1.2"}}
{"require":{"php":"^7.1.2 || ~8.0.3"}}

-- stdout.golden --
{
"constraint": "^7.1.2 || ~8.1.2",
"constraint": "^7.1.2 || ~8.0.3",
"versions": [
"7.1.2",
"7.1.3",
Expand Down Expand Up @@ -158,39 +158,34 @@ cmp stdout stdout.golden
"7.4.30",
"7.4.32",
"7.4.33",
"8.1.2",
"8.1.3",
"8.1.4",
"8.1.5",
"8.1.6",
"8.1.7",
"8.1.8",
"8.1.9",
"8.1.10",
"8.1.11",
"8.1.12",
"8.1.13",
"8.1.14",
"8.1.15",
"8.1.16",
"8.1.17",
"8.1.18",
"8.1.19",
"8.1.20",
"8.1.21",
"8.1.22",
"8.1.23",
"8.1.24",
"8.1.25",
"8.1.26",
"8.1.27",
"8.1.28",
"8.1.29",
"8.1.30",
"8.1.31",
"8.1.32",
"8.1.33"
"8.0.3",
"8.0.5",
"8.0.6",
"8.0.7",
"8.0.8",
"8.0.9",
"8.0.10",
"8.0.11",
"8.0.12",
"8.0.13",
"8.0.14",
"8.0.15",
"8.0.16",
"8.0.17",
"8.0.18",
"8.0.19",
"8.0.20",
"8.0.21",
"8.0.22",
"8.0.23",
"8.0.24",
"8.0.25",
"8.0.26",
"8.0.27",
"8.0.28",
"8.0.29",
"8.0.30"
],
"lowest": "7.1.2",
"highest": "8.1.33"
"highest": "8.0.30"
}
Loading
Loading