From 392cf345b1784333caa1a1185081c71e6ffd61bc Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 22 Feb 2024 10:25:42 +0000 Subject: [PATCH] Enable ARM64 on macOS for Miniforge and Mambaforge. (#331) --- .github/workflows/example-13.yml | 75 +++++++++++++++++++++++++++++ CHANGELOG.md | 19 ++++++++ README.md | 30 ++++++++++++ action.yml | 7 +-- dist/setup/index.js | 9 ++-- src/input.ts | 9 ++-- src/installer/download-miniforge.ts | 3 +- 7 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/example-13.yml diff --git a/.github/workflows/example-13.yml b/.github/workflows/example-13.yml new file mode 100644 index 00000000..254083de --- /dev/null +++ b/.github/workflows/example-13.yml @@ -0,0 +1,75 @@ +name: "Example 13: Apple Silicon" + +on: + pull_request: + branches: + - "*" + push: + branches: + - "develop" + - "main" + - "master" + schedule: + # Note that cronjobs run on master/main by default + - cron: "0 0 * * *" + +jobs: + example-13: + # prevent cronjobs from running on forks + if: + (github.event_name == 'schedule' && github.repository == + 'conda-incubator/setup-miniconda') || (github.event_name != 'schedule') + name: Ex13 (os=${{ matrix.os }} variant=${{ matrix.variant }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ["macos-14"] + variant: ["Miniforge3", "Mambaforge", "Miniconda", "no-variant"] + steps: + - uses: actions/checkout@v4 + - uses: ./ + if: matrix.variant == 'Miniforge3' || matrix.variant == 'Mambaforge' + id: setup-miniforge + continue-on-error: true + with: + auto-update-conda: true + architecture: arm64 + miniforge-variant: ${{ matrix.variant }} + miniforge-version: latest + - uses: ./ + if: matrix.variant == 'Miniconda' + id: setup-miniconda + continue-on-error: true + with: + auto-update-conda: true + miniconda-version: latest + - uses: ./ + if: matrix.variant == 'no-variant' + id: setup-miniconda2 + continue-on-error: true + with: + miniforge-version: latest + - name: Conda info + shell: bash -el {0} + run: conda info + - name: Conda list + shell: bash -el {0} + run: conda list + - name: Environment + shell: bash -el {0} + run: printenv | sort + - name: Create an environment + shell: bash -el {0} + run: conda create -n unused --dry-run zlib + - name: Run mamba + if: matrix.variant != 'Miniconda' + shell: bash -el {0} + run: mamba --version + - name: Install Python + shell: bash -el {0} + run: conda install -y python + - name: Check arm64 + shell: bash -el {0} + run: | + python -c "import platform; assert platform.machine() == 'arm64', platform.machine()" diff --git a/CHANGELOG.md b/CHANGELOG.md index 38fa3912..82956155 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # CHANGELOG +## [v3.0.2] (2024-02-22) + +### Fixes + +- [#312] Enable ARM64 on macOS for Miniforge and Mambaforge including automatic + architecture detection. + +### Tasks and Maintenance + +- [#327] Bump conda-incubator/setup-miniconda from 3.0.0 to 3.0.1 +- [#330] Bump actions/cache from 3 to 4 +- [#334] Bump undici from 5.27.2 to 5.28.3 + +[v3.0.2]: https://github.com/conda-incubator/setup-miniconda/releases/tag/v3.0.2 +[#312]: https://github.com/conda-incubator/setup-miniconda/pull/312 +[#327]: https://github.com/conda-incubator/setup-miniconda/pull/327 +[#330]: https://github.com/conda-incubator/setup-miniconda/pull/330 +[#334]: https://github.com/conda-incubator/setup-miniconda/pull/334 + ## [v3.0.1] (2023-11-29) ### Fixes diff --git a/README.md b/README.md index bbca09c4..bfa89246 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ possibility of automatically activating the `test` environment on all shells. | [Configure conda solver](#example-12-configure-conda-solver) | [![Configure conda solver][ex12-badge]][ex12] | | [Caching packages](#caching-packages) | [![Caching Example Status][caching-badge]][caching] | | [Caching environments](#caching-environments) | [![Caching Env Example Status][caching-env-badge]][caching-env] | +| [Apple Silicon](#example-13-apple-silicon) | [![Apple Silicon][ex13-badge]][ex13] | [ex1]: https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-1.yml @@ -107,6 +108,10 @@ possibility of automatically activating the `test` environment on all shells. https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-12.yml [ex12-badge]: https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-12.yml/badge.svg?branch=main +[ex13]: + https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-13.yml +[ex13-badge]: + https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-13.yml/badge.svg?branch=main ## Other Workflows @@ -596,6 +601,31 @@ jobs: python-version: "3.9" ``` +### Example 13: Apple Silicon + +```yaml +jobs: + example-13: + name: Ex13 (os=${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ["macos-14"] + steps: + - uses: actions/checkout@v4 + - uses: ./ + id: setup-miniconda + continue-on-error: true + with: + miniconda-version: latest + - name: Check arm64 + shell: bash -el {0} + run: | + conda install -y python + python -c "import platform; assert platform.machine() == 'arm64', platform.machine()" +``` + ## Caching ### Caching packages diff --git a/action.yml b/action.yml index 05e32346..2ec29f7c 100644 --- a/action.yml +++ b/action.yml @@ -242,10 +242,11 @@ inputs: default: "libmamba" architecture: description: - 'Architecture of Miniconda that should be installed. Default is "x64". The - CPU architecture of the runner is not detected by the workflow.' + 'Architecture of Miniconda that should be installed. This is automatically + detected by the runner. If you want to override it, you can use "x64", + "x86", "arm64", "aarch64", "s390x".' required: false - default: "x64" + default: "" clean-patched-environment-file: description: "Whether a patched environment-file (if created) should be cleaned" diff --git a/dist/setup/index.js b/dist/setup/index.js index 1a03e082..0bb7a264 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -48605,8 +48605,6 @@ const RULES = [ (i) => !!(i.installerUrl && !constants.KNOWN_EXTENSIONS.includes(urlExt(i.installerUrl))) && `'installer-url' extension '${urlExt(i.installerUrl)}' must be one of: ${constants.KNOWN_EXTENSIONS}`, - (i) => !!(!i.minicondaVersion && i.architecture !== "x64") && - `'architecture: ${i.architecture}' requires "miniconda-version"`, (i) => !!(i.architecture === "x86" && !constants.IS_WINDOWS) && `'architecture: ${i.architecture}' is only available for recent versions on Windows`, (i) => !!(!["latest", ""].includes(i.minicondaVersion) && @@ -48620,7 +48618,7 @@ function parseInputs() { return __awaiter(this, void 0, void 0, function* () { const inputs = Object.freeze({ activateEnvironment: core.getInput("activate-environment"), - architecture: core.getInput("architecture"), + architecture: core.getInput("architecture") || process.arch, condaBuildVersion: core.getInput("conda-build-version"), condaConfigFile: core.getInput("condarc-file"), condaVersion: core.getInput("conda-version"), @@ -48665,6 +48663,9 @@ function parseInputs() { if (errors.length) { throw Error(`${errors.length} errors found in action inputs`); } + if (core.isDebug()) { + core.info(JSON.stringify(inputs)); + } return inputs; }); } @@ -49009,7 +49010,7 @@ function downloadMiniforge(inputs, options) { return __awaiter(this, void 0, void 0, function* () { const tool = inputs.miniforgeVariant.trim() || constants.MINIFORGE_DEFAULT_VARIANT; const version = inputs.miniforgeVersion.trim() || constants.MINIFORGE_DEFAULT_VERSION; - const arch = constants.MINIFORGE_ARCHITECTURES[inputs.architecture]; + const arch = constants.MINIFORGE_ARCHITECTURES[inputs.architecture.toLowerCase()]; // Check valid arch if (!arch) { throw new Error(`Invalid 'architecture: ${inputs.architecture}'`); diff --git a/src/input.ts b/src/input.ts index 26eb3d6a..a605d80a 100644 --- a/src/input.ts +++ b/src/input.ts @@ -60,9 +60,6 @@ const RULES: IRule[] = [ `'installer-url' extension '${urlExt(i.installerUrl)}' must be one of: ${ constants.KNOWN_EXTENSIONS }`, - (i) => - !!(!i.minicondaVersion && i.architecture !== "x64") && - `'architecture: ${i.architecture}' requires "miniconda-version"`, ( i, // Miniconda x86 is only published for Windows lately (last Linux was 2019, last MacOS 2015) ) => @@ -84,7 +81,7 @@ const RULES: IRule[] = [ export async function parseInputs(): Promise { const inputs: types.IActionInputs = Object.freeze({ activateEnvironment: core.getInput("activate-environment"), - architecture: core.getInput("architecture"), + architecture: core.getInput("architecture") || process.arch, condaBuildVersion: core.getInput("conda-build-version"), condaConfigFile: core.getInput("condarc-file"), condaVersion: core.getInput("conda-version"), @@ -136,5 +133,9 @@ export async function parseInputs(): Promise { throw Error(`${errors.length} errors found in action inputs`); } + if (core.isDebug()) { + core.info(JSON.stringify(inputs)); + } + return inputs; } diff --git a/src/installer/download-miniforge.ts b/src/installer/download-miniforge.ts index 5bc7b19a..899cc3c0 100644 --- a/src/installer/download-miniforge.ts +++ b/src/installer/download-miniforge.ts @@ -16,7 +16,8 @@ export async function downloadMiniforge( inputs.miniforgeVariant.trim() || constants.MINIFORGE_DEFAULT_VARIANT; const version = inputs.miniforgeVersion.trim() || constants.MINIFORGE_DEFAULT_VERSION; - const arch = constants.MINIFORGE_ARCHITECTURES[inputs.architecture]; + const arch = + constants.MINIFORGE_ARCHITECTURES[inputs.architecture.toLowerCase()]; // Check valid arch if (!arch) {