Skip to content

Commit 284fc5b

Browse files
committed
GitHub Actions: Fix Update Version Data workflow; Make txtar stable
1 parent c3092f6 commit 284fc5b

File tree

103 files changed

+1694
-3217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1694
-3217
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Export white-listed production code only.
77
/bin -export-ignore
8-
/resources -export-ignore
8+
/data -export-ignore
99
/src -export-ignore
1010
/composer.json -export-ignore
1111
/composer.lock -export-ignore

.github/workflows/update-data.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Update Version Data
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: 13 3 * * 1 # Weekly on Monday
7+
push:
8+
branches:
9+
- main
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref_name }}
13+
cancel-in-progress: true
14+
15+
permissions: {}
16+
17+
jobs:
18+
update-data:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v5
22+
23+
- uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: '8.4'
26+
coverage: none
27+
28+
- uses: actions/setup-go@v6
29+
with:
30+
go-version-file: 'go.mod'
31+
32+
- run: make version-data
33+
env:
34+
MAKEFLAGS: "--jobs=4 --output-sync=target"
35+
36+
- uses: typisttech/.github/.github/actions/create-auto-merged-pull-request@v2
37+
with:
38+
app-id: ${{ vars.TASTENDRUCK_APP_ID }}
39+
private-key: ${{ secrets.TASTENDRUCK_PRIVATE_KEY }}
40+
branch: "tastendruck/github_actions/update-data/${{ github.ref_name }}"
41+
title: ":robot: `make version-data`"
42+
labels: update_data

Makefile

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,27 @@ bin: vendor
1212

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

17-
tests/data/releases-%.json: FORCE
18-
curl 'https://www.php.net/releases/index.php?json&max=1000&version=$*' | jq . > ./tests/data/releases-$*.json
17+
.PHONY: tests/data/versions
18+
tests/data/versions: MAJORS := 5 7 8
19+
tests/data/versions:
20+
rm -rf tests/data/versions
21+
mkdir -p tests/data/versions
22+
$(MAKE) $(foreach MAJOR,$(MAJORS),tests/data/versions/v$(MAJOR).json)
1923

20-
resources/all-versions.json: bin tests/data/releases-5.json tests/data/releases-7.json tests/data/releases-8.json
24+
tests/data/versions/v%.json: FORCE
25+
curl 'https://www.php.net/releases/index.php?json&max=1000&version=$*' | \
26+
jq . > tests/data/versions/v$*.json
27+
28+
.PHONY: data/all-versions.json
29+
data/all-versions.json: bin
2130
./bin/update-all-versions
2231

23-
--go-generate:
24-
go generate ./...
32+
.PHONY: version-data
33+
version-data: data/all-versions.json tests/data/versions
2534

