Create OCWM Monthly #83
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 23 * * 1" # Runs at 11:00 PM every Monday | |
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: | | |
# Get the first day of the next month | |
next_month=$(date -u -d "$(date +%Y-%m-01) +1 month" +%Y-%m-01) | |
# Find the first Monday of the next month | |
first_monday=$(date -u -d "$next_month +$(( (8 - $(date -u -d "$next_month" +%u)) % 7 )) days" +%Y-%m-%d) | |
# Calculate the third Monday by adding 14 days to the first Monday | |
third_monday=$(date -u -d "$first_monday +14 days" +%Y-%m-%d) | |
# Output the issue title with the third Monday's date | |
echo "title=Open Community Working Meeting ${third_monday} - 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-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..." | |
echo "::set-output name=is-third-monday::false" | |
exit 0 | |
fi | |
if [ "$day" -ge 15 ] && [ "$day" -le 21 ]; then | |
echo "This is the third Monday of the month!" | |
echo "::set-output name=is-third-monday::true" | |
else | |
echo "Not the third Monday, exiting..." | |
echo "::set-output name=is-third-monday::false" | |
exit 0 | |
fi | |
- name: Create Issue using Template | |
id: create-issue | |
if: steps.check-third-tuesday.outputs.is-third-monday == 'true' | |
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 | |
if: steps.check-third-tuesday.outputs.is-third-tuesday == 'true' | |
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, | |
}); |