fix(analytics-mailer): strictly enforce monthly reports and remove weekly logic completely
Some checks failed
Monorepo Pipeline / ⚡ Prioritize Release (push) Successful in 3s
Monorepo Pipeline / 🧹 Lint (push) Failing after 1m24s
Monorepo Pipeline / 🧪 Test (push) Successful in 42s
Monorepo Pipeline / 🏗️ Build (push) Successful in 2m10s
Monorepo Pipeline / 🚀 Release (push) Has been skipped
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been skipped
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been skipped
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been skipped
Some checks failed
Monorepo Pipeline / ⚡ Prioritize Release (push) Successful in 3s
Monorepo Pipeline / 🧹 Lint (push) Failing after 1m24s
Monorepo Pipeline / 🧪 Test (push) Successful in 42s
Monorepo Pipeline / 🏗️ Build (push) Successful in 2m10s
Monorepo Pipeline / 🚀 Release (push) Has been skipped
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been skipped
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been skipped
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been skipped
This commit is contained in:
@@ -1,25 +1,14 @@
|
|||||||
name: Analytics Mailer
|
name: Analytics Mailer (Monthly)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
# Run weekly on Monday at 08:00 UTC
|
|
||||||
- cron: '0 8 * * 1'
|
|
||||||
# Run monthly on the 1st day of the month at 08:30 UTC
|
# Run monthly on the 1st day of the month at 08:30 UTC
|
||||||
- cron: '30 8 1 * *'
|
- cron: '30 8 1 * *'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
|
||||||
interval:
|
|
||||||
description: 'Interval to run (weekly or monthly)'
|
|
||||||
required: true
|
|
||||||
default: 'weekly'
|
|
||||||
type: choice
|
|
||||||
options:
|
|
||||||
- weekly
|
|
||||||
- monthly
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
send-reports:
|
send-reports:
|
||||||
name: 📊 Send Analytics Reports
|
name: 📊 Send Analytics Reports (Monthly)
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: catthehacker/ubuntu:act-latest
|
image: catthehacker/ubuntu:act-latest
|
||||||
@@ -56,18 +45,5 @@ jobs:
|
|||||||
- name: Build analytics mailer
|
- name: Build analytics mailer
|
||||||
run: pnpm --filter @mintel/analytics-mailer build
|
run: pnpm --filter @mintel/analytics-mailer build
|
||||||
|
|
||||||
- name: Determine Interval
|
|
||||||
id: set-interval
|
|
||||||
run: |
|
|
||||||
if [ "${{ github.event_name }}" = "schedule" ]; then
|
|
||||||
if [ "${{ github.event.schedule }}" = "0 8 * * 1" ]; then
|
|
||||||
echo "interval=weekly" >> $GITHUB_OUTPUT
|
|
||||||
else
|
|
||||||
echo "interval=monthly" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "interval=${{ github.event.inputs.interval }}" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Run Analytics Mailer
|
- name: Run Analytics Mailer
|
||||||
run: pnpm --filter @mintel/analytics-mailer run start -- --interval=${{ steps.set-interval.outputs.interval }}
|
run: pnpm --filter @mintel/analytics-mailer run start
|
||||||
@@ -4,31 +4,27 @@
|
|||||||
"domain": "klz-cables.com",
|
"domain": "klz-cables.com",
|
||||||
"clientEmail": "klaus.mintel@klz-cables.com, michael.bodemer@klz-cables.com, marc@mintel.me",
|
"clientEmail": "klaus.mintel@klz-cables.com, michael.bodemer@klz-cables.com, marc@mintel.me",
|
||||||
"clientName": "KLZ Cables",
|
"clientName": "KLZ Cables",
|
||||||
"greeting": "Hallo Klaus, hallo Michael,",
|
"greeting": "Hallo Klaus, hallo Michael,"
|
||||||
"interval": "monthly"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"websiteId": "b9035279-72f1-49bc-909d-b073d184c388",
|
"websiteId": "b9035279-72f1-49bc-909d-b073d184c388",
|
||||||
"domain": "mintel.me",
|
"domain": "mintel.me",
|
||||||
"clientEmail": "marc@mintel.me",
|
"clientEmail": "marc@mintel.me",
|
||||||
"clientName": "Mintel.me",
|
"clientName": "Mintel.me",
|
||||||
"greeting": "Hallo Team Mintel,",
|
"greeting": "Hallo Team Mintel,"
|
||||||
"interval": "monthly"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"websiteId": "caa402bc-b2d2-4349-a254-84c0dd2a4460",
|
"websiteId": "caa402bc-b2d2-4349-a254-84c0dd2a4460",
|
||||||
"domain": "mb-grid-solutions.com",
|
"domain": "mb-grid-solutions.com",
|
||||||
"clientEmail": "marc@mintel.me",
|
"clientEmail": "marc@mintel.me",
|
||||||
"clientName": "MB Grid Solutions",
|
"clientName": "MB Grid Solutions",
|
||||||
"greeting": "Hallo Marc,",
|
"greeting": "Hallo Marc,"
|
||||||
"interval": "monthly"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"websiteId": "d773ea10-a3b3-4ccf-9024-987e14c4d669",
|
"websiteId": "d773ea10-a3b3-4ccf-9024-987e14c4d669",
|
||||||
"domain": "e-tib.com",
|
"domain": "e-tib.com",
|
||||||
"clientEmail": "d.joseph@e-tib.com, marc@mintel.me",
|
"clientEmail": "d.joseph@e-tib.com, marc@mintel.me",
|
||||||
"clientName": "E-TIB GmbH",
|
"clientName": "E-TIB GmbH",
|
||||||
"greeting": "Hallo Danny,",
|
"greeting": "Hallo Danny,"
|
||||||
"interval": "monthly"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -3,7 +3,7 @@ import path from "path";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { render } from "@mintel/mail";
|
import { render } from "@mintel/mail";
|
||||||
import { AnalyticsTemplate } from "@mintel/mail";
|
import { AnalyticsTemplate } from "@mintel/mail";
|
||||||
import { getLast7Days, getThisMonth, getThisYear } from "./utils/time-calculator";
|
import { getThisMonth, getThisYear } from "./utils/time-calculator";
|
||||||
import nodemailer from "nodemailer";
|
import nodemailer from "nodemailer";
|
||||||
import * as dotenv from "dotenv";
|
import * as dotenv from "dotenv";
|
||||||
|
|
||||||
@@ -29,7 +29,6 @@ interface ConfigClient {
|
|||||||
clientEmail: string;
|
clientEmail: string;
|
||||||
clientName: string;
|
clientName: string;
|
||||||
greeting?: string;
|
greeting?: string;
|
||||||
interval?: "weekly" | "monthly";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUmamiToken(): Promise<string> {
|
async function getUmamiToken(): Promise<string> {
|
||||||
@@ -107,12 +106,6 @@ export async function fetchUmamiData(api: any, websiteId: string, startAt: numbe
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const isDryRun = process.argv.includes("--dry-run");
|
const isDryRun = process.argv.includes("--dry-run");
|
||||||
const intervalArg = process.argv.find(a => a.startsWith("--interval="));
|
|
||||||
const runInterval = intervalArg ? intervalArg.split("=")[1] : "monthly";
|
|
||||||
|
|
||||||
if (runInterval !== "weekly" && runInterval !== "monthly") {
|
|
||||||
throw new Error("Invalid interval. Use --interval=weekly or --interval=monthly");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load config
|
// Load config
|
||||||
const configPath = path.resolve(process.cwd(), "config.json");
|
const configPath = path.resolve(process.cwd(), "config.json");
|
||||||
@@ -136,19 +129,12 @@ async function main() {
|
|||||||
} : undefined,
|
} : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const timeRanges = runInterval === "weekly"
|
const timeRanges = [getThisMonth(), getThisYear()];
|
||||||
? [getLast7Days(), getThisMonth(), getThisYear()]
|
|
||||||
: [getThisMonth(), getThisYear()];
|
|
||||||
|
|
||||||
console.log(`Generating reports...`);
|
console.log(`Generating reports...`);
|
||||||
|
|
||||||
for (const client of clients) {
|
for (const client of clients) {
|
||||||
if (client.websiteId === "replace-with-umami-website-id") continue;
|
if (client.websiteId === "replace-with-umami-website-id") continue;
|
||||||
const clientInterval = client.interval || "monthly";
|
|
||||||
if (clientInterval !== runInterval) {
|
|
||||||
console.log(`Skipping ${client.domain} (runs ${clientInterval}, currently executing ${runInterval})`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Processing ${client.domain} (${client.clientName})...`);
|
console.log(`Processing ${client.domain} (${client.clientName})...`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user