26-
txtar: resources/all-versions.json --go-generate
27-
$(MAKE) UPDATE_SCRIPTS=1 test-bin
35+
.PHONY: txtar
36+
txtar: data/all-versions.json
37+
go generate ./...
38+
UPDATE_SCRIPTS=1 $(MAKE) test-bin

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Available modes:
9191
Available sources:
9292
- `auto` *(default)*: Use `offline` in `minor-only` mode. Otherwise, fetch from [php.net](https://www.php.net/releases/index.php)
9393
- `php.net`: Fetch releases information from [php.net](https://www.php.net/releases/index.php)
94-
- `offline`: Use [hardcoded releases](resources/all-versions.json) information
94+
- `offline`: Use [hardcoded releases](data/all-versions.json) information
9595

9696
## Installation
9797

bin/update-all-versions

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@ $releases = new PhpNetReleases;
1212
$data = $releases->all();
1313
$data = Semver::rsort($data);
1414

15+
$dir = __DIR__.'/../data';
16+
@mkdir($dir, 0755);
17+
1518
$content = json_encode($data, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
16-
file_put_contents(__DIR__.'/../resources/all-versions.json', $content);
19+
file_put_contents($dir .'/all-versions.json', $content);
20+
21+
echo "Done: '{$dir}/all-versions.json' updated".PHP_EOL;
File renamed without changes.

internal/common.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
package internal
22

3-
var Constraints = []string{
3+
var EOLConstraints = []string{
44
"^7",
55
"^7.1",
66
"^7.1.2",
7-
"^7.1.2 || ~8.1.2",
8-
"^7 ^7.2",
7+
"^7.1.2 || ~8.0.3",
8+
"^7 <7.2.3",
9+
"7@stable",
10+
}
11+
12+
var SupportedConstraints = []string{
13+
"^8",
14+
"^8.2",
15+
"^8.3.4",
16+
"^8.2 || ~8.4.0",
17+
"^8.2 <= 8.4.1",
18+
"^7.4 || ^8.4",
19+
">=7.4",
920
"*",
1021
"@stable",
11-
"^7@stable",
22+
"^8@rc",
1223
}
1324

1425
var Modes = []string{

internal/composer/fail/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ func (d data) Write(f *os.File) error {
8181
}
8282

8383
func main() {
84-
var cases []data
84+
num := len(internal.Modes) * len(rawCases)
85+
cases := make([]data, 0, num)
86+
8587
for _, mode := range internal.Modes {
8688
for _, r := range rawCases {
8789
cases = append(cases, data{

internal/composer/success/main.go

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/typisttech/php-matrix/internal"
99
)
1010

11-
const fileTemplateRaw = `# DO NOT EDIT THIS FILE
11+
const eolTemplateRaw = `# DO NOT EDIT THIS FILE
1212
# This file is generated by "internal/composer/success/main.go"
1313
# Test the '{{ .Name }}' case
1414
@@ -34,28 +34,65 @@ cmp stdout stdout.golden
3434
-- stdout.golden --
3535
`
3636

37-
var fileTemplate = template.Must(template.New("").Parse(fileTemplateRaw))
37+
const supportedTemplateRaw = `# DO NOT EDIT THIS FILE
38+
# This file is generated by "internal/composer/success/main.go"
39+
# Test the '{{ .Name }}' case
40+
41+
exec php-matrix composer {{ .Mode }}
42+
stdout .
43+
! stderr .
44+
45+
exec php-matrix composer {{ .Mode }} --source=auto
46+
stdout .
47+
! stderr .
48+
49+
exec php-matrix composer {{ .Mode }} --source=php.net
50+
stdout .
51+
! stderr .
52+
53+
exec php-matrix composer {{ .Mode }} --source=offline
54+
stdout .
55+
! stderr .
56+
57+
-- composer.json --
58+
{"require":{"php":"{{ .Constraint }}"}}
59+
`
60+
61+
var eolFileTemplate = template.Must(template.New("").Parse(eolTemplateRaw))
62+
var supportedFileTemplate = template.Must(template.New("").Parse(supportedTemplateRaw))
3863

3964
type data struct {
40-
Mode string
41-
Constraint string
65+
Mode string
66+
Constraint string
67+
fileTemplate *template.Template
4268
}
4369

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

4874
func (d data) Write(f *os.File) error {
49-
return fileTemplate.Execute(f, d)
75+
return d.fileTemplate.Execute(f, d)
5076
}
5177

5278
func main() {
53-
var cases []data
79+
num := len(internal.Modes) * (len(internal.EOLConstraints) + len(internal.SupportedConstraints))
80+
cases := make([]data, 0, num)
81+
5482
for _, mode := range internal.Modes {
55-
for _, constraint := range internal.Constraints {
83+
for _, constraint := range internal.EOLConstraints {
84+
cases = append(cases, data{
85+
Mode: mode,
86+
Constraint: constraint,
87+
fileTemplate: eolFileTemplate,
88+
})
89+
}
90+
91+
for _, constraint := range internal.SupportedConstraints {
5692
cases = append(cases, data{
57-
Mode: mode,
58-
Constraint: constraint,
93+
Mode: mode,
94+
Constraint: constraint,
95+
fileTemplate: supportedFileTemplate,
5996
})
6097
}
6198
}

0 commit comments

Comments
 (0)