From 86c6e6fb5254ec78de42cf43c6438cd8a8b3ca10 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Sat, 12 Oct 2024 11:28:53 +0200 Subject: [PATCH] Add msys2 option (#83) --- .github/workflows/checkin.yml | 2 +- .github/workflows/selftest.yml | 23 ++++++++++++++++ .github/workflows/test-cache.yml | 45 +++++++++++++++++++++++++++++--- README.md | 6 ++--- action.yml | 22 ++++++++++++++-- lib/main.js | 24 +++++++++++++++++ src/main.ts | 28 ++++++++++++++++++++ 7 files changed, 141 insertions(+), 9 deletions(-) diff --git a/.github/workflows/checkin.yml b/.github/workflows/checkin.yml index 2febfde2..c897d9a1 100644 --- a/.github/workflows/checkin.yml +++ b/.github/workflows/checkin.yml @@ -5,7 +5,7 @@ jobs: check_pr: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: "npm ci" run: npm ci diff --git a/.github/workflows/selftest.yml b/.github/workflows/selftest.yml index c8f8c5e2..08be3bc6 100644 --- a/.github/workflows/selftest.yml +++ b/.github/workflows/selftest.yml @@ -19,6 +19,16 @@ jobs: - nightly - source - stable + msys2: [true, false] + exclude: + - os: macos-12 + msys2: true + - os: macos-14 + msys2: true + - os: macos-stable + msys2: true + - os: ubuntu-latest + msys2: true runs-on: ${{ matrix.os }} @@ -31,6 +41,7 @@ jobs: if: matrix.target == 'stable' uses: ./ # This uses the action code in the current PR with: + msys2: ${{ matrix.msys2 }} cache: false # We test without cache, as caching is tested in a separate workflow. # This way we make sure the cache isn't hiding any issue. @@ -39,6 +50,7 @@ jobs: if: matrix.target == 'nightly' uses: ./ with: + msys2: ${{ matrix.msys2 }} version: nightly cache: false @@ -46,6 +58,7 @@ jobs: if: matrix.target == 'source' uses: ./ with: + msys2: ${{ matrix.msys2 }} branch: master cache: false @@ -80,3 +93,13 @@ jobs: - run: alr -n version | grep "arch:" | grep AARCH64 if: runner.arch == 'ARM64' shell: bash + + # Verify proper msys2 behavior + + - run: alr -n version | grep "distribution:" | grep MSYS2 + if: matrix.os == 'windows-latest' && matrix.msys2 == true + shell: bash + + - run: alr -n version | grep "distribution:" | grep UNKNOWN + if: matrix.os == 'windows-latest' && matrix.msys2 == false + shell: bash diff --git a/.github/workflows/test-cache.yml b/.github/workflows/test-cache.yml index 038e5529..3c6f6f41 100644 --- a/.github/workflows/test-cache.yml +++ b/.github/workflows/test-cache.yml @@ -24,12 +24,29 @@ jobs: branch: '' - version: '' branch: 'master' + msys2: + - true + - false # Exclude combos that do not make sense (we dont have aarm64 for 1.2.2) exclude: - os: macos-14 config: {version: '1.2.2', branch: ''} - os: macos-latest config: {version: '1.2.2', branch: ''} + - os: windows-latest + config: {version: '1.2.2'} + msys2: false # We don't have the option to disable install on 1.2.2 + + # We don't exclude the following because this way we verify that the + # same cache is used for both msys2 true and false on non-Windows. + # - os: macos-12 + # msys2: true + # - os: macos-14 + # msys2: true + # - os: macos-stable + # msys2: true + # - os: ubuntu-latest + # msys2: true runs-on: ${{ matrix.os }} @@ -44,7 +61,8 @@ jobs: uses: ./ with: version: ${{matrix.config.version}} - branch: ${{matrix.config.branch}} + branch: ${{matrix.config.branch}} + msys2: ${{ matrix.msys2 }} # Next attemp should hit cache given the previous run @@ -54,7 +72,8 @@ jobs: uses: ./ with: version: ${{matrix.config.version}} - branch: ${{matrix.config.branch}} + branch: ${{matrix.config.branch}} + msys2: ${{ matrix.msys2 }} - name: Diagnose cache use shell: bash @@ -77,7 +96,7 @@ jobs: alr exec -- gnat --version alr exec -- gprbuild --version - # Verify proper builds + # Verify proper OS - run: alr -n version | grep "os:" | grep LINUX if: matrix.os == 'ubuntu-latest' shell: bash @@ -89,3 +108,23 @@ jobs: - run: alr -n version | grep "os:" | grep WINDOWS if: matrix.os == 'windows-latest' shell: bash + + # Verify proper architecture + + - run: alr -n version | grep "arch:" | grep X86_64 + if: runner.arch == 'X64' + shell: bash + + - run: alr -n version | grep "arch:" | grep AARCH64 + if: runner.arch == 'ARM64' + shell: bash + + # Verify proper msys2 behavior + + - run: alr -n version | grep "distribution:" | grep MSYS2 + if: matrix.os == 'windows-latest' && matrix.msys2 == true + shell: bash + + - run: alr -n version | grep "distribution:" | grep UNKNOWN + if: matrix.os == 'windows-latest' && matrix.msys2 == false + shell: bash diff --git a/README.md b/README.md index 69928686..fcdf83db 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,10 @@ inputs: description: Arguments to pass to `alr toolchain` after setup. required: false default: 'gnat_native gprbuild' - toolchain_dir: - description: Location to install the toolchain under. + msys2: + description: Whether to install MSYS2 on Windows. When false, `msys2.do_not_install` will be set to true in alr's settings. required: false - default: '' + default: true cache: description: Whether to reuse a cached previous install. required: false diff --git a/action.yml b/action.yml index 58f3b777..01e885e4 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,10 @@ inputs: description: Arguments to pass to `alr toolchain` after setup. required: false default: 'gnat_native gprbuild' + msys2: + description: Whether to install MSYS2 on Windows. When false, `msys2.do_not_install` will be set to true in alr's settings. + required: false + default: true cache: description: Whether to reuse a cached previous install. required: false @@ -46,11 +50,22 @@ runs: echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT fi + # This saves us duplicating caches for msys2 and non-msys2 on non-Windows + - name: Override msys2 for non-Windows platforms + id: override + shell: bash + run: | + if [[ "${{ runner.os }}" == "Windows" ]]; then + echo "msys2=${{ inputs.msys2 }}" >> $GITHUB_OUTPUT + else + echo "msys2=false" >> $GITHUB_OUTPUT + fi + - name: Generate cache key id: cache-key shell: bash run: | - echo "key=alr[1][${{ steps.find-hash.outputs.version }}][${{ inputs.toolchain }}][${{ runner.os }}][${{ runner.arch }}][${{ steps.find-hash.outputs.hash }}]" >> $GITHUB_OUTPUT + echo "key=alr[1][${{steps.find-hash.outputs.version}}][${{inputs.toolchain}}][msys2=${{steps.override.outputs.msys2}}][${{runner.os}}][${{runner.arch}}][${{steps.find-hash.outputs.hash}}]" >> $GITHUB_OUTPUT # The first value in square brackets is to make the key unique for debugging - name: Reuse cached installation @@ -107,7 +122,8 @@ runs: shell: bash run: echo "need=true" >> $GITHUB_OUTPUT - # Download a stable alr capable of installing a toolchain + # Download a stable alr capable of installing a toolchain. Avoid to install + # a msys2 at this point which is not needed and confuses later tests. - name: Install GNAT (I) if: steps.need-GNAT.outputs.need == 'true' shell: bash @@ -124,6 +140,8 @@ runs: unzip -o ${alr_filename} "bin/alr*" -d tmp_alr rm ${alr_filename} echo "$(pwd -W 2>/dev/null || pwd)/tmp_alr/bin" >> $GITHUB_PATH + tmp_alr/bin/alr settings --global --set msys2.do_not_install true || \ + tmp_alr/bin/alr config --global --set msys2.do_not_install true # Perform the actual `alr install` and remove the `alr` just used to avoid # conflicts with the `alr` being built. diff --git a/lib/main.js b/lib/main.js index 576984ff..41c88069 100644 --- a/lib/main.js +++ b/lib/main.js @@ -136,19 +136,31 @@ function run() { try { var version; var branch; + var msys2; var tool_args; if (process.argv[2]) { // e.g., node lib/script.js const inputs = JSON.parse(process.argv[2]); + // Log the inputs for the record + console.log("Inputs: " + process.argv[2]); version = inputs.version; branch = inputs.branch; + msys2 = inputs.msys2 == "true"; tool_args = inputs.toolchain; } else { // Old way in case this is fixed by GH version = core.getInput('version'); branch = core.getInput('branch'); + msys2 = core.getInput('msys2') == "true"; tool_args = core.getInput('toolchain'); } + // Identify the major version number to choose between config/settings + const major = parseInt(version.split(".")[0], 10); + const settings_cmd = (major >= 2 ? "settings" : "config"); + // Fail if version <2 and msys2=false (we cannot honor that) + if (major < 2 && !msys2 && process.platform == "win32") { + throw new Error("MSYS2 installation is mandatory for alr<2.0"); + } // Install the requested version/branch unless cached const cached = detect_cached(); if (!cached) { @@ -168,6 +180,18 @@ function run() { yield exec.exec(`alr -n settings --global --set index.auto_update_asked true`); console.log("Enabled index auto-refresh without further asking."); } + // Disable msys2 installation if requested + if (process.platform == "win32") { + if (msys2) { + // Re-enable in case it was disabled during previous actions steps + yield exec.exec(`alr -n ${settings_cmd} --global --set msys2.do_not_install false`); + console.log(`MSYS2 installation NOT disabled (msys2=${msys2})`); + } + else { + yield exec.exec(`alr -n ${settings_cmd} --global --set msys2.do_not_install true`); + console.log(`MSYS2 installation DISABLED (msys2=${msys2})`); + } + } // And configure the toolchain if (tool_args.length > 0 && !cached) { yield exec.exec(`alr -n toolchain ${tool_args != "--disable-assistant" ? "--select " : ""} ${tool_args}`); diff --git a/src/main.ts b/src/main.ts index e6ea1336..3742a958 100644 --- a/src/main.ts +++ b/src/main.ts @@ -113,20 +113,36 @@ async function run() { try { var version : string var branch : string + var msys2 : boolean var tool_args : string if (process.argv[2]) { // e.g., node lib/script.js const inputs = JSON.parse(process.argv[2]) + + // Log the inputs for the record + console.log("Inputs: " + process.argv[2]) + version = inputs.version branch = inputs.branch + msys2 = inputs.msys2 == "true"; tool_args = inputs.toolchain } else { // Old way in case this is fixed by GH version = core.getInput('version'); branch = core.getInput('branch'); + msys2 = core.getInput('msys2') == "true"; tool_args = core.getInput('toolchain'); } + // Identify the major version number to choose between config/settings + const major : number = parseInt(version.split(".")[0], 10); + const settings_cmd : string = (major >= 2 ? "settings" : "config"); + + // Fail if version <2 and msys2=false (we cannot honor that) + if (major < 2 && !msys2 && process.platform == "win32") { + throw new Error("MSYS2 installation is mandatory for alr<2.0"); + } + // Install the requested version/branch unless cached const cached : boolean = detect_cached() @@ -150,6 +166,18 @@ async function run() { console.log("Enabled index auto-refresh without further asking."); } + // Disable msys2 installation if requested + if (process.platform == "win32") { + if (msys2) { + // Re-enable in case it was disabled during previous actions steps + await exec.exec(`alr -n ${settings_cmd} --global --set msys2.do_not_install false`); + console.log(`MSYS2 installation NOT disabled (msys2=${msys2})`); + } else { + await exec.exec(`alr -n ${settings_cmd} --global --set msys2.do_not_install true`); + console.log(`MSYS2 installation DISABLED (msys2=${msys2})`); + } + } + // And configure the toolchain if (tool_args.length > 0 && !cached) { await exec.exec(`alr -n toolchain ${tool_args != "--disable-assistant" ? "--select " : ""} ${tool_args}`);