2020-03-26 09:34:31 +00:00
|
|
|
const core = require("@actions/core")
|
|
|
|
const exec = require("@actions/exec")
|
|
|
|
const firstline = require("firstline")
|
2020-03-26 14:37:35 +00:00
|
|
|
const hub = require("docker-hub-utils")
|
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-03-26 14:37:35 +00:00
|
|
|
function getDistribution(distribution) {
|
|
|
|
return distribution.replace("UNRELEASED", "unstable")
|
2020-03-26 16:10:18 +00:00
|
|
|
.replace("-security", "")
|
|
|
|
.replace("-backports", "")
|
2020-03-26 14:37:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getOS(distribution) {
|
|
|
|
for (const os of ["debian", "ubuntu"]) {
|
|
|
|
const tags = await hub.queryTags({ user: "library", name: os })
|
|
|
|
if (tags.find(tag => tag.name == distribution)) {
|
|
|
|
return os
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 09:34:31 +00:00
|
|
|
async function main() {
|
|
|
|
try {
|
2020-07-25 10:29:47 +00:00
|
|
|
const sourceRelativeDirectory = core.getInput("source_directory") || "./"
|
|
|
|
const artifactsRelativeDirectory = core.getInput("artifacts_directory") || "./"
|
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)
|
2020-03-26 17:58:33 +00:00
|
|
|
const regex = /^(?<package>.+) \(((?<epoch>[0-9]+):)?(?<version>[^:-]+)(-(?<revision>[^:-]+))?\) (?<distribution>.+);/
|
2020-03-26 09:34:31 +00:00
|
|
|
const match = changelog.match(regex)
|
2020-03-26 17:39:23 +00:00
|
|
|
const { package, epoch, version, revision, distribution } = match.groups
|
2020-03-26 14:37:35 +00:00
|
|
|
const os = await getOS(getDistribution(distribution))
|
2020-03-26 16:45:58 +00:00
|
|
|
const container = package
|
2020-03-26 14:37:35 +00:00
|
|
|
const image = os + ":" + getDistribution(distribution)
|
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 = {
|
|
|
|
package: package,
|
2020-03-26 17:39:23 +00:00
|
|
|
epoch: epoch,
|
2020-03-26 15:04:59 +00:00
|
|
|
version: version,
|
|
|
|
revision: revision,
|
|
|
|
distribution: getDistribution(distribution),
|
|
|
|
os: os,
|
|
|
|
container: container,
|
|
|
|
image: image,
|
|
|
|
workspaceDirectory: workspaceDirectory,
|
|
|
|
sourceDirectory: sourceDirectory,
|
|
|
|
buildDirectory: buildDirectory,
|
|
|
|
artifactsDirectory: artifactsDirectory
|
|
|
|
}
|
|
|
|
console.log(details)
|
|
|
|
core.endGroup()
|
|
|
|
|
2020-03-26 09:34:31 +00:00
|
|
|
core.startGroup("Create container")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"create",
|
|
|
|
"--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"
|
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
|
|
|
core.startGroup("Start container")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"start",
|
|
|
|
container
|
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
2020-03-26 12:26:07 +00:00
|
|
|
if (revision) {
|
|
|
|
core.startGroup("Create tarball")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
|
|
|
"tar",
|
|
|
|
"--exclude-vcs",
|
|
|
|
"--exclude", "./debian",
|
2020-11-08 18:40:45 +00:00
|
|
|
"--transform", `s/^\./${package}-${version}/S`,
|
2020-03-26 14:37:35 +00:00
|
|
|
"-cvzf", `${buildDirectory}/${package}_${version}.orig.tar.gz`,
|
2020-03-26 15:00:12 +00:00
|
|
|
"-C", sourceDirectory,
|
|
|
|
"./"
|
2020-03-26 12:26:07 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
}
|
2020-03-26 10:06:08 +00:00
|
|
|
|
2020-03-26 09:34:31 +00:00
|
|
|
core.startGroup("Update packages list")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
|
|
|
"apt-get", "update"
|
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
|
|
|
core.startGroup("Install development packages")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2020-03-26 15:51:36 +00:00
|
|
|
"apt-get", "install", "-yq", "dpkg-dev", "debhelper"
|
2020-03-26 09:34:31 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
|
|
|
core.startGroup("Install build dependencies")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2020-03-26 15:51:36 +00:00
|
|
|
"apt-get", "build-dep", "-yq", sourceDirectory
|
2020-03-26 09:34:31 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
|
|
|
|
|
|
|
core.startGroup("Build package")
|
|
|
|
await exec.exec("docker", [
|
|
|
|
"exec",
|
|
|
|
container,
|
2020-03-26 10:16:30 +00:00
|
|
|
"dpkg-buildpackage", "-tc"
|
2020-03-26 09:34:31 +00:00
|
|
|
])
|
|
|
|
core.endGroup()
|
2020-03-26 10:45:32 +00:00
|
|
|
|
2020-03-26 14:48:23 +00:00
|
|
|
core.startGroup("Move 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",
|
2020-03-26 23:29:02 +00:00
|
|
|
"-name", `${package}*${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()
|