Skip to content

Commit

Permalink
GHA: use a JavaScript action
Browse files Browse the repository at this point in the history
The composite action didn't work as expected (the action's
`action.sh` and `build.sh` weren't accessible), so I replaced the
shell script with a tiny JavaScript bootstrap, that will properly
collect the action inputs and generate a simple local build.sh and
calls it.

Note that we couldn't use a Docker container action, because we
couldn't access the host docker ending, and would need to add both
docker cli and docker server to the docker container...
  • Loading branch information
ysbaddaden committed Mar 31, 2022
1 parent 3ec303d commit 404e79d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
35 changes: 35 additions & 0 deletions action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const process = require("process")
const { spawn } = require("child_process")
const fs = require("fs")

// basic implementation of @action/core.getInput()
function getInput(name) {
return process.env[`INPUT_${name.toUpperCase()}`].trim()
}

// collect action inputs:
let setupOpts = []
if (getInput("skip-login") === "true") setupOpts.push("--skip-login")
if (getInput("latest") === "true") setupOpts.push("latest")

let buildOpts = [], value
if ((value = getInput("repository")) !== "") buildOpts.push(`-r ${value}`)
if ((value = getInput("repository-suffix")) !== "") buildOpts.push(`-s ${value}`)
if ((value = getInput("tag-suffix")) !== "") buildOpts.push(`-t ${value}`)
if ((value = getInput("build-directory")) !== "") buildOpts.push(`-d ${value}`)
if ((value = getInput("build-options")) !== "") buildOpts.push(`-o "${value}"`)

// generate a local build.sh script:
fs.writeFileSync("build.sh", `#! bash
source ${__dirname}/build.sh
dockerSetup ${setupOpts.join(" ")}
echo $VERSION > VERSION
dockerBuildAndPush ${buildOpts.join(" ")}
`)

// execute it:
const build = spawn("bash", ["build.sh"], { maxBuffer: 100 * 1024 * 1024 })
build.stdout.on("data", data => { process.stdout.write(data) })
build.stderr.on("data", data => { process.stderr.write(data) })
build.on("error", error => { console.error(error) })
build.on("exit", code => { process.exit(code) })
26 changes: 0 additions & 26 deletions action.sh

This file was deleted.

15 changes: 2 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,5 @@ inputs:
type: string

runs:
using: composite

steps:
- run: ./action.sh
env:
INPUT_SKIP_LOGIN: ${{ inputs.skip-login }}
INPUT_LATEST: ${{ inputs.latest }}
INPUT_REPOSITORY: ${{ inputs.repository }}
INPUT_REPOSITORY_SUFFIX: ${{ inputs.repository-suffix }}
INPUT_TAG_SUFFIX: ${{ inputs.tag-suffix }}
INPUT_BUILD_DIRECTORY: ${{ inputs.build-directory }}
INPUT_BUILD_OPTIONS: ${{ inputs.build-options }}
shell: bash
using: node16
main: action.js

0 comments on commit 404e79d

Please sign in to comment.