Create OCWM Monthly #72
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: Create OCWM Monthly | |
on: | |
schedule: | |
- cron: "0 9 * * 2" # Runs at 9:00 AM every Tuesday | |
repository_dispatch: | |
types: ocwm-creator | |
jobs: | |
create-issue: | |
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: Get Token | |
uses: actions/create-github-app-token@v1 | |
id: get_workflow_token | |
with: | |
app-id: ${{ vars.APP_ID }} | |
private-key: ${{ secrets.PRIVATE_KEY }} | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.8' | |
- name: Generate Issue Title | |
id: create-title | |
run: | | |
date=$(date -u -d "6 days" +%Y-%m-%d) | |
echo "title=Open Community Working Meeting ${date} - 12:00 PT" >> "$GITHUB_OUTPUT" | |
# Step to check if it's the third Tuesday of the month | |
- name: Check if today is the third Tuesday | |
id: check-third-tuesday | |
run: | | |
day=$(date +%d) | |
dow=$(date +%u) # Day of the week (1 = Monday, ..., 7 = Sunday) | |
# Get the first day of this month | |
first_tuesday=$(cal | awk '/^..$/ {print $3}') | |
if [ "$dow" -ne 2 ]; then | |
echo "Not a Tuesday, exiting..." | |
exit 0 | |
fi | |
# Calculate the third Tuesday by checking if the current date is between 15th and 21st | |
if [ "$day" -ge 15 ] && [ "$day" -le 21 ]; then | |
echo "This is the third Tuesday of the month!" | |
else | |
echo "Not the third Tuesday, exiting..." | |
exit 0 | |
fi | |
- name: Create Issue using Template | |
id: create-issue | |
uses: peter-evans/create-issue-from-file@v5 | |
with: | |
title: ${{ steps.create-title.outputs.title }} | |
content-filepath: .github/ISSUE_TEMPLATE/open_community_working_meeting.md | |
labels: 'Working Meeting' | |
token: ${{ steps.get_workflow_token.outputs.token }} | |
- name: Install dependencies | |
run: npm install @octokit/[email protected] | |
- name: Update Issue Body | |
uses: actions/github-script@v7 | |
env: | |
MY_TOKEN: ${{ steps.get_workflow_token.outputs.token }} | |
SLACK_WEBHOOK: ${{ vars.SLACK_WEBHOOK }} | |
with: | |
script: | | |
const octokit = require('@octokit/core').Octokit; | |
const mygithub = new octokit({ | |
request: { fetch: fetch,}, | |
auth: process.env.MY_TOKEN | |
}); | |
console.log("Token:" + process.env.MY_TOKEN); | |
const ocwmnumber = ${{ steps.create-issue.outputs.issue-number }}; | |
const { data: ocwmissue } = await mygithub.request(`GET /repos/${context.repo.owner}/${context.repo.repo}/issues/${ ocwmnumber }`, { | |
}) | |
console.log("OCWM Issue:" + JSON.stringify(ocwmissue)); | |
const newBody = `## ${ocwmissue.title}\n\n${ocwmissue.body.split('\n').slice(6).join('\n')}`; | |
await mygithub.request(`PATCH /repos/${context.repo.owner}/${context.repo.repo}/issues/${ ocwmnumber }`, { | |
body: newBody, | |
milestone: null, | |
state: 'open', | |
}) | |
const newTitle = ocwmissue.title; | |
const issueDate = newTitle.replace(/Open Community Working Meeting /g, ""); | |
// Notify Slack | |
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK; | |
const SLACK_MESSAGE = `{ | |
"issue": "https://github.com/${context.repo.owner}/${context.repo.repo}/issues/${ocwmnumber}", | |
"date": "${issueDate}" | |
}`; | |
await fetch(SLACK_WEBHOOK_URL, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: SLACK_MESSAGE, | |
}); |