Initial commit

This commit is contained in:
Borales 2018-11-30 21:14:28 +01:00
commit 7c76ec9392
No known key found for this signature in database
GPG Key ID: CDC05EA9067B0EB5
9 changed files with 147 additions and 0 deletions

7
.dockerignore Normal file
View File

@ -0,0 +1,7 @@
# ignore all files by default
*
# include required files with an exception
!entrypoint.sh
!LICENSE
!README.md
!THIRD_PARTY_NOTICE.md

49
.github/main.workflow vendored Normal file
View File

@ -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"
}

2
Brewfile Normal file
View File

@ -0,0 +1,2 @@
brew "bats"
brew "shellcheck"

16
Dockerfile Normal file
View File

@ -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 <bordun.alexandr@gmail.com>"
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"]

15
entrypoint.sh Executable file
View File

@ -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 $*"

15
script/bootstrap Executable file
View File

@ -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

10
script/test Executable file
View File

@ -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

2
test/bin/yarn Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo "Fake yarn"

31
test/entrypoint.bats Normal file
View File

@ -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" ]
}