diff --git a/my-cool-action/Dockerfile b/my-cool-action/Dockerfile index 9db1acd..18a115f 100644 --- a/my-cool-action/Dockerfile +++ b/my-cool-action/Dockerfile @@ -1,21 +1,8 @@ -# Use the latest version of Node.js -# -# You may prefer the full image: -# FROM node -# -# or even an alpine image (a smaller, faster, less-feature-complete image): -# FROM node:alpine -# -# You can specify a version: -# FROM node:10-slim FROM node:slim -# Labels for GitHub to read your action LABEL "com.github.actions.name"="check-files" LABEL "com.github.actions.description"="Checks files to see which are changed with PR" -# Here are all of the available icons: https://feathericons.com/ LABEL "com.github.actions.icon"="alert-octagon" -# And all of the available colors: https://developer.github.com/actions/creating-github-actions/creating-a-docker-container/#label LABEL "com.github.actions.color"="purple" # Copy the package.json and package-lock.json @@ -27,5 +14,4 @@ RUN npm install # Copy the rest of your action's code COPY . . -# Run `node /index.js` ENTRYPOINT ["node", "/index.js"] diff --git a/my-cool-action/index.js b/my-cool-action/index.js index f8592e8..eb7f783 100644 --- a/my-cool-action/index.js +++ b/my-cool-action/index.js @@ -1,4 +1,6 @@ const { Toolkit } = require('actions-toolkit') +const shell = require('shelljs'); + const tools = new Toolkit({ event: ['pull_request.opened', 'pull_request.synchronize'], }); @@ -9,13 +11,13 @@ Toolkit.run(async tools => { let num = tools.context.payload.number; const list = await tools.github.pulls.listFiles({'number': '2', 'owner': 'tomczoink', 'repo': 'emails-tom' }); - //console.log(list); - let files = Object.values(JSON.parse(list)); - let regex = RegExp('.mjml', 'g'); + let files = Object.values(list.data); + let regex = RegExp('product-updates/(.*?)\.mjml', 'g'); + let changedFiles = []; for (var i = 0; i < files.length; i++) { - console.log(files[i]); - console.log(regex.test(files[i].filename)); + if(regex.test(files[i].filename)) { + shell.exec('./my-cool-action/mjml-compile ./' + files[i].filename ); + } } - }) diff --git a/my-cool-action/mjml b/my-cool-action/mjml new file mode 100755 index 0000000..66e28e7 --- /dev/null +++ b/my-cool-action/mjml @@ -0,0 +1,4 @@ +#!/usr/bin/env node + +require('../lib/index') +require('mjml-cli') diff --git a/my-cool-action/mjml-compile b/my-cool-action/mjml-compile new file mode 100755 index 0000000..68db33b --- /dev/null +++ b/my-cool-action/mjml-compile @@ -0,0 +1,44 @@ +#!/bin/bash + +set -eo pipefail + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" + +if [ -z "$1" ]; then + echo "Usage: mjml-compile [path-to-file-to-compile]" + echo "" + echo " e.g. mjml-compile product-updates/18-02-07-ClientLib1-1/index" + exit 1 +fi + +FILE_WITHOUT_EXT=`echo "$1" | sed 's/\(.*\)\.mjml/\1/'` + +MJML_FILE="${DIR}/../${FILE_WITHOUT_EXT}.mjml" +HTML_FILE="${DIR}/../${FILE_WITHOUT_EXT}.html" + +RED='\033[0;31m' +NO_COLOR='\033[0m' + +if [ ! -f "${MJML_FILE}" ]; then + echo "File '${MJML_FILE}' does not exist" + exit 1 +fi + +node "my-cool-action/mjml" "${MJML_FILE}" -o "${HTML_FILE}" + +if grep "http://link" "${HTML_FILE}"; then + echo -e "\n${RED}Error: http://link exists in the generated HTML. This is NEVER valid!${NO_COLOR}" + exit 1 +fi + +if grep "todo" "${HTML_FILE}"; then + echo -e "\n${RED}Error: The text TODO exists in the generated HTML. This is NEVER valid!${NO_COLOR}" + exit 1 +fi + +if grep -E "src=[\"']" "${HTML_FILE}" | grep -v -E "src=[\"']https://files.ably.io"; then + echo -e "\n${RED}Error: It looks like you are referencing images that are not from the CDN. You must use https://files.ably.io for all image references${NO_COLOR}" + exit 1 +fi + +echo "HTML file generated at: ${FILE_WITHOUT_EXT}.html" diff --git a/my-cool-action/package.json b/my-cool-action/package.json index eec285a..8554887 100644 --- a/my-cool-action/package.json +++ b/my-cool-action/package.json @@ -7,9 +7,12 @@ "test": "jest" }, "dependencies": { - "actions-toolkit": "^2.0.0" + "actions-toolkit": "^2.0.0", + "shelljs": "^0.8.3", + "mjml": "~4.2.1", + "nodemon": "~1.18.10" }, "devDependencies": { "jest": "^24.5.0" } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 92906bb..4cb08ef 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "dependencies": { "actions-toolkit": "^2.0.0", "mjml": "~4.2.1", - "nodemon": "~1.18.10" + "nodemon": "~1.18.10", + "shelljs": "^0.8.3" } } diff --git a/test/entrypoint.sh b/test/entrypoint.sh index 796a19d..ee334e8 100755 --- a/test/entrypoint.sh +++ b/test/entrypoint.sh @@ -5,4 +5,4 @@ for file in product-updates/*/index.mjml; do if [ -f "$file" ]; then bin/mjml-compile "$file" fi -done \ No newline at end of file +done