@@ -36,35 +36,33 @@ export async function hashFile(file) {
3636 return hash . digest ( 'hex' )
3737}
3838
39- export function getVirtualEnvironmentName ( ) {
40- const platform = os . platform ( )
41- if ( platform === 'linux' ) {
42- return `ubuntu-${ findUbuntuVersion ( ) } `
43- } else if ( platform === 'darwin' ) {
44- return 'macos-latest'
45- } else if ( platform === 'win32' ) {
46- return 'windows-latest'
47- } else {
48- throw new Error ( `Unknown platform ${ platform } ` )
39+ function getImageOS ( ) {
40+ const imageOS = process . env [ 'ImageOS' ]
41+ if ( ! imageOS ) {
42+ throw new Error ( 'The environment variable ImageOS must be set' )
4943 }
44+ return imageOS
5045}
5146
52- function findUbuntuVersion ( ) {
53- const lsb_release = fs . readFileSync ( '/etc/lsb-release' , 'utf8' )
54- const match = lsb_release . match ( / ^ D I S T R I B _ R E L E A S E = ( \d + \. \d + ) $ / m)
47+ export function getVirtualEnvironmentName ( ) {
48+ const imageOS = getImageOS ( )
49+
50+ let match = imageOS . match ( / ^ u b u n t u ( \d + ) / ) // e.g. ubuntu18
5551 if ( match ) {
56- return match [ 1 ]
57- } else {
58- throw new Error ( 'Could not find Ubuntu version' )
52+ return `ubuntu-${ match [ 1 ] } .04`
5953 }
60- }
6154
62- export function getImageOS ( ) {
63- const imageOS = process . env [ 'ImageOS' ]
64- if ( ! imageOS ) {
65- throw new Error ( 'The environment variable ImageOS must be set' )
55+ match = imageOS . match ( / ^ m a c o s ( \d { 2 } ) ( \d + ) / ) // e.g. macos1015
56+ if ( match ) {
57+ return `macos-${ match [ 1 ] } .${ match [ 2 ] } `
6658 }
67- return imageOS
59+
60+ match = imageOS . match ( / ^ w i n ( \d + ) / ) // e.g. win19
61+ if ( match ) {
62+ return `windows-20${ match [ 1 ] } `
63+ }
64+
65+ throw new Error ( `Unknown ImageOS ${ imageOS } ` )
6866}
6967
7068export function shouldExtractInToolCache ( engine , version ) {
0 commit comments