Skip to content

Commit

Permalink
Automate Slack release announcement. (pantsbuild#19411)
Browse files Browse the repository at this point in the history
A future change will do the same for email.
  • Loading branch information
benjyw authored Jul 5, 2023
1 parent 062ec62 commit e9c46cc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,18 @@ jobs:
packages-dir: dest/pypi_release
password: ${{ secrets.PANTSBUILD_PYPI_API_TOKEN }}
skip-existing: true
- name: Generate announcement
run: './pants run src/python/pants_release/generate_release_announcement.py --
--channel=slack >> ${{ runner.temp }}/slack_announcement.json
'
- env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
name: Announce to Slack
uses: slackapi/[email protected]
with:
channel-id: C18RRR4JK
payload-file-path: ${{ runner.temp }}/slack_announcement.json
- env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down
18 changes: 18 additions & 0 deletions src/python/pants_release/generate_github_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,24 @@ def release_jobs_and_inputs() -> tuple[Jobs, dict[str, Any]]:
"skip-existing": True,
},
},
{
"name": "Generate announcement",
"run": dedent(
"""\
./pants run src/python/pants_release/generate_release_announcement.py \
-- --channel=slack >> ${{ runner.temp }}/slack_announcement.json
"""
),
},
{
"name": "Announce to Slack",
"uses": "slackapi/[email protected]",
"with": {
"channel-id": "C18RRR4JK",
"payload-file-path": "${{ runner.temp }}/slack_announcement.json",
},
"env": {"SLACK_BOT_TOKEN": f"{gha_expr('secrets.SLACK_BOT_TOKEN')}"},
},
deploy_to_s3(
"Deploy commit mapping to S3",
scope="tags/pantsbuild.pants",
Expand Down
33 changes: 31 additions & 2 deletions src/python/pants_release/generate_release_announcement.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import argparse
import json
from pathlib import Path

from pants_release.common import sorted_contributors
Expand Down Expand Up @@ -50,5 +51,33 @@ def announcement_text() -> str:
return announcement


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"--channel",
required=True,
choices=["slack", "email"],
help="Which channel to generate the announcement for.",
)
options = parser.parse_args()
if options.channel == "slack":
announcement = json.dumps(
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": announcement_text(),
},
},
]
}
)
else:
announcement = announcement_text()
print(announcement)


if __name__ == "__main__":
print(announcement_text())
main()

0 comments on commit e9c46cc

Please sign in to comment.