Skip to content

Commit

Permalink
Add Alpine (apk package manager) native install support (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored May 4, 2023
1 parent ca3acd2 commit 572582a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ async function installCcacheMac() : Promise<void> {
}

async function installCcacheLinux() : Promise<void> {
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<void> {
Expand Down Expand Up @@ -106,7 +110,7 @@ async function installSccacheWindows() : Promise<void> {
}

async function execBash(cmd : string) {
await exec.exec("bash", ["-xc", cmd]);
await exec.exec("sh", ["-xc", cmd]);
}

async function execBashSudo(cmd : string) {
Expand Down

0 comments on commit 572582a

Please sign in to comment.