From ffb33bd8bf47bdc1308723ca03d73d3711225037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 18 Apr 2023 12:57:16 +0200 Subject: [PATCH] Add Alpine (apk package manager) native install support --- .github/workflows/tests.yml | 13 ++++++++++++- dist/restore/index.js | 13 +++++++++---- src/restore.ts | 12 ++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8b795257..4a36921e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -163,7 +163,7 @@ jobs: run: | [[ ${{ steps.restore-keys.outputs.test-cache-hit }} = true ]] - test_docker: + test_docker_ubuntu: # Test that it works in a Docker container without sudo. runs-on: ubuntu-latest container: ubuntu:latest @@ -174,6 +174,17 @@ jobs: - name: Run ccache-action uses: ./ + test_docker_alpine: + # Test that it works in Alpine Docker container with apk package manager. + runs-on: ubuntu-latest + container: alpine:latest + steps: + - uses: actions/checkout@v2 + - run: apk update + shell: sh + - name: Run ccache-action + uses: ./ + test_option_save: # Test that the 'save' option is available. runs-on: ubuntu-latest diff --git a/dist/restore/index.js b/dist/restore/index.js index 850e79e0..5c1bb1c6 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -59426,10 +59426,15 @@ async function installCcacheMac() { await execBash("brew install ccache"); } async function installCcacheLinux() { - if (!await io.which("apt-get")) { - throw Error("Can't install ccache automatically under this platform, please install it yourself before using this action."); + if (await io.which("apt-get")) { + await execBashSudo("apt-get install -y ccache"); + return; + } + else if (await io.which("apk")) { + await execBash("apk add ccache"); + return; } - await execBashSudo("apt-get install -y ccache"); + throw Error("Can't install ccache automatically under this platform, please install it yourself before using this action."); } async function installCcacheWindows() { await installCcacheFromGitHub("4.7.4", "windows-x86_64", @@ -59450,7 +59455,7 @@ async function installSccacheWindows() { `${external_process_namespaceObject.env.USERPROFILE}\\.cargo\\bin`, "sccache.exe"); } async function execBash(cmd) { - await exec.exec("bash", ["-xc", cmd]); + await exec.exec("sh", ["-xc", cmd]); } async function execBashSudo(cmd) { await execBash("$(which sudo) " + cmd); diff --git a/src/restore.ts b/src/restore.ts index 022f6d19..9763b2a2 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -62,10 +62,14 @@ async function installCcacheMac() : Promise { } async function installCcacheLinux() : Promise { - if (!await io.which("apt-get")) { - throw Error("Can't install ccache automatically under this platform, please install it yourself before using this action.") + if (await io.which("apt-get")) { + await execBashSudo("apt-get install -y ccache"); + return; + } else if (await io.which("apk")) { + await execBash("apk add ccache"); + return; } - await execBashSudo("apt-get install -y ccache"); + throw Error("Can't install ccache automatically under this platform, please install it yourself before using this action."); } async function installCcacheWindows() : Promise { @@ -106,7 +110,7 @@ async function installSccacheWindows() : Promise { } async function execBash(cmd : string) { - await exec.exec("bash", ["-xc", cmd]); + await exec.exec("sh", ["-xc", cmd]); } async function execBashSudo(cmd : string) {