77 - cron : ' 0 17 * * 2'
88
99jobs :
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 }}
15+ env :
16+ NUMBER_OF_INSTANCES : 2
17+ MEETING_INTERVAL_WEEKS : 2
1418 steps :
15- - uses : actions/checkout@v5
1619 - name : Check if it's an alternate week
1720 id : check-week
1821 run : |
@@ -26,37 +29,109 @@ jobs:
2629 echo "Skipping odd week: $WEEK_NUMBER"
2730 echo "should_run=false" >> $GITHUB_OUTPUT
2831 fi
29- - name : Get agenda text from template
32+ - name : Get Next Meeting Dates
3033 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
3176 id : get-agenda
3277 run : |
3378 echo 'AGENDA<<EOF' >> $GITHUB_ENV
3479 cat .github/templates/agenda.md >> $GITHUB_ENV
3580 echo 'EOF' >> $GITHUB_ENV
36- - name : Get Next Meeting Date
37- if : steps.check-week.outputs.should_run == 'true'
38- id : get-next-meeting-date
81+ - name : Define discussion title
82+ id : define-title
83+ run : |
84+ DISCUSSION_TITLE="Overlays Meeting (${{ matrix.next_meeting_date }})"
85+ echo "DISCUSSION_TITLE=$DISCUSSION_TITLE" >> $GITHUB_ENV
86+ - name : Search for existing discussion
87+ id : search-discussion
88+ env :
89+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3990 run : |
40- NEXT_MEETING_DATE=$(date -d "next Tuesday" +%Y-%m-%d)
41- echo "NEXT_MEETING_DATE=$NEXT_MEETING_DATE" >> $GITHUB_ENV
91+ FOUND_DISCUSSIONS=$(gh api graphql -f query='
92+ query SearchDiscussionMutation ($repositoryOwner: String!, $repositoryName: String!, $categoryId: ID!) {
93+ repository(owner: $repositoryOwner, name: $repositoryName) {
94+ discussions(first: 10, orderBy: {direction: DESC, field: CREATED_AT}, categoryId: $categoryId) {
95+ nodes {
96+ title
97+ }
98+ }
99+ }
100+ }' \
101+ -f repositoryOwner="${{ github.repository_owner }}" \
102+ -f repositoryName="${{ github.event.repository.name }}" \
103+ -f categoryId="${{ env.CATEGORY_ID }}" \
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+
117+ echo "DISCUSSION_COUNT=$DISCUSSION_COUNT" >> $GITHUB_OUTPUT
118+ echo "Found $DISCUSSION_COUNT existing discussions with title: $TARGET_TITLE"
42119 - name : Create discussion with agenda
43- if : steps.check-week .outputs.should_run == 'true '
120+ if : steps.search-discussion .outputs.DISCUSSION_COUNT == '0 '
44121 id : create-repository-discussion
45- 46122 env :
47- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
48- with :
49- variables : |
50- body: "${{ env.AGENDA }}"
51- title: "Overlays Meeting (${{ env.NEXT_MEETING_DATE }})"
52- repositoryId: 'MDEwOlJlcG9zaXRvcnkzNTk4NjU5MDI='
53- categoryId: 'DIC_kwDOFXMeLs4COVB8'
54- query : |
123+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
124+ run : |
125+ gh api graphql -f query='
55126 mutation CreateDiscussionMutation ($title: String!, $body: String!, $repositoryId: ID!, $categoryId: ID!) {
56127 createDiscussion(input: { title: $title, body: $body, repositoryId: $repositoryId, categoryId: $categoryId }) {
57128 discussion {
58129 title
130+ url
59131 }
60132 }
61- }
62-
133+ }' \
134+ -f title="${{ env.DISCUSSION_TITLE }}" \
135+ -f body="${{ env.AGENDA }}" \
136+ -f repositoryId="${{ env.REPOSITORY_ID }}" \
137+ -f categoryId="${{ env.CATEGORY_ID }}"
0 commit comments