From cd0df2d617c3959ebcf5459ab3a7be3147a8126c Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Tue, 5 Mar 2024 14:05:58 -0500 Subject: [PATCH] update change log script --- .github/resources/changelog-generator.py | 40 +++++++++++++------ .../workflows/generate-release-changelog.yml | 18 ++++----- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/.github/resources/changelog-generator.py b/.github/resources/changelog-generator.py index 1e8c67871..7dd8140ee 100644 --- a/.github/resources/changelog-generator.py +++ b/.github/resources/changelog-generator.py @@ -12,7 +12,7 @@ import uuid REPO_OWNER = "infisical" REPO_NAME = "infisical" TOKEN = os.environ["GITHUB_TOKEN"] -# SLACK_WEBHOOK_URL = os.environ["SLACK_WEBHOOK_URL"] +SLACK_WEBHOOK_URL = os.environ["SLACK_WEBHOOK_URL"] OPENAI_API_KEY = os.environ["OPENAI_API_KEY"] SLACK_MSG_COLOR = "#36a64f" @@ -30,6 +30,23 @@ def set_multiline_output(name, value): print(value, file=fh) print(delimiter, file=fh) +def post_changelog_to_slack(changelog, tag): + slack_payload = { + "text": "Hey team, it's changelog time! :wave:", + "attachments": [ + { + "color": SLACK_MSG_COLOR, + "title": f"🗓️Infisical Changelog - {tag}", + "text": changelog, + } + ], + } + + response = requests.post(SLACK_WEBHOOK_URL, json=slack_payload) + + if response.status_code != 200: + raise Exception("Failed to post changelog to Slack.") + def find_previous_release_tag(release_tag:str): previous_tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0", f"{release_tag}^"]).decode("utf-8").strip() while not(previous_tag.startswith("infisical/")): @@ -123,20 +140,17 @@ The changelog should: 6. Linear Links: note that the Linear link is optional, include it only if provided. 7. Do not wrap your answer in a codeblock. Just output the text, nothing else Here's a good example to follow, please try to match the formatting as closely as possible, only changing the content of the changelog and have some liberty with the introduction. Notice the importance of the formatting of a changelog item: -``` -- : We optimize our ci to strip comments and minify production builds. ()) -``` +- : We optimize our ci to strip comments and minify production builds. ()) And here's an example of the full changelog: -``` + *Features* -• : We optimize our ci to strip comments and minify production builds. () +• : We optimize our ci to strip comments and minify production builds. () *Fixes & Improvements* -• : We optimize our ci to strip comments and minify production builds. () +• : We optimize our ci to strip comments and minify production builds. () *Technical Updates* -• : We optimize our ci to strip comments and minify production builds. () +• : We optimize our ci to strip comments and minify production builds. () Stay tuned for more exciting updates coming soon! -``` And here are the commits: {} """.format( @@ -166,11 +180,11 @@ if __name__ == "__main__": pr_details = extract_commit_details_from_prs(prs) # Generate changelog - changelog = f"## Infisical - {latest_tag}\n\n{generate_changelog_with_openai(pr_details)}" + changelog = generate_changelog_with_openai(pr_details) + post_changelog_to_slack(changelog,latest_tag) # Print or post changelog to Slack - set_multiline_output("changelog", changelog) + # set_multiline_output("changelog", changelog) except Exception as e: - print(str(e)) - + print(str(e)) \ No newline at end of file diff --git a/.github/workflows/generate-release-changelog.yml b/.github/workflows/generate-release-changelog.yml index 48e35497d..de14f288a 100644 --- a/.github/workflows/generate-release-changelog.yml +++ b/.github/workflows/generate-release-changelog.yml @@ -2,7 +2,10 @@ name: Generate Changelog permissions: contents: write -on: [workflow_dispatch] +on: + push: + tags: + - "infisical/v*.*.*-postgres" jobs: generate_changelog: @@ -10,6 +13,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + fetch-tags: true - name: Set up Python uses: actions/setup-python@v5 with: @@ -24,13 +29,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - - name: Set git identity - run: | - git config user.name 'github-actions[bot]' - git config user.email 'github-actions[bot]@infisical.noreply.github.com' - - name: Save the changelog to file - run: | - echo "${{ steps.gen-changelog.outputs.changelog }}" >> CHANGELOG.md - git add CHANGELOG.md - git commit -m "chore: changelog update" --no-verify - git push origin main + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file