2020-03-26 09:34:31 +00:00
|
|
|
const core = require("@actions/core")
|
|
|
|
const exec = require("@actions/exec")
|
2024-01-05 17:50:29 +00:00
|
|
|
const io = require('@actions/io')
|
2020-03-26 09:34:31 +00:00
|
|
|
const firstline = require("firstline")
|
2020-03-26 12:26:07 +00:00
|
|
|
const path = require("path")
|
|
|
|
const fs = require("fs")
|
2020-03-26 09:34:31 +00:00
|
|
|
|
2020-11-12 16:35:42 +00:00
|
|
|
function getImageTag(imageName, distribution) {
|
|
|
|
if (imageName == "debian") {
|
|
|
|
return distribution.replace("UNRELEASED", "unstable")
|
|
|
|
.replace("-security", "")
|
|
|
|
} else {
|
|
|
|
return distribution.replace("UNRELEASED", "unstable")
|
|
|
|
.replace("-security", "")
|
|
|
|
.replace("-backports", "")
|
|
|
|
}
|
2020-03-26 14:37:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 16:35:42 +00:00
|
|
|
async function getImageName(distribution) {
|
|
|
|
const tag = getImageTag("", distribution)
|
|
|
|
for (const image of ["debian", "ubuntu"]) {
|
2022-10-27 07:58:09 +00:00
|
|
|
try {
|
2024-01-04 18:36:01 +00:00
|
|
|
const skopeoPath = await io.which('skopeo', true)
|
|
|
|
if (!skopeoPath) {
|
|
|
|
core.startGroup("Install skopeo")
|
|
|
|
await exec.exec("sudo", [
|
|
|
|
"apt-get",
|
|
|
|
"update"
|
|
|
|
])
|
|
|
|
await exec.exec("sudo", [
|
|
|
|
"apt-get",
|
|
|
|
"-y",
|
|
|
|
"install",
|
|
|
|
"skopeo"
|
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
}
|
2022-10-27 08:11:20 +00:00
|
|
|
core.startGroup("Get image name")
|
2022-10-27 07:58:09 +00:00
|
|
|
await exec.exec("skopeo", [
|
|
|
|
"inspect",
|
|
|
|
`docker://docker.io/library/${image}:${tag}`
|
|
|
|
])
|
2022-10-27 08:11:20 +00:00
|
|
|
core.endGroup()
|
2020-11-12 16:35:42 +00:00
|
|
|
return image
|
2022-10-27 07:58:09 +00:00
|
|
|
} catch {
|
|
|
|
continue
|
2020-03-26 14:37:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 09:34:31 +00:00
|
|
|
async function main() {
|
|
|
|
try {
|
2021-07-09 22:11:23 +00:00
|
|
|
const cpuArchitecture = core.getInput("cpu_architecture") || "amd64"
|
2020-07-25 10:29:47 +00:00
|
|
|
const sourceRelativeDirectory = core.getInput("source_directory") || "./"
|
|
|
|
const artifactsRelativeDirectory = core.getInput("artifacts_directory") || "./"
|
2021-07-09 21:54:49 +00:00
|
|
|
const osDistribution = core.getInput("os_distribution") || ""
|
2022-10-27 11:00:43 +00:00
|
|
|
const lintianOpts = core.getInput("lintian_opts") || ""
|
2022-10-28 09:22:24 +00:00
|
|
|
const lintianRun = core.getBooleanInput('lintian_run') || false
|
2020-03-26 09:34:31 +00:00
|
|
|
|
2020-03-26 12:26:07 +00:00
|
|
|
const workspaceDirectory = process.cwd()
|
2020-03-26 14:37:35 +00:00
|
|
|
const sourceDirectory = path.join(workspaceDirectory, sourceRelativeDirectory)
|
|
|
|
const buildDirectory = path.dirname(sourceDirectory)
|
|
|
|
const artifactsDirectory = path.join(workspaceDirectory, artifactsRelativeDirectory)
|
|
|
|
|
|
|
|
const file = path.join(sourceDirectory, "debian/changelog")
|
2020-03-26 09:34:31 +00:00
|
|
|
const changelog = await firstline(file)
|
2021-07-09 21:54:49 +00:00
|
|
|
const regex = /^(?<pkg>.+) \(((?<epoch>[0-9]+):)?(?<version>[^:-]+)(-(?<revision>[^:-]+))?\) (?<packageDistribution>.+);/
|
2020-03-26 09:34:31 +00:00
|
|
|
const match = changelog.match(regex)
|
2021-07-09 21:54:49 +00:00
|
|
|
const { pkg, epoch, version, revision, packageDistribution } = match.groups
|
|
|
|
const distribution = osDistribution ? osDistribution : packageDistribution
|
2020-11-12 16:35:42 +00:00
|
|
|
const imageName = await getImageName(distribution)
|
|
|
|
const imageTag = await getImageTag(imageName, distribution)
|
|
|
|
const container = pkg
|
|
|
|
const image = imageName + ":" + imageTag
|
2020-03-26 09:34:31 +00:00
|
|
|
|
2020-03-26 12:26:07 +00:00
|
|
|
fs.mkdirSync(artifactsDirectory, { recursive: true })
|
|
|
|
|
2020-03-26 15:04:59 +00:00
|
|
|
core.startGroup("Print details")
|
|
|
|
const details = {
|
2020-11-12 16:35:42 +00:00
|
|
|
pkg: pkg,
|
2020-03-26 17:39:23 +00:00
|
|
|
epoch: epoch,
|
2020-03-26 15:04:59 +00:00
|
|
|
version: version,
|
|
|
|
revision: revision,
|
2020-11-12 16:35:42 +00:00
|
|
|
distribution: distribution,
|
2021-07-09 22:22:23 +00:00
|
|
|
arch: cpuArchitecture,
|
2020-03-26 15:04:59 +00:00
|
|
|
image: image,
|
2020-11-12 16:35:42 +00:00
|
|
|
container: container,
|
2020-03-26 15:04:59 +00:00
|
|
|
workspaceDirectory: workspaceDirectory,
|
|
|
|
sourceDirectory: sourceDirectory,
|
|
|
|
buildDirectory: buildDirectory,
|
2022-10-27 11:00:43 +00:00
|
|
|
artifactsDirectory: artifactsDirectory,
|
2022-10-28 09:22:24 +00:00
|
|
|
lintianOpts: lintianOpts,
|
2022-11-08 16:14:31 +00:00
|
|
|
lintianRun: lintianRun
|
2020-03-26 15:04:59 +00:00
|
|
|
}
|
|
|
|
console.log(details)
|
|
|
|
core.endGroup()
|
|
|
|
|
2021-07-09 22:11:23 +00:00
|
|
|
if (cpuArchitecture != "amd64") {
|
|
|
|
core.startGroup("Install QEMU")
|
|
|
|
// Need newer QEMU to avoid errors
|
2022-10-27 07:00:28 +00:00
|
|
|
await exec.exec("wget", ["http://mirrors.kernel.org/ubuntu/pool/universe/q/qemu/qemu-user-static_6.2+dfsg-2ubuntu6_amd64.deb", "-O", "/tmp/qemu.deb"])
|
2021-07-09 22:11:23 +00:00
|
|
|
await exec.exec("sudo", ["dpkg", "-i", "/tmp/qemu.deb"])
|
|
|
|
core.endGroup()
|
|
|
|
}
|
|
|
|
|
2020-03-26 09:34:31 +00:00
|
|
|
core.startGroup("Create container")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"create",
|
2021-07-09 22:11:23 +00:00
|
|
|
"--platform", `linux/${cpuArchitecture}`,
|
2020-03-26 09:34:31 +00:00
|
|
|
"--name", container,
|
2020-03-26 14:48:23 +00:00
|
|
|
"--volume", workspaceDirectory + ":" + workspaceDirectory,
|
2020-03-26 14:37:35 +00:00
|
|
|
"--workdir", sourceDirectory,
|
2020-03-26 15:51:21 +00:00
|
|
|
"--env", "DEBIAN_FRONTEND=noninteractive",
|
2020-03-26 17:10:17 +00:00
|
|
|
"--env", "DPKG_COLORS=always",
|
|
|
|
"--env", "FORCE_UNSAFE_CONFIGURE=1",
|
2020-03-26 09:34:31 +00:00
|
|
|
"--tty",
|
|
|
|
image,
|
|
|
|
"sleep", "inf"
|
|
|
|
])
|
2020-12-09 22:07:04 +00:00
|
|
|
core.saveState("container", container)
|
2020-03-26 09:34:31 +00:00
|
|
|
core.endGroup()
|
|
|
|
|
|
|
|
core.startGroup("Start container")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"start",
|
|
|
|
container
|
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
2020-12-26 16:34:57 +00:00
|
|
|
core.startGroup("Prepare environment")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2020-12-26 17:15:06 +00:00
|
|
|
"bash", "-c", "echo 'APT::Get::Assume-Yes \"true\";' > /etc/apt/apt.conf.d/00noconfirm"
|
2020-12-26 16:34:57 +00:00
|
|
|
])
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2020-12-26 17:00:53 +00:00
|
|
|
"bash", "-c", "echo debconf debconf/frontend select Noninteractive | debconf-set-selections"
|
2020-12-26 16:34:57 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
2020-03-26 09:34:31 +00:00
|
|
|
core.startGroup("Update packages list")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
|
|
|
"apt-get", "update"
|
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
2022-11-07 21:47:05 +00:00
|
|
|
// The goofy usage of "apt-get -t || apt-get" here is because
|
|
|
|
// of github issue #63.
|
|
|
|
//
|
|
|
|
// When building on a "normal" release like "bullseye", the
|
|
|
|
// debian container is generated with "bullseye-updates" enabled.
|
|
|
|
// This can cause problems when specifying the target release as
|
|
|
|
// `-t bullseye`. For example, if "bullseye-updates" contains
|
|
|
|
// a new version of libc6 and libc6-dev, then the image will
|
|
|
|
// contain the updated libc6, but "apt-get -t bullseye" would try
|
|
|
|
// to install the old version of libc6-dev. Since libc6-dev has
|
|
|
|
// a versioned dependency on the matching libc6, this will fail.
|
|
|
|
//
|
|
|
|
// On a backports release like "bullseye-backports", the
|
|
|
|
// backports package archive has a lower priority than the
|
|
|
|
// "parent" package archive. When building in this situation
|
|
|
|
// apt-get needs "-t" in order to raise the priority of the
|
|
|
|
// backports packages so that they get installed, instead of
|
|
|
|
// installing the older packages from the parent release.
|
2020-03-26 09:34:31 +00:00
|
|
|
core.startGroup("Install development packages")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2022-11-07 21:47:05 +00:00
|
|
|
"bash", "-c",
|
2022-10-27 11:00:43 +00:00
|
|
|
`apt-get install -yq -t '${imageTag}' dpkg-dev debhelper devscripts lintian || apt-get install -yq dpkg-dev debhelper devscripts lintian`
|
2020-03-26 09:34:31 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
2022-11-08 00:44:22 +00:00
|
|
|
core.startGroup("Trust this git repo")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2022-11-08 16:08:21 +00:00
|
|
|
"git", "config", "--global", "--add", "safe.directory", sourceDirectory
|
2022-11-08 00:44:22 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
2021-04-26 19:52:23 +00:00
|
|
|
if (imageTag != "trusty") {
|
|
|
|
core.startGroup("Install build dependencies")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2022-11-07 21:47:05 +00:00
|
|
|
"bash", "-c",
|
|
|
|
`apt-get build-dep -yq -t '${imageTag}' '${sourceDirectory}' || apt-get build-dep -yq '${sourceDirectory}'`
|
2021-04-26 19:52:23 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
}
|
2020-03-26 09:34:31 +00:00
|
|
|
|
2021-07-09 22:10:09 +00:00
|
|
|
if (revision) {
|
|
|
|
core.startGroup("Create tarball")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2023-03-06 08:32:00 +00:00
|
|
|
"tar",
|
|
|
|
"--exclude-vcs",
|
|
|
|
"--exclude=debian",
|
|
|
|
"--create",
|
|
|
|
"--gzip",
|
|
|
|
"--verbose",
|
|
|
|
`--file=../${pkg}_${version}.orig.tar.gz`,
|
|
|
|
"."
|
2021-07-09 22:10:09 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
}
|
|
|
|
|
2020-12-26 16:13:03 +00:00
|
|
|
core.startGroup("Build packages")
|
2020-03-26 09:34:31 +00:00
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2021-01-02 22:27:33 +00:00
|
|
|
"dpkg-buildpackage"
|
2020-03-26 09:34:31 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
2020-03-26 10:45:32 +00:00
|
|
|
|
2022-11-08 16:14:31 +00:00
|
|
|
if (lintianRun) {
|
2022-10-28 09:22:24 +00:00
|
|
|
core.startGroup("Run static analysis")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2022-11-08 16:14:31 +00:00
|
|
|
"find",
|
2022-10-28 09:22:24 +00:00
|
|
|
buildDirectory,
|
|
|
|
"-maxdepth", "1",
|
|
|
|
"-name", `*${version}*.changes`,
|
|
|
|
"-type", "f",
|
|
|
|
"-print",
|
|
|
|
"-exec", "lintian", lintianOpts, "{}", "\+"
|
|
|
|
])
|
|
|
|
core.endGroup()
|
2022-11-08 16:14:31 +00:00
|
|
|
}
|
2022-10-27 11:00:43 +00:00
|
|
|
|
2020-12-26 16:13:03 +00:00
|
|
|
core.startGroup("Install built packages")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
|
|
|
"debi", "--with-depends"
|
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
|
|
|
core.startGroup("List packages contents")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
|
|
|
"debc"
|
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
|
|
|
core.startGroup("Move build artifacts")
|
2020-03-26 10:49:41 +00:00
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2020-03-26 11:07:14 +00:00
|
|
|
"find",
|
2020-03-26 14:37:35 +00:00
|
|
|
buildDirectory,
|
2020-03-26 11:07:14 +00:00
|
|
|
"-maxdepth", "1",
|
2021-03-11 13:33:37 +00:00
|
|
|
"-name", `*${version}*.*`,
|
2020-03-26 11:07:14 +00:00
|
|
|
"-type", "f",
|
|
|
|
"-print",
|
2020-03-26 14:48:23 +00:00
|
|
|
"-exec", "mv", "{}", artifactsDirectory, ";"
|
2020-03-26 10:45:32 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
2020-03-26 09:34:31 +00:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|