Skip to content

meaningless changes to trigger workflows #11

meaningless changes to trigger workflows

meaningless changes to trigger workflows #11

name: buildAndSendSignatures
on:
push:
branches:
- 'master'
paths:
- 'data/**.json'
- 'templates/template.html'
env:
GH_ACTIONS_ENV: true
MODIFIED_PATHS: ${{ toJson(github.event.pusher.changes) }}
jobs:
build_and_send_signatures:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
# https://stackoverflow.com/questions/74265821/get-modified-files-in-github-actions
- name: Get changed files
id: changed-files
run: |
# Get modified files as input
input_text=""
if ${{ github.event_name == 'pull_request' }}; then
input_text="$(git diff --name-only -r HEAD^1 HEAD | xargs)"
else
input_text="$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)"
fi
# Detect if the template has been modified
template_modified=false
for file in ${input_text}; do
if [ "templates/template.html" = "${file}" ]; then
template_modified=true
fi
done
# Select the signatures that are going to be built
signatures_to_build=""
if [ "${template_modified}" = "false" ]; then
for file in ${input_text}; do
if grep -q "/" < "${file}" && [ "$(echo "${file}" | cut -f1 -d "/")" = "data" ]; then
if grep -q "." < "${file}"; then
signatures_to_build="$(echo "${file}" | cut -d "/" -f2 | cut -d "." -f1) ${signatures_to_build}"
fi
fi
done
else # template_modified = true
for file in data/*.json; do
signatures_to_build="$(echo "${file}" | cut -d "/" -f2 | cut -d "." -f1) ${signatures_to_build}"
done
fi
echo "signatures_to_build=${signatures_to_build}"
echo "signatures_to_build=${signatures_to_build}" >> $GITHUB_OUTPUT
# Build the list of files that have to be sent via email
file_to_send=""
for file in ${signatures_to_build}; do
files_to_send="./out/${file}.html ${files_to_send}"
done
echo "files_to_send=${files_to_send}"
echo "files_to_send=${files_to_send}" >> $GITHUB_OUTPUT
- name: List changed files
run: |
echo "Signatures to build:"
for file in ${{ steps.changed-files.outputs.signatures_to_build }}; do
echo "$file"
done
echo "Files to send:"
for file in ${{ steps.changed-files.outputs.files_to_send }}; do
echo "$file"
done
- name: Substitute marks (implicit parameters in env)
run: |
chmod u+x src/substituteMarks.sh
./src/substituteMarks.sh ${{ steps.changed-files.outputs.signatures_to_build }}
- name: Set up nodeJS
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Render signatures
run: |
npm install
node ./src/renderSignatures.js
- name: Send emails
id: send-emails
run: |
for signature in ${{ steps.changed-files.outputs.signatures_to_build }}; do
pointer="$(echo "${signature}" | tr '[:lower:]' '[:upper:]')_EMAIL"
email_value="${!pointer}"
echo curl --url 'smtps://smtp.gmail.com:465' \
--ssl-reqd \
--mail-from '${{secrets.EMAIL_USERNAME}}' \
--mail-rcpt '${email_value}' \
--user '${{secrets.EMAIL_USERNAME}}:${{secrets.EMAIL_PASSWORD}}' \
--upload-file "out/${signature}.html"
curl --url 'smtps://smtp.gmail.com:465' \
--ssl-reqd \
--mail-from '${{secrets.EMAIL_USERNAME}}' \
--mail-rcpt '${email_value}' \
--user '${{secrets.EMAIL_USERNAME}}:${{secrets.EMAIL_PASSWORD}}' \
--upload-file "out/${signature}.html"
done