add workflow for Agenda Verification and Notifications before Monday Meetings #3
This file contains 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
name: OCWM Pre-Meeting Check | ||
on: | ||
schedule: | ||
- cron: '50 21 * * 1' # Runs at 11:50 AM PT on the 3rd Monday of the month | ||
workflow_dispatch: | ||
jobs: | ||
check_agenda: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Node 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
- name: Install Dependencies | ||
run: npm install @octokit/core@5.1.0 | ||
- name: Check if today is the third Monday | ||
id: check-third-monday | ||
run: | | ||
echo "third_monday=true" >> $GITHUB_ENV | ||
- name: Check Latest OCWM Issue | ||
id: check_issue | ||
if: ${{ env.third_monday == 'true' }} | ||
env: | ||
MY_TOKEN: ${{ steps.get_workflow_token.outputs.token }} | ||
OWNER: ${{ vars.ORGANISATION }} | ||
REPO: 'community' | ||
OCWM_LABEL: ${{ vars.OCWM_LABEL }} | ||
TEMPLATE_PATH: '../ISSUE_TEMPLATE/open_community_working_meeting.md' | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_GEN_NOTIF }} | ||
run: | | ||
const fs = require('fs'); | ||
const octokit = require('@octokit/core').Octokit; | ||
const mygithub = new octokit({ | ||
request: { fetch: fetch, }, | ||
auth: process.env.MY_TOKEN | ||
}); | ||
// Read the template from the markdown file | ||
const templateContent = fs.readFileSync(process.env.TEMPLATE_PATH, 'utf8'); | ||
// Fetch the latest issue with OCWM_LABEL | ||
const { data: issues } = await mygithub.request(`GET /repos/${process.env.OWNER}/${process.env.REPO}/issues?labels=${encodeURIComponent(process.env.OCWM_LABEL)}&per_page=1`); | ||
if (issues.length === 0) { | ||
console.log("No open community working meeting issues found."); | ||
return; | ||
} | ||
const latestIssue = issues[0]; | ||
const issueBody = latestIssue.body; | ||
// Check if the issue body matches the template | ||
if (issueBody.includes(templateContent)) { | ||
console.log("Template matched, cancelling the meeting."); | ||
// Add a comment to the issue | ||
await mygithub.request(`POST /repos/${process.env.OWNER}/${process.env.REPO}/issues/${latestIssue.number}/comments`, { | ||
body: "The meeting has been cancelled as there is no agenda for today. Thanks everyone!" | ||
}); | ||
// Send a notification to Slack | ||
const slackPayload = { | ||
text: `The meeting has been cancelled as there is no agenda for today. Thanks everyone!` | ||
}; | ||
await fetch(process.env.SLACK_WEBHOOK, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(slackPayload) | ||
}); | ||
} else { | ||
console.log("Agenda found. Meeting will proceed."); | ||
}name: OCWM Pre-Meeting Check | ||
on: | ||
schedule: | ||
- cron: '50 21 * * 1' # Runs at 11:50 AM PT on the 3rd Monday of the month | ||
jobs: | ||
check_agenda: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Node 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
- name: Install Dependencies | ||
run: npm install @octokit/core@5.1.0 | ||
- name: Check if today is the third Monday | ||
id: check-third-monday | ||
run: | | ||
day=$(date +%d) | ||
dow=$(date +%u) # Day of the week (1 = Monday, ..., 7 = Sunday) | ||
# Check if the day is between 15th and 21st, and if it's Monday (1) | ||
if [ "$dow" -ne 1 ]; then | ||
echo "Not a Monday, exiting..." | ||
exit 0 | ||
fi | ||
if [ "$day" -ge 15 ] && [ "$day" -le 21 ]; then | ||
echo "This is the third Monday of the month!" | ||
else: | ||
echo "Not the third Monday, exiting..." | ||
exit 0 | ||
fi | ||
- name: Check Latest OCWM Issue | ||
id: check_issue | ||
uses: actions/github-script@v7 | ||
env: | ||
MY_TOKEN: ${{ steps.get_workflow_token.outputs.token }} | ||
OWNER: ${{ vars.ORGANISATION }} | ||
REPO: 'community' | ||
OCWM_LABEL: ${{ vars.OCWM_LABEL }} | ||
TEMPLATE_PATH: '../ISSUE_TEMPLATE/open_community_working_meeting.md' | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_GEN_NOTIF }} | ||
with: | ||
script: | | ||
const fs = require('fs'); | ||
const octokit = require('@octokit/core').Octokit; | ||
const mygithub = new octokit({ | ||
request: { fetch: fetch, }, | ||
auth: process.env.MY_TOKEN | ||
}); | ||
// Read the template from the markdown file | ||
const templateContent = fs.readFileSync(process.env.TEMPLATE_PATH, 'utf8'); | ||
// Fetch the latest issue with OCWM_LABEL | ||
const { data: issues } = await mygithub.request(`GET /repos/${process.env.OWNER}/${process.env.REPO}/issues?labels=${encodeURIComponent(process.env.OCWM_LABEL)}&per_page=1`); | ||
if (issues.length === 0) { | ||
console.log("No open community working meeting issues found."); | ||
return; | ||
} | ||
const latestIssue = issues[0]; | ||
const issueBody = latestIssue.body; | ||
// Check if the issue body matches the template | ||
if (issueBody.includes(templateContent)) { | ||
console.log("Template matched, cancelling the meeting."); | ||
// Add a comment to the issue | ||
await mygithub.request(`POST /repos/${process.env.OWNER}/${process.env.REPO}/issues/${latestIssue.number}/comments`, { | ||
body: "The meeting has been cancelled as there is no agenda for today. Thanks everyone!" | ||
}); | ||
// Send a notification to Slack | ||
const slackPayload = { | ||
text: `The meeting has been cancelled as there is no agenda for today. Thanks everyone!` | ||
}; | ||
await fetch(process.env.SLACK_WEBHOOK, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(slackPayload) | ||
}); | ||
} else { | ||
console.log("Agenda found. Meeting will proceed."); | ||
} |