Skip to content

Commit

Permalink
feat(scripts): add timestamp update to check-connect-data
Browse files Browse the repository at this point in the history
  • Loading branch information
karliatto authored and tomasklim committed Feb 18, 2025
1 parent 24a9dae commit 772e758
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions scripts/ci/check-connect-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,30 @@ const fetchJSON = async (url: string) => {
return response.json();
};

const getLatestTimestamp = (timestamps: string[]): string | null => {
if (timestamps.length === 0) {
return null;
}

const latestTime = Math.max(...timestamps.map(Date.parse));

return new Date(latestTime).toISOString();
};

const updateConfigFromJSON = async () => {
try {
const devicesKeys = Object.keys(authenticityPaths) as AuthenticityPathsKeys[];

// Import the current configuration object
let { deviceAuthenticityConfig } = require(CONFIG_FILE_PATH);

const timestamps: string[] = [];

for (const deviceKey of devicesKeys) {
const { authenticity, authenticityDev } = authenticityPaths[deviceKey];
const authenticityUrl = `${AUTHENTICITY_BASE_URL}/${authenticity}`;
const authenticityData = await fetchJSON(authenticityUrl);
timestamps.push(authenticityData.timestamp);
const authenticityDevUrl = `${AUTHENTICITY_BASE_URL}/${authenticityDev}`;
const authenticityDevData = await fetchJSON(authenticityDevUrl);

Expand All @@ -59,6 +72,15 @@ const updateConfigFromJSON = async () => {
};
}

const latestTimestamp = getLatestTimestamp(timestamps);

if (!latestTimestamp) {
// Sanity check and type safety.
throw new Error('Timestamp should always be present.');
}

deviceAuthenticityConfig['timestamp'] = latestTimestamp;

const updatedConfigString = `
/** THIS FILE IS AUTOMATICALLY UPDATED by script ci/scripts/check-connect-data.ts */
import { DeviceAuthenticityConfig } from './deviceAuthenticityConfigTypes';
Expand Down

0 comments on commit 772e758

Please sign in to comment.