diff --git a/.github/workflows/agenda.yaml b/.github/workflows/agenda.yaml index 9389510..f46f5d4 100644 --- a/.github/workflows/agenda.yaml +++ b/.github/workflows/agenda.yaml @@ -7,15 +7,15 @@ on: - cron: '0 17 * * 2' jobs: - create-discussion: - permissions: - discussions: write + get-next-dates: + permissions: {} runs-on: ubuntu-22.04 + outputs: + meeting_dates: ${{ steps.get-next-meeting-dates.outputs.MEETING_DATES }} env: - CATEGORY_ID: 'DIC_kwDOFXMeLs4COVB8' - REPOSITORY_ID: 'MDEwOlJlcG9zaXRvcnkzNTk4NjU5MDI=' + NUMBER_OF_INSTANCES: 2 + MEETING_INTERVAL_WEEKS: 2 steps: - - uses: actions/checkout@v5 - name: Check if it's an alternate week id: check-week run: | @@ -29,35 +29,69 @@ jobs: echo "Skipping odd week: $WEEK_NUMBER" echo "should_run=false" >> $GITHUB_OUTPUT fi - - name: Get agenda text from template + - name: Get Next Meeting Dates if: steps.check-week.outputs.should_run == 'true' + id: get-next-meeting-dates + run: | + # Generate multiple meeting dates based on NUMBER_OF_INSTANCES + MEETING_DATES="[" + for i in $(seq 1 $NUMBER_OF_INSTANCES); do + # Calculate the date for the i-th Tuesday from now + # For i=1, get next Tuesday; for i=2, get Tuesday after next, etc. + WEEKS_AHEAD=$(((i - 1)*MEETING_INTERVAL_WEEKS)) + if [ $i -eq 1 ]; then + DATE_CMD="next Tuesday" + else + DATE_CMD="next Tuesday +${WEEKS_AHEAD} weeks" + fi + MEETING_DATE=$(date -d "$DATE_CMD" +%Y-%m-%d) + if [ $i -eq 1 ]; then + MEETING_DATES="$MEETING_DATES\"$MEETING_DATE\"" + else + MEETING_DATES="$MEETING_DATES,\"$MEETING_DATE\"" + fi + done + MEETING_DATES="$MEETING_DATES]" + echo "MEETING_DATES=$MEETING_DATES" >> $GITHUB_OUTPUT + - name: Set No Next Meeting Dates + if: steps.check-week.outputs.should_run == 'false' + run: | + echo "MEETING_DATES=[]" >> $GITHUB_OUTPUT + + create-discussion: + needs: get-next-dates + strategy: + matrix: + next_meeting_date: ${{ fromJson(needs.get-next-dates.outputs.meeting_dates) }} + runs-on: ubuntu-22.04 + env: + CATEGORY_ID: 'DIC_kwDOFXMeLs4COVB8' + REPOSITORY_ID: 'MDEwOlJlcG9zaXRvcnkzNTk4NjU5MDI=' + permissions: + discussions: write + contents: read + steps: + - uses: actions/checkout@v5 + - name: Get agenda text from template id: get-agenda run: | echo 'AGENDA<> $GITHUB_ENV cat .github/templates/agenda.md >> $GITHUB_ENV echo 'EOF' >> $GITHUB_ENV - - name: Get Next Meeting Date - if: steps.check-week.outputs.should_run == 'true' - id: get-next-meeting-date - run: | - NEXT_MEETING_DATE=$(date -d "next Tuesday" +%Y-%m-%d) - echo "NEXT_MEETING_DATE=$NEXT_MEETING_DATE" >> $GITHUB_ENV - name: Define discussion title - if: steps.check-week.outputs.should_run == 'true' id: define-title run: | - DISCUSSION_TITLE="Overlays Meeting (${{ env.NEXT_MEETING_DATE }})" + DISCUSSION_TITLE="Overlays Meeting (${{ matrix.next_meeting_date }})" echo "DISCUSSION_TITLE=$DISCUSSION_TITLE" >> $GITHUB_ENV - name: Search for existing discussion - if: steps.check-week.outputs.should_run == 'true' id: search-discussion env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - FOUND_DISCUSSION_TITLE=$(gh api graphql -f query=' + FOUND_DISCUSSIONS=$(gh api graphql -f query=' query SearchDiscussionMutation ($repositoryOwner: String!, $repositoryName: String!, $categoryId: ID!) { repository(owner: $repositoryOwner, name: $repositoryName) { - discussions(first: 1, orderBy: {direction: DESC, field: CREATED_AT}, categoryId: $categoryId) { + discussions(first: 10, orderBy: {direction: DESC, field: CREATED_AT}, categoryId: $categoryId) { nodes { title } @@ -67,16 +101,23 @@ jobs: -f repositoryOwner="${{ github.repository_owner }}" \ -f repositoryName="${{ github.event.repository.name }}" \ -f categoryId="${{ env.CATEGORY_ID }}" \ - --jq '.data.repository.discussions.nodes[0].title') - if [ "$FOUND_DISCUSSION_TITLE" = "${{ env.DISCUSSION_TITLE }}" ]; then - DISCUSSION_COUNT=1 - else - DISCUSSION_COUNT=0 - fi + --jq '.data.repository.discussions.nodes[].title') + + DISCUSSION_COUNT=0 + TARGET_TITLE="${{ env.DISCUSSION_TITLE }}" + + # Iterate through all returned discussion titles + while IFS= read -r discussion_title; do + if [ "$discussion_title" = "$TARGET_TITLE" ]; then + DISCUSSION_COUNT=1 + break + fi + done <<< "$FOUND_DISCUSSIONS" + echo "DISCUSSION_COUNT=$DISCUSSION_COUNT" >> $GITHUB_OUTPUT - echo "Found $DISCUSSION_COUNT existing discussions" + echo "Found $DISCUSSION_COUNT existing discussions with title: $TARGET_TITLE" - name: Create discussion with agenda - if: steps.check-week.outputs.should_run == 'true' && steps.search-discussion.outputs.DISCUSSION_COUNT == '0' + if: steps.search-discussion.outputs.DISCUSSION_COUNT == '0' id: create-repository-discussion env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}