Skip to content

Commit d34b955

Browse files
committed
feat: support community repo for alpine
1 parent ae24e96 commit d34b955

File tree

6 files changed

+37
-15
lines changed

6 files changed

+37
-15
lines changed

dist/legacy/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { execRoot } from "admina"
2-
import { info, warning } from "ci-log"
1+
import { info } from "ci-log"
2+
import { appendFile, readFile } from "fs/promises"
33
import { pathExists } from "path-exists"
44
import { hasApk } from "./has-apk.js"
5+
import { updateApkMemoized } from "./update.js"
56

67
/**
78
* Add an APK repository
@@ -11,29 +12,49 @@ import { hasApk } from "./has-apk.js"
1112

1213
export async function addApkRepository(repoUrl: string): Promise<boolean> {
1314
if (!(await hasApk())) {
14-
warning("apk is not available on this system")
15-
return false
15+
throw new Error("apk is not available on this system")
1616
}
1717

1818
try {
1919
// Check if repositories file exists
2020
const reposFile = "/etc/apk/repositories"
2121
if (!(await pathExists(reposFile))) {
22-
warning(`APK repositories file not found at ${reposFile}`)
23-
return false
22+
throw new Error(`APK repositories file not found at ${reposFile}`)
2423
}
2524

2625
// Add repository to the file
2726
info(`Adding repository: ${repoUrl}`)
28-
await execRoot("sh", ["-c", `echo "${repoUrl}" >> ${reposFile}`])
27+
await appendFile(reposFile, `${repoUrl}\n`)
2928

3029
// Update package index after adding repository
31-
await execRoot("apk", ["update"])
30+
await updateApkMemoized.clear()
31+
await updateApkMemoized()
3232

3333
info(`Successfully added repository: ${repoUrl}`)
3434
return true
3535
} catch (error) {
36-
warning(`Failed to add repository ${repoUrl}: ${error}`)
37-
return false
36+
throw new Error(`Failed to add repository ${repoUrl}: ${error}`)
3837
}
3938
}
39+
40+
/**
41+
* Enable the community repository
42+
* @returns Whether the repository was added successfully
43+
*/
44+
export async function enableCommunityRepository() {
45+
const alpineVersion = (await getAlpineVersion()).split(".").slice(0, 2).join(".")
46+
47+
return addApkRepository(`https://dl-cdn.alpinelinux.org/alpine/v${alpineVersion}/community/`)
48+
}
49+
50+
/**
51+
* Get the Alpine version
52+
* @returns The Alpine version
53+
*/
54+
export async function getAlpineVersion() {
55+
const releaseFile = "/etc/alpine-release"
56+
if (!(await pathExists(releaseFile))) {
57+
throw new Error(`Alpine release file not found at ${releaseFile}`)
58+
}
59+
return readFile(releaseFile, "utf8")
60+
}

src/gcc/mingw.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { pathExists } from "path-exists"
88
import { addExeExt } from "patha"
99
import semverCoerce from "semver/functions/coerce.js"
1010
import semverSatisfies from "semver/functions/satisfies.js"
11-
import { hasApk, installApkPack } from "setup-alpine"
11+
import { enableCommunityRepository, hasApk, installApkPack } from "setup-alpine"
1212
import { installAptPack } from "setup-apt"
1313
import { rcOptions } from "../cli-options.js"
1414
import { loadAssetList, matchAsset } from "../utils/asset/load-assets.js"
@@ -47,6 +47,7 @@ export async function setupMingw(version: string, setupDir: string, arch: string
4747
} else if (isUbuntu()) {
4848
installationInfo = await installAptPack([{ name: "mingw-w64", version }])
4949
} else if (await hasApk()) {
50+
await enableCommunityRepository()
5051
installationInfo = await installApkPack([
5152
{ name: "mingw-w64-gcc", version },
5253
{ name: "mingw-w64-crt", version },

0 commit comments

Comments
 (0)