Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking most #3

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions my-cool-action/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,5 +14,4 @@ RUN npm install
# Copy the rest of your action's code
COPY . .

# Run `node /index.js`
ENTRYPOINT ["node", "/index.js"]
14 changes: 8 additions & 6 deletions my-cool-action/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { Toolkit } = require('actions-toolkit')
const shell = require('shelljs');

const tools = new Toolkit({
event: ['pull_request.opened', 'pull_request.synchronize'],
});
Expand All @@ -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 );
}
}

})
4 changes: 4 additions & 0 deletions my-cool-action/mjml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

require('../lib/index')
require('mjml-cli')
44 changes: 44 additions & 0 deletions my-cool-action/mjml-compile
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 5 additions & 2 deletions my-cool-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ for file in product-updates/*/index.mjml; do
if [ -f "$file" ]; then
bin/mjml-compile "$file"
fi
done
done