Skip to content

Commit 9b23250

Browse files
authored
Merge pull request #208 from OAI/ci/multiple-agendas
ci/multiple agendas
2 parents 8a5b303 + 9386f58 commit 9b23250

File tree

1 file changed

+67
-26
lines changed

1 file changed

+67
-26
lines changed

.github/workflows/agenda.yaml

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ on:
77
- cron: '0 17 * * 2'
88

99
jobs:
10-
create-discussion:
11-
permissions:
12-
discussions: write
10+
get-next-dates:
11+
permissions: {}
1312
runs-on: ubuntu-22.04
13+
outputs:
14+
meeting_dates: ${{ steps.get-next-meeting-dates.outputs.MEETING_DATES }}
1415
env:
15-
CATEGORY_ID: 'DIC_kwDOFXMeLs4COVB8'
16-
REPOSITORY_ID: 'MDEwOlJlcG9zaXRvcnkzNTk4NjU5MDI='
16+
NUMBER_OF_INSTANCES: 2
17+
MEETING_INTERVAL_WEEKS: 2
1718
steps:
18-
- uses: actions/checkout@v5
1919
- name: Check if it's an alternate week
2020
id: check-week
2121
run: |
@@ -29,35 +29,69 @@ jobs:
2929
echo "Skipping odd week: $WEEK_NUMBER"
3030
echo "should_run=false" >> $GITHUB_OUTPUT
3131
fi
32-
- name: Get agenda text from template
32+
- name: Get Next Meeting Dates
3333
if: steps.check-week.outputs.should_run == 'true'
34+
id: get-next-meeting-dates
35+
run: |
36+
# Generate multiple meeting dates based on NUMBER_OF_INSTANCES
37+
MEETING_DATES="["
38+
for i in $(seq 1 $NUMBER_OF_INSTANCES); do
39+
# Calculate the date for the i-th Tuesday from now
40+
# For i=1, get next Tuesday; for i=2, get Tuesday after next, etc.
41+
WEEKS_AHEAD=$(((i - 1)*MEETING_INTERVAL_WEEKS))
42+
if [ $i -eq 1 ]; then
43+
DATE_CMD="next Tuesday"
44+
else
45+
DATE_CMD="next Tuesday +${WEEKS_AHEAD} weeks"
46+
fi
47+
MEETING_DATE=$(date -d "$DATE_CMD" +%Y-%m-%d)
48+
if [ $i -eq 1 ]; then
49+
MEETING_DATES="$MEETING_DATES\"$MEETING_DATE\""
50+
else
51+
MEETING_DATES="$MEETING_DATES,\"$MEETING_DATE\""
52+
fi
53+
done
54+
MEETING_DATES="$MEETING_DATES]"
55+
echo "MEETING_DATES=$MEETING_DATES" >> $GITHUB_OUTPUT
56+
- name: Set No Next Meeting Dates
57+
if: steps.check-week.outputs.should_run == 'false'
58+
run: |
59+
echo "MEETING_DATES=[]" >> $GITHUB_OUTPUT
60+
61+
create-discussion:
62+
needs: get-next-dates
63+
strategy:
64+
matrix:
65+
next_meeting_date: ${{ fromJson(needs.get-next-dates.outputs.meeting_dates) }}
66+
runs-on: ubuntu-22.04
67+
env:
68+
CATEGORY_ID: 'DIC_kwDOFXMeLs4COVB8'
69+
REPOSITORY_ID: 'MDEwOlJlcG9zaXRvcnkzNTk4NjU5MDI='
70+
permissions:
71+
discussions: write
72+
contents: read
73+
steps:
74+
- uses: actions/checkout@v5
75+
- name: Get agenda text from template
3476
id: get-agenda
3577
run: |
3678
echo 'AGENDA<<EOF' >> $GITHUB_ENV
3779
cat .github/templates/agenda.md >> $GITHUB_ENV
3880
echo 'EOF' >> $GITHUB_ENV
39-
- name: Get Next Meeting Date
40-
if: steps.check-week.outputs.should_run == 'true'
41-
id: get-next-meeting-date
42-
run: |
43-
NEXT_MEETING_DATE=$(date -d "next Tuesday" +%Y-%m-%d)
44-
echo "NEXT_MEETING_DATE=$NEXT_MEETING_DATE" >> $GITHUB_ENV
4581
- name: Define discussion title
46-
if: steps.check-week.outputs.should_run == 'true'
4782
id: define-title
4883
run: |
49-
DISCUSSION_TITLE="Overlays Meeting (${{ env.NEXT_MEETING_DATE }})"
84+
DISCUSSION_TITLE="Overlays Meeting (${{ matrix.next_meeting_date }})"
5085
echo "DISCUSSION_TITLE=$DISCUSSION_TITLE" >> $GITHUB_ENV
5186
- name: Search for existing discussion
52-
if: steps.check-week.outputs.should_run == 'true'
5387
id: search-discussion
5488
env:
5589
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5690
run: |
57-
FOUND_DISCUSSION_TITLE=$(gh api graphql -f query='
91+
FOUND_DISCUSSIONS=$(gh api graphql -f query='
5892
query SearchDiscussionMutation ($repositoryOwner: String!, $repositoryName: String!, $categoryId: ID!) {
5993
repository(owner: $repositoryOwner, name: $repositoryName) {
60-
discussions(first: 1, orderBy: {direction: DESC, field: CREATED_AT}, categoryId: $categoryId) {
94+
discussions(first: 10, orderBy: {direction: DESC, field: CREATED_AT}, categoryId: $categoryId) {
6195
nodes {
6296
title
6397
}
@@ -67,16 +101,23 @@ jobs:
67101
-f repositoryOwner="${{ github.repository_owner }}" \
68102
-f repositoryName="${{ github.event.repository.name }}" \
69103
-f categoryId="${{ env.CATEGORY_ID }}" \
70-
--jq '.data.repository.discussions.nodes[0].title')
71-
if [ "$FOUND_DISCUSSION_TITLE" = "${{ env.DISCUSSION_TITLE }}" ]; then
72-
DISCUSSION_COUNT=1
73-
else
74-
DISCUSSION_COUNT=0
75-
fi
104+
--jq '.data.repository.discussions.nodes[].title')
105+
106+
DISCUSSION_COUNT=0
107+
TARGET_TITLE="${{ env.DISCUSSION_TITLE }}"
108+
109+
# Iterate through all returned discussion titles
110+
while IFS= read -r discussion_title; do
111+
if [ "$discussion_title" = "$TARGET_TITLE" ]; then
112+
DISCUSSION_COUNT=1
113+
break
114+
fi
115+
done <<< "$FOUND_DISCUSSIONS"
116+
76117
echo "DISCUSSION_COUNT=$DISCUSSION_COUNT" >> $GITHUB_OUTPUT
77-
echo "Found $DISCUSSION_COUNT existing discussions"
118+
echo "Found $DISCUSSION_COUNT existing discussions with title: $TARGET_TITLE"
78119
- name: Create discussion with agenda
79-
if: steps.check-week.outputs.should_run == 'true' && steps.search-discussion.outputs.DISCUSSION_COUNT == '0'
120+
if: steps.search-discussion.outputs.DISCUSSION_COUNT == '0'
80121
id: create-repository-discussion
81122
env:
82123
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)