Skip to content

Commit

Permalink
Start on announce-release job
Browse files Browse the repository at this point in the history
Some users and developers, such as downstream package maintainers,
would benefit from a way to subscribe on GitHub to notifications
for releases associated with the `gitoxide` crate, i.e. the
releases done via `release.yml`, but not of the many `gix-` crates
that they would also be notified about if they watched releases via
the GitHub watch feature.

The idea here is to create a way for people to easily be notified
by subscribing to a specific locked discussion thread that a GitHub
Actions job posts after publishing a `gitoxide` release.

I am testing this with #6, but that is just for testing.
If this is used, the actual announcements "discussion" thread would
be separate, and on GitoxideLabs/gitoxide (not on a fork).
  • Loading branch information
EliahKagan committed Nov 20, 2024
1 parent 700cfa5 commit 47ab5e8
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
"v$manifest_version" )
echo 'OK: Release name/version agrees with Cargo.toml version.'
;;
TEST-* | *-DO-NOT-USE )
TEST-* | *-DO-NOT-USE ) # NOTE: If changed, change it in `announce-release` below, too.
echo 'OK: Release name/version is strange but marked as such.'
;;
"$manifest_version" )
Expand Down Expand Up @@ -429,6 +429,85 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

announce-release:
runs-on: ubuntu-latest

needs: [ create-release, publish-release ]

permissions:
contents: read
discussions: write

env:
VERSION: ${{ needs.create-release.outputs.version }}

steps:
- name: Find the discussion ID
run: |
[[ "$DISCUSSION_URL" =~ ^https://github\.com/([^/:@]+)/([^/:@]+)/discussions/([0-9]+)$ ]]
owner="${BASH_REMATCH[1]}"
name="${BASH_REMATCH[2]}"
number="${BASH_REMATCH[3]}"
id="$(gh api graphql -f query='
query GetDiscussionId($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
discussion(number: $number) {
id
}
}
}' -F owner="$owner" -F name="$name" -F number="$number" --jq .data.repository.discussion.id)"
echo "DISCUSSION_ID=$id" >> "$GITHUB_ENV"
env:
DISCUSSION_URL: ${{ vars.RELEASE_ANNOUNCEMENTS_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# FIXME: Also consider a release of any name as a test, if it has not been published!
- name: Avoid announcing a test in a non-test thread
run: |
case "$VERSION" in
TEST-* | *-DO-NOT-USE ) # NOTE: Should be the same pattern as in `create-release` above.
echo "Looks like we're testing releasing. Checking discussion title."
title="$(gh api graphql -f query='
query($id: ID!) {
node(id: $id) {
... on Discussion {
title
}
}
}' -F id="$DISCUSSION_ID" --jq .data.node.title)"
grep -Eiqz '^[[(]?test\b' <<<"$title"
;;
esac
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Compose the comment
run: |
grep -Eqx '[[:alnum:]._+-]+' <<<"$VERSION" # Ensure the version needs no sanitization.
release_url="https://github.com/$REPOSITORY/releases/tag/$VERSION"
comment_body="`gitoxide` [$VERSION]($release_url) has been released."
echo "COMMENT_BODY=$comment_body" >> "$GITHUB_ENV"
env:
REPOSITORY: ${{ github.repository }}

- name: Post the comment
run: |
gh api graphql -f query='
mutation PostComment($discussionId: ID!, $body: String!) {
addDiscussionComment(input: {discussionId: $discussionId, body: $body}) {
comment {
id
body
}
}
}' -F discussionId="$DISCUSSION_ID" -F body="$COMMENT_BODY"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

installation:
strategy:
matrix:
Expand Down

0 comments on commit 47ab5e8

Please sign in to comment.