@@ -44,6 +44,8 @@ class Input {
4444 this . location ;
4545 /** @type {boolean } */
4646 this . cache ;
47+ /** @type {boolean } */
48+ this . usemainmirroronly ;
4749 }
4850}
4951
@@ -61,6 +63,14 @@ function parseInput() {
6163 let p_location = core . getInput ( 'location' ) ;
6264 let p_cache = core . getBooleanInput ( 'cache' ) ;
6365
66+ // Configures pacman to use only repo.msys2.org instead of the mirrorlist.
67+ // See: https://github.com/msys2/setup-msys2/issues/571
68+ let p_use_main_mirror_only = false ;
69+ const envValue = process . env [ '__SETUP_MSYS2_USE_MAIN_MIRROR_ONLY' ] ;
70+ if ( envValue === 'true' || envValue === '1' ) {
71+ p_use_main_mirror_only = true ;
72+ }
73+
6474 const msystem_allowed = [ 'MSYS' , 'MINGW32' , 'MINGW64' , 'UCRT64' , 'CLANG64' , 'CLANGARM64' ] ;
6575 if ( ! msystem_allowed . includes ( p_msystem . toUpperCase ( ) ) ) {
6676 throw new Error ( `'msystem' needs to be one of ${ msystem_allowed . join ( ', ' ) } , got ${ p_msystem } ` ) ;
@@ -85,6 +95,7 @@ function parseInput() {
8595 input . platformcheckseverity = p_platformcheckseverity ;
8696 input . location = ( p_location == "RUNNER_TEMP" ) ? process . env [ 'RUNNER_TEMP' ] : p_location ;
8797 input . cache = p_cache ;
98+ input . usemainmirroronly = p_use_main_mirror_only ;
8899
89100 return input ;
90101}
@@ -136,6 +147,18 @@ async function disableKeyRefresh(msysRootDir) {
136147 await fs . promises . writeFile ( postFile , newContent , 'utf8' ) ;
137148}
138149
150+ /**
151+ * @param {string } msysRootDir
152+ * @returns {Promise<void> }
153+ */
154+ async function configureMainMirror ( msysRootDir ) {
155+ const mirrorlistMingw = path . join ( msysRootDir , 'etc' , 'pacman.d' , 'mirrorlist.mingw' ) ;
156+ const mirrorlistMsys = path . join ( msysRootDir , 'etc' , 'pacman.d' , 'mirrorlist.msys' ) ;
157+
158+ await fs . promises . writeFile ( mirrorlistMingw , 'Server = https://repo.msys2.org/mingw/$repo/\n' , 'utf8' ) ;
159+ await fs . promises . writeFile ( mirrorlistMsys , 'Server = https://repo.msys2.org/msys/$arch/\n' , 'utf8' ) ;
160+ }
161+
139162/**
140163 * @param {string[] } paths
141164 * @param {string } restoreKey
@@ -200,7 +223,7 @@ class PackageCache {
200223 // We want a cache key that is ideally always the same for the same kind of job.
201224 // So that mingw32 and ming64 jobs, and jobs with different install packages have different caches.
202225 let shasum = crypto . createHash ( 'sha1' ) ;
203- shasum . update ( [ CACHE_FLUSH_COUNTER , input . release , input . update , input . pathtype , input . msystem , input . install ] . toString ( ) + INSTALLER_CHECKSUM ) ;
226+ shasum . update ( [ CACHE_FLUSH_COUNTER , input . release , input . update , input . pathtype , input . msystem , input . install , input . usemainmirroronly ] . toString ( ) + INSTALLER_CHECKSUM ) ;
204227 this . jobCacheKey = this . fallbackCacheKey + '-conf:' + shasum . digest ( 'hex' ) . slice ( 0 , 8 ) ;
205228
206229 this . restoreKey = undefined ;
@@ -390,6 +413,12 @@ async function run() {
390413 core . endGroup ( ) ;
391414 }
392415
416+ if ( input . usemainmirroronly ) {
417+ core . startGroup ( 'Configuring main mirror...' ) ;
418+ await configureMainMirror ( msysRootDir ) ;
419+ core . endGroup ( ) ;
420+ }
421+
393422 core . startGroup ( 'Disable CheckSpace...' ) ;
394423 // Reduce time required to install packages by disabling pacman's disk space checking
395424 await runMsys ( [ 'sed' , '-i' , 's/^CheckSpace/#CheckSpace/g' , '/etc/pacman.conf' ] ) ;
0 commit comments