Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions .github/workflows/auto-assign.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
name: Auto Assign

on:
issues:
types: [opened]
pull_request:
types: [opened]

jobs:
run:
auto-assign:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- name: 'Auto-assign issue'
uses: pozil/auto-assign-issue@v1
with:
- name: Auto-assign issue or PR
uses: pozil/auto-assign-issue@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
assignees: globalpressinc
numOfAssignee: 1
20 changes: 20 additions & 0 deletions .github/workflows/jekyll-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Jekyll site CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build the site in the jekyll/builder container
run: |
docker run \
-v ${{ github.workspace }}:/srv/jekyll -v ${{ github.workspace }}/_site:/srv/jekyll/_site \
jekyll/builder:latest /bin/bash -c "chmod -R 755 /srv/jekyll && jekyll build --future"
108 changes: 108 additions & 0 deletions scripts/slack-alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* scripts/slack-alert.js
* - Sends a summary Slack message after the CI job completes.
* - Uses SLACK_WEBHOOK_URL secret. Retries with exponential backoff.
* - On repeated failure, logs fallback file to /tmp for audit.
*
* Environment variables (provided by workflow):
* - SLACK_WEBHOOK_URL
* - JOB_STATUS (success / failure / cancelled)
* - REPO, BRANCH, RUN_ID, RUN_NUMBER, ACTOR, EVENT_NAME
*/

const fs = require('fs');
const util = require('util');

const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
const JOB_STATUS = process.env.JOB_STATUS || 'unknown';
const REPO = process.env.REPO || 'unknown/repo';
const BRANCH = process.env.BRANCH || 'unknown';
const RUN_ID = process.env.RUN_ID || '';
const RUN_NUMBER = process.env.RUN_NUMBER || '';
const ACTOR = process.env.ACTOR || '';
const EVENT_NAME = process.env.EVENT_NAME || '';

const FALLBACK_LOG = '/tmp/ci-slack-fallback.log';

if (!SLACK_WEBHOOK_URL) {
console.error('Missing SLACK_WEBHOOK_URL. Writing fallback log.');
writeFallback({ error: 'Missing SLACK_WEBHOOK_URL', env: { REPO, BRANCH, RUN_ID, RUN_NUMBER, ACTOR, EVENT_NAME, JOB_STATUS } });
process.exitCode = 1;
process.exit(1);
}

const statusEmoji = JOB_STATUS === 'success' ? ':white_check_mark:' : JOB_STATUS === 'failure' ? ':x:' : ':warning:';

const message = {
text: `${statusEmoji} CI ${JOB_STATUS.toUpperCase()} - ${REPO}`,
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `*CI ${JOB_STATUS.toUpperCase()}* for *${REPO}*\n*Branch:* ${BRANCH}\n*Run:* <https://github.com/${REPO}/actions/runs/${RUN_ID}|#${RUN_NUMBER}>\n*Triggered by:* ${ACTOR}\n*Event:* ${EVENT_NAME}`
}
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `Generated by global.press0 CI`
}
]
}
]
};

(async () => {
try {
await postWithRetry(SLACK_WEBHOOK_URL, message, 3);
console.log('Slack notification sent.');
} catch (err) {
console.error('Failed to send Slack notification:', err);
await writeFallback({ error: err.message, stack: err.stack, payload: message, env: { REPO, BRANCH, RUN_ID, RUN_NUMBER, ACTOR, EVENT_NAME, JOB_STATUS } });
process.exitCode = 1;
}
})();

async function postWithRetry(url, payload, retries = 3) {
let attempt = 0;
let lastErr;
while (attempt < retries) {
try {
attempt++;
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
// Node 18 global fetch used; if older node, add node-fetch in package.json
Comment on lines +75 to +79
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment mentions that Node 18's global fetch is being used, but there's no validation that the fetch API is available. If this code runs on Node versions prior to 18 (where fetch is not globally available), it will fail with a ReferenceError. Consider adding a check or ensuring the Node version requirement is documented and enforced.

Copilot uses AI. Check for mistakes.
});
if (!res.ok) {
const text = await res.text();
throw new Error(`Unexpected response ${res.status}: ${text}`);
}
return;
} catch (err) {
lastErr = err;
const backoffMs = Math.pow(2, attempt) * 500;
console.warn(`Slack attempt ${attempt} failed. Retrying in ${backoffMs}ms. Error: ${err.message}`);
await sleep(backoffMs);
}
}
throw lastErr;
}

async function writeFallback(obj) {
try {
const payload = { ts: new Date().toISOString(), obj };
await fs.promises.appendFile(FALLBACK_LOG, util.format('%O\n', payload), { encoding: 'utf8' });
console.log(`Wrote fallback log to ${FALLBACK_LOG}`);
} catch (err) {
console.error('Failed writing fallback log:', err);
}
}

function sleep(ms) {
return new Promise((res) => setTimeout(res, ms));
}
Loading