Skip to content

Commit 7d9d4bc

Browse files
committed
Add internal option to only use the main mirror
We use that in some places to avoid mirror issues and things being out of sync, like msys2-installer and msys2-autobuild. Move into the action so we can maintain it in one place. Use an env var instead of an action input, so it's more hidden, and doesn't confuse users. Please don't use this as a normal action user, as it adds strain to our main mirror. Fixes #571
1 parent f0aa88f commit 7d9d4bc

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

.github/workflows/Test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,3 +699,47 @@ jobs:
699699
run: |
700700
uname -a
701701
openssl help
702+
703+
704+
main-mirror:
705+
name: 🔒 main-mirror-only
706+
needs: [cache]
707+
runs-on: windows-latest
708+
steps:
709+
- name: 🧰 Checkout
710+
uses: actions/checkout@v6
711+
with:
712+
persist-credentials: false
713+
- name: 📥 Download artifact
714+
uses: actions/download-artifact@v7
715+
with:
716+
name: action
717+
- name: 🚧 run action
718+
uses: ./
719+
with:
720+
update: true
721+
install: git
722+
env:
723+
__SETUP_MSYS2_USE_MAIN_MIRROR_ONLY: 'true'
724+
- shell: msys2 {0}
725+
run: |
726+
# Verify pacman-conf.exe output doesn't contain mirror.msys2.org
727+
echo "Checking pacman-conf.exe output:"
728+
pacman-conf.exe
729+
if pacman-conf.exe | grep -q 'mirror\.msys2\.org'; then
730+
echo "ERROR: pacman-conf.exe output contains mirror.msys2.org"
731+
exit 1
732+
fi
733+
echo "✓ No mirror.msys2.org found in pacman-conf.exe output"
734+
735+
# Verify mirrorlist files only contain repo.msys2.org
736+
echo "Checking mirrorlist.mingw:"
737+
cat /etc/pacman.d/mirrorlist.mingw
738+
grep -q 'repo.msys2.org/mingw' /etc/pacman.d/mirrorlist.mingw
739+
[ $(wc -l < /etc/pacman.d/mirrorlist.mingw) -eq 1 ] || exit 1
740+
echo "Checking mirrorlist.msys:"
741+
cat /etc/pacman.d/mirrorlist.msys
742+
grep -q 'repo.msys2.org/msys' /etc/pacman.d/mirrorlist.msys
743+
[ $(wc -l < /etc/pacman.d/mirrorlist.msys) -eq 1 ] || exit 1
744+
745+
git --version

main.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)