|  | 
| 51 | 51 |           "v$manifest_version" ) | 
| 52 | 52 |             echo 'OK: Release name/version agrees with Cargo.toml version.' | 
| 53 | 53 |             ;; | 
| 54 |  | -          TEST-* | *-DO-NOT-USE ) | 
|  | 54 | +          TEST-* | *-DO-NOT-USE )  # NOTE: If changed, change it in `announce-release` below, too. | 
| 55 | 55 |             echo 'OK: Release name/version is strange but marked as such.' | 
| 56 | 56 |             ;; | 
| 57 | 57 |           "$manifest_version" ) | 
| @@ -429,6 +429,83 @@ jobs: | 
| 429 | 429 |         env: | 
| 430 | 430 |           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | 
| 431 | 431 | 
 | 
|  | 432 | +  # Comment in a locked discussion that notifies about only `gitoxide` (e.g. not `gix-*`) releases. | 
|  | 433 | +  announce-release: | 
|  | 434 | +    runs-on: ubuntu-latest | 
|  | 435 | + | 
|  | 436 | +    needs: [ create-release, publish-release ] | 
|  | 437 | + | 
|  | 438 | +    permissions: | 
|  | 439 | +      contents: write  # Needed to distinguish unpublished (still draft) from missing releases. | 
|  | 440 | +      discussions: write | 
|  | 441 | + | 
|  | 442 | +    env: | 
|  | 443 | +      REPOSITORY: ${{ github.repository }} | 
|  | 444 | +      VERSION: ${{ needs.create-release.outputs.version }} | 
|  | 445 | +      DISCUSSION_URL: ${{ vars.RELEASE_ANNOUNCEMENTS_URL }} | 
|  | 446 | +      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | 
|  | 447 | + | 
|  | 448 | +    steps: | 
|  | 449 | +      - name: Find the discussion ID | 
|  | 450 | +        run: | | 
|  | 451 | +          [[ "$DISCUSSION_URL" =~ ^https://github\.com/([^/:@]+)/([^/:@]+)/discussions/([0-9]+)$ ]] | 
|  | 452 | +          owner="${BASH_REMATCH[1]}" | 
|  | 453 | +          name="${BASH_REMATCH[2]}" | 
|  | 454 | +          number="${BASH_REMATCH[3]}" | 
|  | 455 | +
 | 
|  | 456 | +          id="$(gh api graphql -f query=' | 
|  | 457 | +          query GetDiscussionId($owner: String!, $name: String!, $number: Int!) { | 
|  | 458 | +            repository(owner: $owner, name: $name) { | 
|  | 459 | +              discussion(number: $number) { | 
|  | 460 | +                id | 
|  | 461 | +              } | 
|  | 462 | +            } | 
|  | 463 | +          }' -F owner="$owner" -F name="$name" -F number="$number" --jq .data.repository.discussion.id)" | 
|  | 464 | +
 | 
|  | 465 | +          echo "DISCUSSION_ID=$id" >> "$GITHUB_ENV" | 
|  | 466 | +
 | 
|  | 467 | +      - name: Avoid announcing a test in a non-test thread | 
|  | 468 | +        run: | | 
|  | 469 | +          case "$VERSION" in | 
|  | 470 | +          TEST-* | *-DO-NOT-USE )  # NOTE: Should be the same pattern as in `create-release` above. | 
|  | 471 | +            echo "The release name indicates testing, so we'll only post if the thread is for that." | 
|  | 472 | +            ;; | 
|  | 473 | +          * ) | 
|  | 474 | +            is_draft="$(gh release --repo="$REPOSITORY" view "$VERSION" --json isDraft --jq .isDraft)" | 
|  | 475 | +            if [ "$is_draft" = false ]; then | 
|  | 476 | +              exit 0  # OK to post in a non-test announcement thread. | 
|  | 477 | +            fi | 
|  | 478 | +            echo "The release is not published, so we'll only post if the thread is for testing." | 
|  | 479 | +            ;; | 
|  | 480 | +          esac | 
|  | 481 | +
 | 
|  | 482 | +          title="$(gh api graphql -f query=' | 
|  | 483 | +          query($id: ID!) { | 
|  | 484 | +            node(id: $id) { | 
|  | 485 | +              ... on Discussion { | 
|  | 486 | +                title | 
|  | 487 | +              } | 
|  | 488 | +            } | 
|  | 489 | +          }' -F id="$DISCUSSION_ID" --jq .data.node.title)" | 
|  | 490 | +
 | 
|  | 491 | +          grep -Eiqz '^[[(]?test\b' <<<"$title" | 
|  | 492 | +
 | 
|  | 493 | +      - name: Post the comment | 
|  | 494 | +        run: | | 
|  | 495 | +          grep -Eqx '[[:alnum:]._+-]+' <<<"$VERSION"  # Ensure the version needs no sanitization. | 
|  | 496 | +          release_url="https://github.com/$REPOSITORY/releases/tag/$VERSION" | 
|  | 497 | +          comment_body="\`gitoxide\` [$VERSION]($release_url) has been released." | 
|  | 498 | +
 | 
|  | 499 | +          gh api graphql -f query=' | 
|  | 500 | +          mutation PostComment($discussionId: ID!, $body: String!) { | 
|  | 501 | +            addDiscussionComment(input: {discussionId: $discussionId, body: $body}) { | 
|  | 502 | +              comment { | 
|  | 503 | +                id | 
|  | 504 | +                body | 
|  | 505 | +              } | 
|  | 506 | +            } | 
|  | 507 | +          }' -F discussionId="$DISCUSSION_ID" -F body="$comment_body" | 
|  | 508 | +
 | 
| 432 | 509 |   installation: | 
| 433 | 510 |     strategy: | 
| 434 | 511 |       matrix: | 
|  | 
0 commit comments