This commit is contained in:
Dawid Dziurla 2020-03-26 13:26:07 +01:00
parent b367c08be4
commit d9becc67b6
No known key found for this signature in database
GPG key ID: 7B6D8368172E9B0B
4 changed files with 42 additions and 27 deletions

View file

@ -13,4 +13,9 @@ jobs:
- name: Test run - name: Test run
uses: ./ uses: ./
with: with:
directory: lolcat source_directory: lolcat
artifacts_directory: output
- name: Check files
run: |
ls -lh output
ls -lh output/lolcat_*.*

View file

@ -8,6 +8,7 @@ An action that builds a Debian package from source.
- name: Build Debian package - name: Build Debian package
uses: dawidd6/action-debian-package@master uses: dawidd6/action-debian-package@master
with: 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 os: debian # or ubuntu, defaults to debian
``` ```

View file

@ -4,10 +4,14 @@ branding:
color: red color: red
icon: package icon: package
inputs: inputs:
directory: source_directory:
description: Directory where Debian sources are, relative to workspace description: Directory where Debian sources are, relative to workspace
required: false required: false
default: ./ default: ./
artifacts_directory:
description: Directory where build artifacts will be placed, relative to workspace
required: false
default: ./
os: os:
description: '"ubuntu" or "debian"' description: '"ubuntu" or "debian"'
required: false required: false

29
main.js
View file

@ -1,30 +1,32 @@
const path = require("path")
const core = require("@actions/core") const core = require("@actions/core")
const exec = require("@actions/exec") const exec = require("@actions/exec")
const firstline = require("firstline") const firstline = require("firstline")
const path = require("path")
const fs = require("fs")
async function main() { async function main() {
try { 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 os = core.getInput("os", { required: true })
const directoryRunner = path.join(process.cwd(), directory) const workspaceDirectory = process.cwd()
const directoryContainer = "/build/source" const file = path.join(workspaceDirectory, sourceDirectory, "debian/changelog")
const file = path.join(directoryRunner, "debian/changelog")
const changelog = await firstline(file) const changelog = await firstline(file)
const regex = /^(?<package>.+) \((?<version>.+)-(?<revision>.+)\) (?<distribution>.+); (?<options>.+)$/ const regex = /^(?<package>.+) \((?<version>[^-]+)-?(?<revision>[^-]+)?\) (?<distribution>.+); (?<options>.+)$/
const match = changelog.match(regex) const match = changelog.match(regex)
const { package, version, revision, distribution } = match.groups const { package, version, revision, distribution } = match.groups
const container = package + "_" + version + "-" + revision const container = package + "_" + version
const image = os + ":" + distribution.replace("UNRELEASED", "unstable") const image = os + ":" + distribution.replace("UNRELEASED", "unstable")
fs.mkdirSync(artifactsDirectory, { recursive: true })
core.startGroup("Create container") core.startGroup("Create container")
await exec.exec("docker", [ await exec.exec("docker", [
"create", "create",
"--name", container, "--name", container,
"--volume", directoryRunner + ":" + directoryContainer, "--volume", workspaceDirectory + ":" + workspaceDirectory,
"--workdir", directoryContainer, "--workdir", path.join(workspaceDirectory, sourceDirectory),
"--tty", "--tty",
image, image,
"sleep", "inf" "sleep", "inf"
@ -38,6 +40,7 @@ async function main() {
]) ])
core.endGroup() core.endGroup()
if (revision) {
core.startGroup("Create tarball") core.startGroup("Create tarball")
await exec.exec("docker", [ await exec.exec("docker", [
"exec", "exec",
@ -50,6 +53,7 @@ async function main() {
"./" "./"
]) ])
core.endGroup() core.endGroup()
}
core.startGroup("Update packages list") core.startGroup("Update packages list")
await exec.exec("docker", [ await exec.exec("docker", [
@ -71,7 +75,7 @@ async function main() {
await exec.exec("docker", [ await exec.exec("docker", [
"exec", "exec",
container, container,
"apt-get", "build-dep", "-y", directoryContainer "apt-get", "build-dep", "-y", "./"
]) ])
core.endGroup() core.endGroup()
@ -90,9 +94,10 @@ async function main() {
"find", "find",
"..", "..",
"-maxdepth", "1", "-maxdepth", "1",
"-name", `${package}_${version}*.*`,
"-type", "f", "-type", "f",
"-print", "-print",
"-exec", "cp", "{}", ".", ";" "-exec", "cp", "{}", artifactsDirectory, ";"
]) ])
core.endGroup() core.endGroup()
} catch (error) { } catch (error) {