diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index eb3585b..4c391c5 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -699,3 +699,47 @@ jobs: run: | uname -a openssl help + + + main-mirror: + name: 🔒 main-mirror-only + needs: [cache] + runs-on: windows-latest + steps: + - name: 🧰 Checkout + uses: actions/checkout@v6 + with: + persist-credentials: false + - name: 📥 Download artifact + uses: actions/download-artifact@v7 + with: + name: action + - name: 🚧 run action + uses: ./ + with: + update: true + install: git + env: + __SETUP_MSYS2_USE_MAIN_MIRROR_ONLY: 'true' + - shell: msys2 {0} + run: | + # Verify pacman-conf.exe output doesn't contain mirror.msys2.org + echo "Checking pacman-conf.exe output:" + pacman-conf.exe + if pacman-conf.exe | grep -q 'mirror\.msys2\.org'; then + echo "ERROR: pacman-conf.exe output contains mirror.msys2.org" + exit 1 + fi + echo "✓ No mirror.msys2.org found in pacman-conf.exe output" + + # Verify mirrorlist files only contain repo.msys2.org + echo "Checking mirrorlist.mingw:" + cat /etc/pacman.d/mirrorlist.mingw + grep -q 'repo.msys2.org/mingw' /etc/pacman.d/mirrorlist.mingw + [ $(wc -l < /etc/pacman.d/mirrorlist.mingw) -eq 1 ] || exit 1 + echo "Checking mirrorlist.msys:" + cat /etc/pacman.d/mirrorlist.msys + grep -q 'repo.msys2.org/msys' /etc/pacman.d/mirrorlist.msys + [ $(wc -l < /etc/pacman.d/mirrorlist.msys) -eq 1 ] || exit 1 + + git --version diff --git a/main.js b/main.js index 64ff3f7..6e76dc7 100644 --- a/main.js +++ b/main.js @@ -44,6 +44,8 @@ class Input { this.location; /** @type {boolean} */ this.cache; + /** @type {boolean} */ + this.usemainmirroronly; } } @@ -61,6 +63,14 @@ function parseInput() { let p_location = core.getInput('location'); let p_cache = core.getBooleanInput('cache'); + // Configures pacman to use only repo.msys2.org instead of the mirrorlist. + // See: https://github.com/msys2/setup-msys2/issues/571 + let p_use_main_mirror_only = false; + const envValue = process.env['__SETUP_MSYS2_USE_MAIN_MIRROR_ONLY']; + if (envValue === 'true' || envValue === '1') { + p_use_main_mirror_only = true; + } + const msystem_allowed = ['MSYS', 'MINGW32', 'MINGW64', 'UCRT64', 'CLANG64', 'CLANGARM64']; if (!msystem_allowed.includes(p_msystem.toUpperCase())) { throw new Error(`'msystem' needs to be one of ${ msystem_allowed.join(', ') }, got ${p_msystem}`); @@ -85,6 +95,7 @@ function parseInput() { input.platformcheckseverity = p_platformcheckseverity; input.location = (p_location == "RUNNER_TEMP") ? process.env['RUNNER_TEMP'] : p_location; input.cache = p_cache; + input.usemainmirroronly = p_use_main_mirror_only; return input; } @@ -136,6 +147,18 @@ async function disableKeyRefresh(msysRootDir) { await fs.promises.writeFile(postFile, newContent, 'utf8'); } +/** + * @param {string} msysRootDir + * @returns {Promise} + */ +async function configureMainMirror(msysRootDir) { + const mirrorlistMingw = path.join(msysRootDir, 'etc', 'pacman.d', 'mirrorlist.mingw'); + const mirrorlistMsys = path.join(msysRootDir, 'etc', 'pacman.d', 'mirrorlist.msys'); + + await fs.promises.writeFile(mirrorlistMingw, 'Server = https://repo.msys2.org/mingw/$repo/\n', 'utf8'); + await fs.promises.writeFile(mirrorlistMsys, 'Server = https://repo.msys2.org/msys/$arch/\n', 'utf8'); +} + /** * @param {string[]} paths * @param {string} restoreKey @@ -200,7 +223,7 @@ class PackageCache { // We want a cache key that is ideally always the same for the same kind of job. // So that mingw32 and ming64 jobs, and jobs with different install packages have different caches. let shasum = crypto.createHash('sha1'); - shasum.update([CACHE_FLUSH_COUNTER, input.release, input.update, input.pathtype, input.msystem, input.install].toString() + INSTALLER_CHECKSUM); + shasum.update([CACHE_FLUSH_COUNTER, input.release, input.update, input.pathtype, input.msystem, input.install, input.usemainmirroronly].toString() + INSTALLER_CHECKSUM); this.jobCacheKey = this.fallbackCacheKey + '-conf:' + shasum.digest('hex').slice(0, 8); this.restoreKey = undefined; @@ -390,6 +413,12 @@ async function run() { core.endGroup(); } + if (input.usemainmirroronly) { + core.startGroup('Configuring main mirror...'); + await configureMainMirror(msysRootDir); + core.endGroup(); + } + core.startGroup('Disable CheckSpace...'); // Reduce time required to install packages by disabling pacman's disk space checking await runMsys(['sed', '-i', 's/^CheckSpace/#CheckSpace/g', '/etc/pacman.conf']);