Skip to content

Commit

Permalink
alpine linux support (#100)
Browse files Browse the repository at this point in the history
* detect linux distro and use apk for alpine
  • Loading branch information
umegaya committed Dec 5, 2021
1 parent 80a9fae commit b926bc4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
27 changes: 25 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10243,11 +10243,13 @@ var external_child_process_ = __nccwpck_require__(3129);




/**
* @param {string} cmd
* @returns {Promise<string>}
*/
const execShellCommand = (cmd) => {
core.debug(`Executing shell command: [${cmd}]`)
return new Promise((resolve, reject) => {
const proc = process.platform !== "win32" ?
(0,external_child_process_.spawn)(cmd, [], { shell: true }) :
Expand Down Expand Up @@ -10290,6 +10292,20 @@ const getValidatedInput = (key) => {
return value;
}


/**
* @return {Promise<string>}
*/
const getLinuxDistro = async () => {
try {
const osRelease = await external_fs_default().promises.readFile("/etc/os-release")
const match = osRelease.toString().match(/^ID=(.*)$/m)
return match ? match[1] : "(unknown)"
} catch (e) {
return "(unknown)"
}
}

;// CONCATENATED MODULE: ./src/index.js
// @ts-check

Expand Down Expand Up @@ -10328,8 +10344,15 @@ async function run() {
await execShellCommand('pacman -Sy --noconfirm tmate');
tmateExecutable = 'CHERE_INVOKING=1 tmate'
} else {
await execShellCommand(optionalSudoPrefix + 'apt-get update');
await execShellCommand(optionalSudoPrefix + 'apt-get install -y openssh-client xz-utils');
const distro = await getLinuxDistro();
core.debug("linux distro: [" + distro + "]");
if (distro === "alpine") {
// for set -e workaround, we need to install bash because alpine doesn't have it
await execShellCommand(optionalSudoPrefix + 'apk add openssh-client xz bash');
} else {
await execShellCommand(optionalSudoPrefix + 'apt-get update');
await execShellCommand(optionalSudoPrefix + 'apt-get install -y openssh-client xz-utils');
}

const tmateArch = TMATE_ARCH_MAP[external_os_default().arch()];
if (!tmateArch) {
Expand Down
16 changes: 16 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// @ts-check
import { spawn } from 'child_process'
import * as core from "@actions/core"
import fs from 'fs'

/**
* @param {string} cmd
* @returns {Promise<string>}
*/
export const execShellCommand = (cmd) => {
core.debug(`Executing shell command: [${cmd}]`)
return new Promise((resolve, reject) => {
const proc = process.platform !== "win32" ?
spawn(cmd, [], { shell: true }) :
Expand Down Expand Up @@ -48,3 +50,17 @@ export const getValidatedInput = (key) => {
}
return value;
}


/**
* @return {Promise<string>}
*/
export const getLinuxDistro = async () => {
try {
const osRelease = await fs.promises.readFile("/etc/os-release")
const match = osRelease.toString().match(/^ID=(.*)$/m)
return match ? match[1] : "(unknown)"
} catch (e) {
return "(unknown)"
}
}
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as github from "@actions/github"
import * as tc from "@actions/tool-cache"
import { Octokit } from "@octokit/rest"

import { execShellCommand, getValidatedInput } from "./helpers"
import { execShellCommand, getValidatedInput, getLinuxDistro } from "./helpers"

const TMATE_LINUX_VERSION = "2.4.0"

Expand Down Expand Up @@ -35,8 +35,15 @@ export async function run() {
await execShellCommand('pacman -Sy --noconfirm tmate');
tmateExecutable = 'CHERE_INVOKING=1 tmate'
} else {
await execShellCommand(optionalSudoPrefix + 'apt-get update');
await execShellCommand(optionalSudoPrefix + 'apt-get install -y openssh-client xz-utils');
const distro = await getLinuxDistro();
core.debug("linux distro: [" + distro + "]");
if (distro === "alpine") {
// for set -e workaround, we need to install bash because alpine doesn't have it
await execShellCommand(optionalSudoPrefix + 'apk add openssh-client xz bash');
} else {
await execShellCommand(optionalSudoPrefix + 'apt-get update');
await execShellCommand(optionalSudoPrefix + 'apt-get install -y openssh-client xz-utils');
}

const tmateArch = TMATE_ARCH_MAP[os.arch()];
if (!tmateArch) {
Expand Down

0 comments on commit b926bc4

Please sign in to comment.