@@ -6,66 +6,97 @@ const FLAVORS = [
66] ;
77
88/**
9- * @todo : load from https://github.com/FriendsOfShopware/shopware-static-data/pull/1
9+ * @todo change url when https://github.com/FriendsOfShopware/shopware-static-data/pull/1 is merged.
1010 */
11- const PHP_VERSIONS = [
12- "8.0" ,
13- "8.1" ,
14- "8.2" ,
15- ] ;
11+ const loadShopwarePHPVersions = async ( ) => {
12+ const response = await fetch ( "https://raw.githubusercontent.com/FriendsOfShopware/shopware-static-data/main/data/all-supported-php-versions-by-shopware-version.json" )
13+ return await response . json ( ) ;
14+ }
1615
17- const getTemplate = ( version ) => {
16+ const parseMinorVersion = ( version ) => {
1817 const parts = version . match ( / v [ 0 . 9 ] * .\. ( [ 0 - 9 ] * ) \. .* / ) ;
1918 if ( parts . length < 2 ) {
2019 throw new Error ( "Unexpected version format: " + version ) ;
2120 }
2221
23- const minor = parts [ 1 ] ;
24- if ( parseInt ( minor ) <= 4 ) {
22+ return parseInt ( parts [ 1 ] , 10 ) ;
23+ }
24+
25+ const getTemplate = ( version ) => {
26+ const minor = parseMinorVersion ( version ) ;
27+
28+ // For everything below 6.5, we need the shopware/production template.
29+ if ( minor <= 4 ) {
2530 return "https://github.com/shopware/production" ;
2631 }
2732
2833 return "https://github.com/shopware/platform" ;
2934}
3035
36+ /**
37+ * Helper to find the supported PHP versions in the static-dump.
38+ * Needed because some (older) shopware tags have an v before the composer version.
39+ */
40+ const findSupportedPhpVersion = ( supportedPhpVersions , shopwareVersion ) => {
41+ const parts = shopwareVersion . match ( / ^ v ? ( .* ) / ) ;
42+ if ( parts . length < 2 ) {
43+ throw new Error ( `Something went wrong, extracting the version from ${ shopwareVersion } . Got ${ parts } from the regex.` )
44+ }
45+ const version = parts [ 1 ] ;
46+
47+ if ( supportedPhpVersions [ version ] ) {
48+ return supportedPhpVersions [ version ] ;
49+ }
50+
51+ if ( supportedPhpVersions [ 'v' + version ] ) {
52+ return supportedPhpVersions [ 'v' + version ] ;
53+ }
54+
55+ // Shopware Version not found. Can happen when e.g. RCs are not published on Packagist.
56+ return undefined ;
57+ }
58+
3159async function main ( ) {
3260 const response = await fetch ( "https://api.github.com/repos/shopware/platform/git/refs/tags" )
3361 const tags = await response . json ( ) ;
3462
3563 const versions = tags . map ( ( tag ) => {
3664 const version = tag . ref . replace ( "refs/tags/" , "" ) ;
37- const parts = version . match ( / v [ 0 . 9 ] * .\. ( [ 0 - 9 ] * ) \. .* / ) ;
38- if ( parts . length < 2 ) {
39- return ;
40- }
41-
42- const minor = parts [ 1 ] ;
43- // skip
65+ const minor = parseMinorVersion ( version ) ;
66+
67+ // We only want to support versions >= 6.3 to reduce build time
4468 if ( parseInt ( minor ) <= 3 ) {
4569 return ;
4670 }
4771
4872 return version ;
4973 } ) . filter ( version => ! ! version ) ;
5074
51- let matrix = versions . map ( ( version ) => {
52- const template = getTemplate ( version ) ;
75+ const shopwarePhpVersions = await loadShopwarePHPVersions ( ) ;
5376
54- const matrix = [ ] ;
77+ let matrix = versions
78+ . map ( ( version ) => {
79+ const template = getTemplate ( version ) ;
5580
56- for ( let flavor in FLAVORS ) {
57- for ( let phpVersion in PHP_VERSIONS ) {
58- matrix . push ( {
59- "shopware-version" : version ,
60- "php-version" : phpVersion ,
61- "flavour" : flavor ,
62- "template" : template ,
63- } )
64- }
65- }
81+ const matrix = [ ] ;
82+
83+
84+ const supportedPhpVersions = findSupportedPhpVersion ( shopwarePhpVersions , version ) ;
85+
86+ FLAVORS . forEach ( ( flavor ) => {
87+ supportedPhpVersions . forEach ( ( phpVersion ) => {
88+ matrix . push ( {
89+ "shopware-version" : version ,
90+ "php-version" : phpVersion ,
91+ "flavour" : flavor ,
92+ "template" : template ,
93+ } )
94+ } ) ;
95+ } ) ;
6696
67- return matrix ;
68- } )
97+ return matrix ;
98+ } )
99+ . flat ( ) ;
69100
70101 console . log ( JSON . stringify ( {
71102 include : matrix ,
0 commit comments