Skip to content

Commit

Permalink
Do the title check if the release is still a draft
Browse files Browse the repository at this point in the history
For testing, this checks the discussion title only when the release
is unpublished. Just for now, it does not also do the check in the
previously covered case where the release is named to indicate that
it exists to test releasing rather than being a "real" release.

Really, we should test both, and we should probably check the name
first, since when both apply, the name indicating that it is not
even an actual release is the more important reason to avoid
announcing it by commenting in a discussion for real release
announcements. But the name check is temporarily commented out, in
order to more easily test the draft status check.

This checks whether the release is a draft by actually accessing
the release, rather than repeating the check from the final step in
the preceding `publish-release` job for whether it *should* be
published, and also rather than storing and retrieving information
about whether that job did publish it.

The reason to actually check the release is that the draft status
can be changed manually in either direction at any time:

- Changing it between the jobs is plausible if one notices that
  something is unexpectedly broken (or unexpectedly okay).

- But the more important reason is that we have to check each time,
  rather than using any state from the previous jobs we depend on,
  if we are to work as expected when the `announce-release` job
  itself is re-run (which makes sense to do, for example, if one
  has fixed a problem and manually marked a release non-draft).

This change also refactors the steps, combining the two last steps
in the job. The combination of the new `gh` invocation to check the
draft status, and the consolation of those two steps, makes it so
`GITHUB_TOKEN` is used in all steps and `REPOSITORY` is used in
multiple steps. So this moves them from per-step `env` to job-level
`env`.

That leaves `DISCUSSION_URL` as the only step-level `env` key.
Since it's not sensitive, nor likely to be used accidentally
anywhere it shouldn't, it is also moved to the job-level `env` so
it's easier to see what the job depends on.
  • Loading branch information
EliahKagan committed Nov 20, 2024
1 parent e292a81 commit 4c1f540
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,10 @@ jobs:
discussions: write

env:
REPOSITORY: ${{ github.repository }}
VERSION: ${{ needs.create-release.outputs.version }}
DISCUSSION_URL: ${{ vars.RELEASE_ANNOUNCEMENTS_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Find the discussion ID
Expand All @@ -459,43 +462,40 @@ jobs:
}' -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!
# FIXME: Uncomment name-checking case, after testing the draft-checking case!
- 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"
# TEST-* | *-DO-NOT-USE ) # NOTE: Should be the same pattern as in `create-release` above.
# echo "The release name indicates testing, so we'll only post if the thread is for that."
# ;;
* )
is_draft="$(gh release --repo="$REPOSITORY" view "$VERSION" --json isDraft --jq .isDraft)"
if [ "$is_draft" = false ]; then
exit 0 # OK to post in a non-test announcement thread.
fi
echo "The release is not published, so we'll only post if the thread is for testing."
;;
esac
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Compose the comment
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"
- name: Post 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}) {
Expand All @@ -504,9 +504,7 @@ jobs:
body
}
}
}' -F discussionId="$DISCUSSION_ID" -F body="$COMMENT_BODY"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
}' -F discussionId="$DISCUSSION_ID" -F body="$comment_body"
installation:
strategy:
Expand Down

0 comments on commit 4c1f540

Please sign in to comment.