-
Notifications
You must be signed in to change notification settings - Fork 1
Fix login redirect bug #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e2347a
Add Slack alert script for CI job notifications
xpertforextradeinc 9809e77
Merge pull request #7 from Global-press/github/workflows/ci.yml
xpertforextradeinc d653f75
Add CI workflow for Jekyll site using Docker
xpertforextradeinc 4924bf3
Upgrade auto-assign action to version 2
xpertforextradeinc 6e9e0f9
Update slack-alert.js
xpertforextradeinc 78975df
Update jekyll-docker.yml
xpertforextradeinc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| }); | ||
| 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)); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.