From 09ff3f9fdd0eb69b0df9d1d96bb22ffed85167a4 Mon Sep 17 00:00:00 2001 From: "Henson, Garth" Date: Mon, 4 Feb 2019 12:56:28 -0500 Subject: [PATCH] initial commit --- Dockerfile | 24 +++++++++ README.md | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 39 +++++++++++++++ helpers.sh | 93 ++++++++++++++++++++++++++++++++++ yarn.lock | 4 ++ 5 files changed, 296 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 entrypoint.sh create mode 100755 helpers.sh create mode 100644 yarn.lock diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5dcac27 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM node:10-alpine + +LABEL version="1.0.0" +LABEL repository="http://github.com/guahanweb/actions-test" +LABEL homepage="http://github.com/actions" +LABEL maintainer="Garth Henson " + +LABEL com.github.actions.name="Node App Helper Actions" +LABEL com.github.actions.description="Provides some helper scripts to aid in basic Node.js app delivery" +LABEL com.github.actions.icon="settings" +LABEL com.github.actions.color="green" + +# install additional dependencies +RUN apk --update add git openssh bash && \ + rm -rf /var/lib/apt/lists/* && \ + rm /var/cache/apk/* + +# COPY LICENSE README.md / + +COPY "helpers.sh" "/helpers.sh" +COPY "entrypoint.sh" "/entrypoint.sh" + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["help"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..99532de --- /dev/null +++ b/README.md @@ -0,0 +1,136 @@ +# Node.js Actions + +This action is designed to help easily proxy any Node.js scripts into GH Actions to create workflows easily. By design, there are only a few predefined paths in this action, but the `run` path is flexible enough to build any workflow you may design. + +The `entrypoint.sh` script takes in arguments to define what path to follow. There are currently two primary predefined tasks. + +## Tasks + +Each task is essentially a sub-task to the main entrypoint and will execute a very specific operation. + +### `run` + +The primary task is `run`. This simply executes the provided script within your NPM or yarn context. By configuring your action definition, you can use the `run` task to chain any number of operations within your system. + +For example, if you had an NPM script titled `build` that would create your artifacts for deployment, you could set up your action like this: + +``` +action "Build" { + uses = "guahanweb/actions/node-app@master" + args = "run build" +} +``` + +**NOTE:** if you are using Yarn, provide an `env` definition specifying the `PKG_MANAGER` to be Yarn: + +``` + env = { + PKG_MANAGER = "yarn" + } +``` + +Under the covers, this is essentially going to run `npm run build` or `yarn build` on the worker machine. Obviously, this can be expanded to run any actions you may need. + +**Linting example:** + +``` +action "Lint" { + uses = "guahanweb/actions/node-app@master" + env = { + PKG_MANAGER = "yarn" + } + args = "run lint" +} +``` + +#### Environment Variables + +Several environment variables are availabe to customize the behavior of your actions. + +
+
NODE_ENV
+
The environment in which to execute your node application.
+ defaults to production
+
PKG_MANAGER
+
Specifies which package manager you are using. Valid values are npm and yarn.
+ defaults to npm
+
+ +### `gh-pages` + +This action also offers the ability to easily publish to an orphan branch on your repository. This is generally used for publishing static content to a `gh-pages` branch to be hosted by GitHub, but you can customize it to any branching strategy you desire. + +This task requires the `GITHUB_TOKEN` secret from your action, or it will not have the appropriate permissions to push to your repo. + +#### Example + +``` +action "GH Pages" { + uses = "guahanweb/actions/node-app@master" + secrets = ["GITHUB_TOKEN"] + args = "gh-pages" +} +``` + +#### Environment Variables + +Since every application is different, there are a few overrides you can provide within your `env` block to customize behavior. + +
+
GITHUB_TOKEN
+
This token is provided by GitHub when you specify it in your secrets array. It is required for the operation to have permission to push to your repository.
+
BUILD_DIR
+
Specifies the directory that contains the static assets to be pushed.
+ defaults to build
+
REMOTE_BRANCH
+
Spcifies the branch name to which the contents of $BUILD_DIR should be pushed.
+ defaults to gh-pages
+
+ +### `test` + +The `test` operation is provided as an alias to `run test`. + +## Putting it all together + +Once you have a handle on the options, you can create multiple actions easily and chain them together into a workflow. Here is an example of how you might specify a workflow to lint, test, build, and deploy a GH Pages website using this repository. + +#### Example Workflow + +``` +workflow "Build and Deploy Pages" { + on = "push" + resolves = ["Lint", "Build", "Test", "Deploy Pages"] +} + +action "Lint" { + uses = "guahanweb/actions/node-app@master" + env = { + PKG_MANAGER = "yarn" + } + args = "run lint" +} + +action "Build" { + uses = "guahanweb/actions/node-app@master" + env = { + PKG_MANAGER = "yarn" + } + args = "run build" +} + +action "Test" { + uses = "guahanweb/actions/node-app@master" + env = { + PKG_MANAGER = "yarn" + } + args = "test" +} + +action "Deploy Pages" { + uses = "guahanweb/actions/node-app@master" + secrets = ["GITHUB_TOKEN"] + args = "gh-pages" + needs = ["Lint", "Build", "Test"] +} +``` \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..fd13c71 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# set up environment +export NODE_ENV=${NODE_ENV:-"production"} +export PKG_MANAGER=${PKG_MANAGER:-"npm"} + +# include some helper methods +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source "$DIR/helpers.sh" + + +function help { + echo "The following commands can be run from this script." + echo "" + echo " - run