From 7c76ec9392055f50b2bd1be71fd4b2ffb1637ff9 Mon Sep 17 00:00:00 2001 From: Borales Date: Fri, 30 Nov 2018 21:14:28 +0100 Subject: [PATCH] Initial commit --- .dockerignore | 7 +++++++ .github/main.workflow | 49 +++++++++++++++++++++++++++++++++++++++++++ Brewfile | 2 ++ Dockerfile | 16 ++++++++++++++ entrypoint.sh | 15 +++++++++++++ script/bootstrap | 15 +++++++++++++ script/test | 10 +++++++++ test/bin/yarn | 2 ++ test/entrypoint.bats | 31 +++++++++++++++++++++++++++ 9 files changed, 147 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/main.workflow create mode 100644 Brewfile create mode 100644 Dockerfile create mode 100755 entrypoint.sh create mode 100755 script/bootstrap create mode 100755 script/test create mode 100755 test/bin/yarn create mode 100644 test/entrypoint.bats diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..023ebc0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +# ignore all files by default +* +# include required files with an exception +!entrypoint.sh +!LICENSE +!README.md +!THIRD_PARTY_NOTICE.md diff --git a/.github/main.workflow b/.github/main.workflow new file mode 100644 index 0000000..66e555e --- /dev/null +++ b/.github/main.workflow @@ -0,0 +1,49 @@ +workflow "Build and Publish" { + on = "push" + resolves = "Docker Publish" +} + +action "Shell Lint" { + uses = "actions/bin/shellcheck@master" + args = "entrypoint.sh" +} + +action "Test" { + uses = "actions/bin/bats@master" + args = "test/*.bats" +} + +action "Docker Lint" { + uses = "docker://replicated/dockerfilelint" + args = ["Dockerfile"] +} + +action "Build" { + needs = ["Shell Lint", "Test", "Docker Lint"] + uses = "actions/docker/cli@master" + args = "build -t yarn ." +} + +action "Docker Tag" { + needs = ["Build"] + uses = "actions/docker/tag@master" + args = "yarn borales/yarn --no-latest" +} + +action "Publish Filter" { + needs = ["Build"] + uses = "actions/bin/filter@master" + args = "branch master" +} + +action "Docker Login" { + needs = ["Publish Filter"] + uses = "actions/docker/login@master" + secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"] +} + +action "Docker Publish" { + needs = ["Docker Tag", "Docker Login"] + uses = "actions/docker/cli@master" + args = "push borales/yarn" +} diff --git a/Brewfile b/Brewfile new file mode 100644 index 0000000..7772992 --- /dev/null +++ b/Brewfile @@ -0,0 +1,2 @@ +brew "bats" +brew "shellcheck" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..351d466 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:10-slim + +LABEL version="1.0.0" +LABEL repository="https://github.com/Borales/actions-yarn" +LABEL homepage="https://github.com/Borales/actions-yarn" +LABEL maintainer="Oleksandr Bordun " + +LABEL com.github.actions.name="GitHub Action for Yarn" +LABEL com.github.actions.description="Wraps the yarn CLI to enable common yarn commands." +LABEL com.github.actions.icon="package" +LABEL com.github.actions.color="red" +# COPY LICENSE README.md THIRD_PARTY_NOTICE.md / + +COPY "entrypoint.sh" "/entrypoint.sh" +ENTRYPOINT ["/entrypoint.sh"] +CMD ["help"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..f5c53ff --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +if [ -n "$NPM_AUTH_TOKEN" ]; then + # Respect NPM_CONFIG_USERCONFIG if it is provided, default to $HOME/.npmrc + NPM_CONFIG_USERCONFIG="${NPM_CONFIG_USERCONFIG-"$HOME/.npmrc"}" + NPM_REGISTRY_URL="${NPM_REGISTRY_URL-registry.npmjs.org}" + + # Allow registry.npmjs.org to be overridden with an environment variable + printf "//$NPM_REGISTRY_URL/:_authToken=$NPM_AUTH_TOKEN\nregistry=$NPM_REGISTRY_URL" > "$NPM_CONFIG_USERCONFIG" + chmod 0600 "$NPM_CONFIG_USERCONFIG" +fi + +sh -c "yarn $*" diff --git a/script/bootstrap b/script/bootstrap new file mode 100755 index 0000000..5144b6a --- /dev/null +++ b/script/bootstrap @@ -0,0 +1,15 @@ +#!/bin/sh +# script/bootstrap: Resolve dependencies that the application requires to run. + +# Exit if any subcommand fails +set -e + +# Ensure we're always running from the project root +cd "$(dirname "$0")/.." + +if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then + brew bundle check >/dev/null 2>&1 || { + echo "==> Installing Homebrew dependencies…" + brew bundle + } +fi diff --git a/script/test b/script/test new file mode 100755 index 0000000..c131299 --- /dev/null +++ b/script/test @@ -0,0 +1,10 @@ +#!/bin/sh + +# Exit if any subcommand fails +set -e + +# Ensure we're always running from the project root +cd "$(dirname "$0")/.." + +bats test/*.bats +shellcheck *.sh diff --git a/test/bin/yarn b/test/bin/yarn new file mode 100755 index 0000000..1632951 --- /dev/null +++ b/test/bin/yarn @@ -0,0 +1,2 @@ +#!/bin/sh +echo "Fake yarn" diff --git a/test/entrypoint.bats b/test/entrypoint.bats new file mode 100644 index 0000000..319c8a7 --- /dev/null +++ b/test/entrypoint.bats @@ -0,0 +1,31 @@ +#!/usr/bin/env bats + +PATH="$PATH:$BATS_TEST_DIRNAME/bin" + +function setup() { + # Ensure GITHUB_WORKSPACE is set + export GITHUB_WORKSPACE="${GITHUB_WORKSPACE-"${BATS_TEST_DIRNAME}/.."}" +} + +@test "entrypoint runs successfully" { + run $GITHUB_WORKSPACE/entrypoint.sh help + echo "$output" + [ "$status" -eq 0 ] +} + +@test "npmrc location can be overridden" { + export NPM_CONFIG_USERCONFIG=$( mktemp ) + export NPM_AUTH_TOKEN=NPM_AUTH_TOKEN + run $GITHUB_WORKSPACE/entrypoint.sh help + [ "$status" -eq 0 ] + [ "$(cat $NPM_CONFIG_USERCONFIG)" = "//registry.npmjs.org/:_authToken=NPM_AUTH_TOKEN" ] +} + +@test "registry can be overridden" { + export NPM_CONFIG_USERCONFIG=$( mktemp ) + export NPM_REGISTRY_URL=someOtherRegistry.someDomain.net + export NPM_AUTH_TOKEN=NPM_AUTH_TOKEN + run $GITHUB_WORKSPACE/entrypoint.sh help + [ "$status" -eq 0 ] + [ "$(cat $NPM_CONFIG_USERCONFIG)" = "//someOtherRegistry.someDomain.net/:_authToken=NPM_AUTH_TOKEN" ] +}