From d9becc67b6f4cc6aa17816d360a32882767af918 Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Thu, 26 Mar 2020 13:26:07 +0100 Subject: [PATCH] update --- .github/workflows/test.yml | 7 ++++- README.md | 3 ++- action.yml | 6 ++++- main.js | 53 +++++++++++++++++++++----------------- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 34fadbf..d22420b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,4 +13,9 @@ jobs: - name: Test run uses: ./ with: - directory: lolcat \ No newline at end of file + source_directory: lolcat + artifacts_directory: output + - name: Check files + run: | + ls -lh output + ls -lh output/lolcat_*.* \ No newline at end of file diff --git a/README.md b/README.md index 7311d99..576679f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ An action that builds a Debian package from source. - name: Build Debian package uses: dawidd6/action-debian-package@master with: - directory: lolcat # optional, relative to workspace directory + source_directory: lolcat # optional, relative to workspace directory + artifacts_directory: output # optional, relative to workspace directory os: debian # or ubuntu, defaults to debian ``` diff --git a/action.yml b/action.yml index cc2c31a..3b8a37b 100644 --- a/action.yml +++ b/action.yml @@ -4,10 +4,14 @@ branding: color: red icon: package inputs: - directory: + source_directory: description: Directory where Debian sources are, relative to workspace required: false default: ./ + artifacts_directory: + description: Directory where build artifacts will be placed, relative to workspace + required: false + default: ./ os: description: '"ubuntu" or "debian"' required: false diff --git a/main.js b/main.js index 6a15f40..efd45b1 100644 --- a/main.js +++ b/main.js @@ -1,30 +1,32 @@ -const path = require("path") const core = require("@actions/core") const exec = require("@actions/exec") const firstline = require("firstline") +const path = require("path") +const fs = require("fs") async function main() { try { - const directory = core.getInput("directory", { required: true }) + const sourceDirectory = core.getInput("source_directory", { required: true }) + const artifactsDirectory = core.getInput("artifacts_directory", { required: true }) const os = core.getInput("os", { required: true }) - const directoryRunner = path.join(process.cwd(), directory) - const directoryContainer = "/build/source" - - const file = path.join(directoryRunner, "debian/changelog") + const workspaceDirectory = process.cwd() + const file = path.join(workspaceDirectory, sourceDirectory, "debian/changelog") const changelog = await firstline(file) - const regex = /^(?.+) \((?.+)-(?.+)\) (?.+); (?.+)$/ + const regex = /^(?.+) \((?[^-]+)-?(?[^-]+)?\) (?.+); (?.+)$/ const match = changelog.match(regex) const { package, version, revision, distribution } = match.groups - const container = package + "_" + version + "-" + revision + const container = package + "_" + version const image = os + ":" + distribution.replace("UNRELEASED", "unstable") + fs.mkdirSync(artifactsDirectory, { recursive: true }) + core.startGroup("Create container") await exec.exec("docker", [ "create", "--name", container, - "--volume", directoryRunner + ":" + directoryContainer, - "--workdir", directoryContainer, + "--volume", workspaceDirectory + ":" + workspaceDirectory, + "--workdir", path.join(workspaceDirectory, sourceDirectory), "--tty", image, "sleep", "inf" @@ -38,18 +40,20 @@ async function main() { ]) core.endGroup() - core.startGroup("Create tarball") - await exec.exec("docker", [ - "exec", - container, - "tar", - "--exclude-vcs", - "--exclude", "./debian", - "--transform", `s/^\./${package}-${version}/`, - "-cvzf", `../${package}_${version}.orig.tar.gz`, - "./" - ]) - core.endGroup() + if (revision) { + core.startGroup("Create tarball") + await exec.exec("docker", [ + "exec", + container, + "tar", + "--exclude-vcs", + "--exclude", "./debian", + "--transform", `s/^\./${package}-${version}/`, + "-cvzf", `../${package}_${version}.orig.tar.gz`, + "./" + ]) + core.endGroup() + } core.startGroup("Update packages list") await exec.exec("docker", [ @@ -71,7 +75,7 @@ async function main() { await exec.exec("docker", [ "exec", container, - "apt-get", "build-dep", "-y", directoryContainer + "apt-get", "build-dep", "-y", "./" ]) core.endGroup() @@ -90,9 +94,10 @@ async function main() { "find", "..", "-maxdepth", "1", + "-name", `${package}_${version}*.*`, "-type", "f", "-print", - "-exec", "cp", "{}", ".", ";" + "-exec", "cp", "{}", artifactsDirectory, ";" ]) core.endGroup() } catch (error) {