@@ -11,6 +11,93 @@ const MANIFEST_REPO_OWNER = 'actions';
11
11
const MANIFEST_REPO_NAME = 'python-versions' ;
12
12
const MANIFEST_REPO_BRANCH = 'main' ;
13
13
export const MANIFEST_URL = `https://raw.githubusercontent.com/${ MANIFEST_REPO_OWNER } /${ MANIFEST_REPO_NAME } /${ MANIFEST_REPO_BRANCH } /versions-manifest.json` ;
14
+ import os = require( 'os' )
15
+ import * as semver from 'semver'
16
+
17
+ interface IToolReleaseFile {
18
+ filename : string
19
+ // 'aix', 'darwin', 'freebsd', 'linux', 'openbsd',
20
+ // 'sunos', and 'win32'
21
+ // platform_version is an optional semver filter
22
+ // TODO: do we need distribution (e.g. ubuntu).
23
+ // not adding yet but might need someday.
24
+ // right now, 16.04 and 18.04 work
25
+ platform : string
26
+ platform_version ?: string
27
+
28
+ // 'arm', 'arm64', 'ia32', 'mips', 'mipsel',
29
+ // 'ppc', 'ppc64', 's390', 's390x',
30
+ // 'x32', and 'x64'.
31
+ arch : string
32
+
33
+ download_url : string
34
+ }
35
+
36
+ interface IToolRelease {
37
+ version : string
38
+ stable : boolean
39
+ release_url : string
40
+ files : IToolReleaseFile [ ]
41
+ }
42
+
43
+ async function _findMatch (
44
+ versionSpec : string ,
45
+ stable : boolean ,
46
+ candidates : IToolRelease [ ] ,
47
+ archFilter : string
48
+ ) : Promise < IToolRelease | undefined > {
49
+ const platFilter = os . platform ( )
50
+
51
+ let result : IToolRelease | undefined
52
+ let match : IToolRelease | undefined
53
+
54
+ let file : IToolReleaseFile | undefined
55
+ for ( const candidate of candidates ) {
56
+ const version = candidate . version
57
+
58
+ core . debug ( `check ${ version } satisfies ${ versionSpec } ` )
59
+ if (
60
+ semver . satisfies ( version , versionSpec ) &&
61
+ ( ! stable || candidate . stable === stable )
62
+ ) {
63
+ file = candidate . files . find ( item => {
64
+ core . debug (
65
+ `item.arch:${ item . arch } ===archFilter:${ archFilter } && item.platform:${ item . platform } ===platFilter:${ platFilter } `
66
+ )
67
+
68
+ let chk = item . arch === archFilter && item . platform === platFilter
69
+ core . debug ( `chk = ${ chk } item.platform_version = ${ item . platform_version } ` )
70
+ if ( chk && item . platform_version ) {
71
+ const osVersion = module . exports . _getOsVersion ( )
72
+ core . debug ( `osVersion = ${ osVersion } item.platform_version = ${ item . platform_version } ` )
73
+
74
+ if ( osVersion === item . platform_version ) {
75
+ chk = true
76
+ } else {
77
+ chk = semver . satisfies ( osVersion , item . platform_version )
78
+ }
79
+ core . debug ( `chk2 = ${ chk } ` )
80
+ }
81
+
82
+ return chk
83
+ } )
84
+
85
+ if ( file ) {
86
+ core . debug ( `matched ${ candidate . version } ` )
87
+ match = candidate
88
+ break
89
+ }
90
+ }
91
+ }
92
+
93
+ if ( match && file ) {
94
+ // clone since we're mutating the file list to be only the file that matches
95
+ result = Object . assign ( { } , match )
96
+ result . files = [ file ]
97
+ }
98
+
99
+ return result
100
+ }
14
101
15
102
export async function findReleaseFromManifest (
16
103
semanticVersionSpec : string ,
@@ -22,7 +109,13 @@ export async function findReleaseFromManifest(
22
109
AUTH ,
23
110
MANIFEST_REPO_BRANCH
24
111
) ;
25
- core . debug ( `semanticVersionSpec=${ semanticVersionSpec } manifest=${ JSON . stringify ( manifest ) } architecture=${ architecture } ` )
112
+ // core.debug(`semanticVersionSpec=${semanticVersionSpec} manifest=${JSON.stringify(manifest)} architecture=${architecture}`)
113
+ await _findMatch (
114
+ semanticVersionSpec ,
115
+ false ,
116
+ manifest ,
117
+ architecture
118
+ ) ;
26
119
return await tc . findFromManifest (
27
120
semanticVersionSpec ,
28
121
false ,
0 commit comments