|
| 1 | +/* |
| 2 | + * Copyright (c) 2021-present Fabien Potencier <fabien@symfony.com> |
| 3 | + * |
| 4 | + * This file is part of Symfony CLI project |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Affero General Public License as |
| 8 | + * published by the Free Software Foundation, either version 3 of the |
| 9 | + * License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Affero General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Affero General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +package main |
| 21 | + |
| 22 | +import ( |
| 23 | + "encoding/json" |
| 24 | + "fmt" |
| 25 | + "io" |
| 26 | + "net/http" |
| 27 | + "os" |
| 28 | + |
| 29 | + "github.com/hashicorp/go-version" |
| 30 | +) |
| 31 | + |
| 32 | +func main() { |
| 33 | + generateLatestPhpVersion() |
| 34 | +} |
| 35 | + |
| 36 | +func generateLatestPhpVersion() { |
| 37 | + resp, err := http.Get("https://www.php.net/releases/active.php") |
| 38 | + if err != nil { |
| 39 | + panic(err) |
| 40 | + } |
| 41 | + defer resp.Body.Close() |
| 42 | + |
| 43 | + body, err := io.ReadAll(resp.Body) |
| 44 | + if err != nil { |
| 45 | + panic(err) |
| 46 | + } |
| 47 | + |
| 48 | + var result map[int]map[string]struct { |
| 49 | + Announcement bool |
| 50 | + LatestMinor string `json:"version"` |
| 51 | + } |
| 52 | + |
| 53 | + if err := json.Unmarshal(body, &result); err != nil { |
| 54 | + panic(err) |
| 55 | + } |
| 56 | + |
| 57 | + var latestVersion *version.Version |
| 58 | + |
| 59 | + for _, versions := range result { |
| 60 | + for _, versionInfo := range versions { |
| 61 | + if !versionInfo.Announcement { |
| 62 | + continue |
| 63 | + } |
| 64 | + |
| 65 | + ver, err := version.NewVersion(versionInfo.LatestMinor) |
| 66 | + if err != nil { |
| 67 | + panic(err) |
| 68 | + } |
| 69 | + |
| 70 | + if latestVersion == nil || ver.GreaterThan(latestVersion) { |
| 71 | + latestVersion = ver |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + f, err := os.Create("php_version.go") |
| 77 | + if err != nil { |
| 78 | + panic(err) |
| 79 | + } |
| 80 | + f.WriteString(`// Code generated by commands/generator/main.go |
| 81 | +// DO NOT EDIT |
| 82 | +
|
| 83 | +/* |
| 84 | + * Copyright (c) 2021-present Fabien Potencier <fabien@symfony.com> |
| 85 | + * |
| 86 | + * This file is part of Symfony CLI project |
| 87 | + * |
| 88 | + * This program is free software: you can redistribute it and/or modify |
| 89 | + * it under the terms of the GNU Affero General Public License as |
| 90 | + * published by the Free Software Foundation, either version 3 of the |
| 91 | + * License, or (at your option) any later version. |
| 92 | + * |
| 93 | + * This program is distributed in the hope that it will be useful, |
| 94 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 95 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 96 | + * GNU Affero General Public License for more details. |
| 97 | + * |
| 98 | + * You should have received a copy of the GNU Affero General Public License |
| 99 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 100 | + */ |
| 101 | +
|
| 102 | +package commands |
| 103 | +
|
| 104 | +const LatestPhpMajorVersion = "` + fmt.Sprintf("%d.%d", latestVersion.Segments()[0], latestVersion.Segments()[1]) + `" |
| 105 | +const LatestPhpMinorVersion = "` + latestVersion.Original() + `" |
| 106 | +`) |
| 107 | +} |
0 commit comments