diff --git a/.github/workflows/selftest.macos-13.yml b/.github/workflows/selftest.macos-13.yml index ae42cfd..25a2d6d 100644 --- a/.github/workflows/selftest.macos-13.yml +++ b/.github/workflows/selftest.macos-13.yml @@ -5,7 +5,7 @@ on: - cron: 0 0 1 * * push: branches: - - selftest + - update jobs: build: name: ${{ matrix.os }} / GHC ${{ matrix.ghc }} @@ -21,58 +21,9 @@ jobs: - run: cabal install alex - run: alex --version strategy: + fail-fast: false matrix: os: - macos-13 ghc: - - 7.10.3 - - 8.0.2 - - 8.2.2 - - 8.4.1 - - 8.4.2 - - 8.4.3 - - 8.4.4 - - 8.6.1 - - 8.6.2 - - 8.6.3 - - 8.6.4 - - 8.6.5 - - 8.8.1 - - 8.8.2 - - 8.8.3 - - 8.8.4 - - 8.10.1 - - 8.10.2 - - 8.10.3 - - 8.10.4 - - 8.10.5 - - 8.10.6 - - 8.10.7 - - 9.0.1 - - 9.0.2 - - 9.2.1 - - 9.2.2 - - 9.2.3 - - 9.2.4 - - 9.2.5 - - 9.2.6 - - 9.2.7 - - 9.2.8 - - 9.4.1 - - 9.4.2 - - 9.4.3 - - 9.4.4 - - 9.4.5 - - 9.4.6 - - 9.4.7 - - 9.4.8 - - 9.6.1 - - 9.6.2 - - 9.6.3 - - 9.6.4 - - 9.6.5 - - 9.6.6 - - 9.8.1 - 9.8.2 - - 9.8.4 - - 9.10.1 diff --git a/.github/workflows/selftest.macos-14.yml b/.github/workflows/selftest.macos-14.yml index d0bd0b0..7ce50ad 100644 --- a/.github/workflows/selftest.macos-14.yml +++ b/.github/workflows/selftest.macos-14.yml @@ -21,6 +21,7 @@ jobs: - run: cabal install alex - run: alex --version strategy: + fail-fast: false matrix: os: - macos-14 diff --git a/.github/workflows/selftest.macos-15.yml b/.github/workflows/selftest.macos-15.yml index b90909c..90f5c02 100644 --- a/.github/workflows/selftest.macos-15.yml +++ b/.github/workflows/selftest.macos-15.yml @@ -21,6 +21,7 @@ jobs: - run: cabal install alex - run: alex --version strategy: + fail-fast: false matrix: os: - macos-15 diff --git a/.github/workflows/selftest.ubuntu-20.04.yml b/.github/workflows/selftest.ubuntu-20.04.yml index 6702c17..ec150bf 100644 --- a/.github/workflows/selftest.ubuntu-20.04.yml +++ b/.github/workflows/selftest.ubuntu-20.04.yml @@ -21,6 +21,7 @@ jobs: - run: cabal install alex - run: alex --version strategy: + fail-fast: false matrix: os: - ubuntu-20.04 diff --git a/.github/workflows/selftest.ubuntu-22.04.yml b/.github/workflows/selftest.ubuntu-22.04.yml index 0c2761a..846d662 100644 --- a/.github/workflows/selftest.ubuntu-22.04.yml +++ b/.github/workflows/selftest.ubuntu-22.04.yml @@ -21,6 +21,7 @@ jobs: - run: cabal install alex - run: alex --version strategy: + fail-fast: false matrix: os: - ubuntu-22.04 diff --git a/.github/workflows/selftest.ubuntu-24.04.yml b/.github/workflows/selftest.ubuntu-24.04.yml index b7ec1ef..86bfacf 100644 --- a/.github/workflows/selftest.ubuntu-24.04.yml +++ b/.github/workflows/selftest.ubuntu-24.04.yml @@ -21,6 +21,7 @@ jobs: - run: cabal install alex - run: alex --version strategy: + fail-fast: false matrix: os: - ubuntu-24.04 diff --git a/.github/workflows/selftest.windows-2019.yml b/.github/workflows/selftest.windows-2019.yml index d23e9ed..4b03c56 100644 --- a/.github/workflows/selftest.windows-2019.yml +++ b/.github/workflows/selftest.windows-2019.yml @@ -21,6 +21,7 @@ jobs: - run: cabal install alex - run: alex --version strategy: + fail-fast: false matrix: os: - windows-2019 diff --git a/.github/workflows/selftest.windows-2022.yml b/.github/workflows/selftest.windows-2022.yml index 7f34b7c..28a53a8 100644 --- a/.github/workflows/selftest.windows-2022.yml +++ b/.github/workflows/selftest.windows-2022.yml @@ -21,6 +21,7 @@ jobs: - run: cabal install alex - run: alex --version strategy: + fail-fast: false matrix: os: - windows-2022 diff --git a/README.md b/README.md index 87b13bc..bf8b538 100644 --- a/README.md +++ b/README.md @@ -1,56 +1,56 @@ | | `ubuntu-20.04` | `ubuntu-22.04` | `ubuntu-24.04` | `macos-13` | `macos-14` | `macos-15` | `windows-2019` | `windows-2022` | | :----------------------- | :------------: | :------------: | :------------: | :--------: | :--------: | :--------: | :------------: | :------------: | -| `latest` `9.10` `9.10.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.8` `9.8.4` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| `latest` `9.10` `9.10.1` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.8` `9.8.4` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | | `9.8.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.8.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.6` `9.6.6` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.6.5` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.6.4` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.6.3` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.6.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.6.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.4` `9.4.8` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.4.7` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.4.6` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.4.5` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.4.4` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.4.3` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.4.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.4.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.2` `9.2.8` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.2.7` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.2.6` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.2.5` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.2.4` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.2.3` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.2.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.2.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.0` `9.0.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `9.0.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.10` `8.10.7` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.10.6` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.10.5` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.10.4` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.10.3` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.10.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.10.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.8` `8.8.4` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.8.3` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | ❌ | -| `8.8.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.8.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.6` `8.6.5` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.6.4` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.6.3` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.6.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.6.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.4` `8.4.4` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.4.3` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.4.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.4.1` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.2` `8.2.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `8.0` `8.0.2` | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | -| `7.10` `7.10.3` | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.8.1` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.6` `9.6.6` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.6.5` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.6.4` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.6.3` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.6.2` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.6.1` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.4` `9.4.8` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.4.7` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.4.6` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.4.5` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.4.4` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.4.3` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.4.2` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.4.1` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.2` `9.2.8` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.2.7` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.2.6` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.2.5` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.2.4` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.2.3` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.2.2` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.2.1` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.0` `9.0.2` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `9.0.1` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.10` `8.10.7` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.10.6` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.10.5` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.10.4` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.10.3` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.10.2` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.10.1` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.8` `8.8.4` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.8.3` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | ❌ | +| `8.8.2` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.8.1` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.6` `8.6.5` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.6.4` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.6.3` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.6.2` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.6.1` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.4` `8.4.4` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.4.3` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.4.2` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.4.1` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.2` `8.2.2` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `8.0` `8.0.2` | 🟢 | 🟢 | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | +| `7.10` `7.10.3` | 🟢 | ❌ | 🟢 | ❌ | 🟢 | 🟢 | 🟢 | 🟢 | | `7.4` `7.4.2` | 🟢 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | | `7.2` `7.2.2` | 🟢 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | | `7.0` `7.0.4` | 🟢 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | diff --git a/dist/index.js b/dist/index.js index 6bad9e4..1ff0335 100644 --- a/dist/index.js +++ b/dist/index.js @@ -105,10 +105,28 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.list = exports.install = void 0; +exports.list = exports.install = exports.ensure = void 0; const core = __importStar(__nccwpck_require__(186)); const exec_1 = __nccwpck_require__(514); const resolve_1 = __nccwpck_require__(778); +const io_1 = __nccwpck_require__(436); +async function ensure() { + if (!await (0, io_1.which)('ghcup')) { + await (0, exec_1.exec)('brew install ghcup'); + const home = process.env['HOME']; + if (home) { + core.addPath(home + '/.ghcup/bin/'); + } + } + if (!await (0, io_1.which)('cabal')) { + await (0, exec_1.exec)('ghcup install cabal latest --set'); + const result = await (0, exec_1.getExecOutput)('cabal', ['path', '-v0', '--installdir'], { + silent: true, + }); + core.addPath(result.stdout.trim()); + } +} +exports.ensure = ensure; async function install(version) { const older804 = (0, resolve_1.compareVersions)(version, '8.4') == -1; const ncursesRequired = older804 && process.env['ImageOS'] == 'ubuntu22'; @@ -119,7 +137,6 @@ async function install(version) { } await core.group('ghcup install', async () => { await (0, exec_1.exec)(`ghcup install ghc ${version} --set`); - core.addPath('$HOME/.ghcup/bin'); }); } exports.install = install; @@ -174,8 +191,8 @@ const ghcup = __importStar(__nccwpck_require__(474)); const resolve_1 = __nccwpck_require__(778); async function main() { try { + await ghcup.ensure(); await workaroundRunnerImageIssue7061(); - await addCabalBinToPath(); const requested = core.getInput('ghc-version'); const version = await ensure(requested); core.setOutput('ghc-version', version); @@ -198,12 +215,6 @@ async function workaroundRunnerImageIssue7061() { } }); } -async function addCabalBinToPath() { - const home = process.env['HOME']; - if (home) { - core.addPath(home + '/.cabal/bin/'); - } -} async function ensure(requested) { const resolved = await (0, resolve_1.resolve)(requested); await install(resolved); @@ -275,6 +286,7 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.installed = exports.resolve = exports.resolveVersion = exports.compareVersions = void 0; const exec_1 = __nccwpck_require__(514); +const io_1 = __nccwpck_require__(436); const apt = __importStar(__nccwpck_require__(911)); const ghcup = __importStar(__nccwpck_require__(474)); function compareVersions(a, b) { @@ -307,19 +319,27 @@ function resolveVersion(requested, versions) { } } exports.resolveVersion = resolveVersion; +async function resolveFoo(requested) { + const versions = new Set([...apt.versions(), ...await ghcup.list()]); + return resolveVersion(requested, versions); +} async function resolve(requested) { const systemVersion = await installed(); const aptVersions = apt.versions(); let version; if (requested === 'system') { - version = systemVersion; + if (systemVersion) { + version = systemVersion; + } + else { + version = await resolveFoo('latest'); + } } else if (apt.versions().has(requested)) { version = requested; } else { - const versions = new Set([...apt.versions(), ...await ghcup.list()]); - version = resolveVersion(requested, versions); + version = await resolveFoo(requested); } if (version) { const source = version === systemVersion ? 'system' : @@ -335,10 +355,15 @@ async function resolve(requested) { } exports.resolve = resolve; async function installed() { - const result = await (0, exec_1.getExecOutput)('ghc', ['--numeric-version'], { - silent: true, - }); - return result.stdout.trim(); + if (await (0, io_1.which)('ghc')) { + const result = await (0, exec_1.getExecOutput)('ghc', ['--numeric-version'], { + silent: true, + }); + return result.stdout.trim(); + } + else { + return undefined; + } } exports.installed = installed; diff --git a/generate/selftest.ts b/generate/selftest.ts index 58f253d..199ed58 100644 --- a/generate/selftest.ts +++ b/generate/selftest.ts @@ -19,7 +19,7 @@ export async function versionMap() { 'ubuntu-20.04': new Set([...ppa.ubuntu20, ...ghcup]), 'ubuntu-22.04': new Set([...ghcup].filter(v => !not_working_on_ubuntu_22_04.has(v))), 'ubuntu-24.04': ghcup, - 'macos-13': ghcup, + 'macos-13': new Set(['9.8.2']), 'macos-14': ghcup, 'macos-15': ghcup, 'windows-2019': ghcup, diff --git a/src/ghcup.ts b/src/ghcup.ts index f4bcb59..6b04e6b 100644 --- a/src/ghcup.ts +++ b/src/ghcup.ts @@ -1,6 +1,24 @@ import * as core from '@actions/core'; import { exec, getExecOutput } from '@actions/exec'; import { compareVersions } from './resolve'; +import { which } from '@actions/io'; + +export async function ensure() { + if (!await which('ghcup')) { + await exec('brew install ghcup'); + const home = process.env['HOME']; + if (home) { + core.addPath(home + '/.ghcup/bin/'); + } + } + if (!await which('cabal')) { + await exec('ghcup install cabal latest --set'); + const result = await getExecOutput('cabal', ['path', '-v0', '--installdir'], { + silent: true, + }); + core.addPath(result.stdout.trim()); + } +} export async function install(version: string) { const older804 = compareVersions(version, '8.4') == -1; @@ -12,7 +30,6 @@ export async function install(version: string) { } await core.group('ghcup install', async () => { await exec(`ghcup install ghc ${version} --set`); - core.addPath('$HOME/.ghcup/bin'); }); } diff --git a/src/main.ts b/src/main.ts index 5c70559..dbb2f5f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,8 +8,8 @@ import { installed, resolve, ResolvedVersion } from './resolve'; async function main() { try { + await ghcup.ensure(); await workaroundRunnerImageIssue7061(); - await addCabalBinToPath(); const requested = core.getInput('ghc-version'); const version = await ensure(requested); core.setOutput('ghc-version', version); @@ -32,13 +32,6 @@ async function workaroundRunnerImageIssue7061() { }); } -async function addCabalBinToPath() { - const home = process.env['HOME']; - if (home) { - core.addPath(home + '/.cabal/bin/'); - } -} - async function ensure(requested: string): Promise { const resolved = await resolve(requested); await install(resolved); diff --git a/src/resolve.ts b/src/resolve.ts index 43eeb0b..34c3473 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -1,4 +1,5 @@ import { getExecOutput } from '@actions/exec'; +import { which } from '@actions/io'; import * as apt from './apt'; import * as ghcup from './ghcup'; @@ -39,18 +40,26 @@ export type ResolvedVersion = { source: 'system' | 'apt' | 'ghcup'; }; +async function resolveFoo(requested: string): Promise { + const versions = new Set([...apt.versions(), ...await ghcup.list()]); + return resolveVersion(requested, versions); +} + export async function resolve(requested: string): Promise { const systemVersion = await installed(); const aptVersions = apt.versions(); let version; if (requested === 'system') { - version = systemVersion; + if (systemVersion) { + version = systemVersion; + } else { + version = await resolveFoo('latest'); + } } else if (apt.versions().has(requested)) { version = requested; } else { - const versions = new Set([...apt.versions(), ...await ghcup.list()]); - version = resolveVersion(requested, versions); + version = await resolveFoo(requested); } if (version) { @@ -65,9 +74,13 @@ export async function resolve(requested: string): Promise { } } -export async function installed(): Promise { - const result = await getExecOutput('ghc', ['--numeric-version'], { - silent: true, - }); - return result.stdout.trim(); +export async function installed(): Promise { + if (await which('ghc')) { + const result = await getExecOutput('ghc', ['--numeric-version'], { + silent: true, + }); + return result.stdout.trim(); + } else { + return undefined; + } }