-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into feat-support-imports-…
…in-cli-export
- Loading branch information
Showing
1,521 changed files
with
63,901 additions
and
27,121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
# inspired by https://www.photoroom.com/inside-photoroom/how-we-automated-our-changelog-thanks-to-chatgpt | ||
import os | ||
import requests | ||
import re | ||
from openai import OpenAI | ||
import subprocess | ||
from datetime import datetime | ||
|
||
import uuid | ||
|
||
# Constants | ||
REPO_OWNER = "infisical" | ||
REPO_NAME = "infisical" | ||
TOKEN = os.environ["GITHUB_TOKEN"] | ||
SLACK_WEBHOOK_URL = os.environ["SLACK_WEBHOOK_URL"] | ||
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"] | ||
SLACK_MSG_COLOR = "#36a64f" | ||
|
||
headers = { | ||
"Authorization": f"Bearer {TOKEN}", | ||
"Accept": "application/vnd.github+json", | ||
"X-GitHub-Api-Version": "2022-11-28", | ||
} | ||
|
||
|
||
def set_multiline_output(name, value): | ||
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: | ||
delimiter = uuid.uuid1() | ||
print(f'{name}<<{delimiter}', file=fh) | ||
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/")): | ||
previous_tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0", f"{previous_tag}^"]).decode("utf-8").strip() | ||
return previous_tag | ||
|
||
def get_tag_creation_date(tag_name): | ||
url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/git/refs/tags/{tag_name}" | ||
response = requests.get(url, headers=headers) | ||
response.raise_for_status() | ||
commit_sha = response.json()['object']['sha'] | ||
|
||
commit_url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/commits/{commit_sha}" | ||
commit_response = requests.get(commit_url, headers=headers) | ||
commit_response.raise_for_status() | ||
creation_date = commit_response.json()['commit']['author']['date'] | ||
|
||
return datetime.strptime(creation_date, '%Y-%m-%dT%H:%M:%SZ') | ||
|
||
|
||
def fetch_prs_between_tags(previous_tag_date:datetime, release_tag_date:datetime): | ||
# Use GitHub API to fetch PRs merged between the commits | ||
url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/pulls?state=closed&merged=true" | ||
response = requests.get(url, headers=headers) | ||
|
||
if response.status_code != 200: | ||
raise Exception("Error fetching PRs from GitHub API!") | ||
|
||
prs = [] | ||
for pr in response.json(): | ||
# the idea is as tags happen recently we get last 100 closed PRs and then filter by tag creation date | ||
if pr["merged_at"] and datetime.strptime(pr["merged_at"],'%Y-%m-%dT%H:%M:%SZ') < release_tag_date and datetime.strptime(pr["merged_at"],'%Y-%m-%dT%H:%M:%SZ') > previous_tag_date: | ||
prs.append(pr) | ||
|
||
return prs | ||
|
||
|
||
def extract_commit_details_from_prs(prs): | ||
commit_details = [] | ||
for pr in prs: | ||
commit_message = pr["title"] | ||
commit_url = pr["html_url"] | ||
pr_number = pr["number"] | ||
branch_name = pr["head"]["ref"] | ||
issue_numbers = re.findall(r"(www-\d+|web-\d+)", branch_name) | ||
|
||
# If no issue numbers are found, add the PR details without issue numbers and URLs | ||
if not issue_numbers: | ||
commit_details.append( | ||
{ | ||
"message": commit_message, | ||
"pr_number": pr_number, | ||
"pr_url": commit_url, | ||
"issue_number": None, | ||
"issue_url": None, | ||
} | ||
) | ||
continue | ||
|
||
for issue in issue_numbers: | ||
commit_details.append( | ||
{ | ||
"message": commit_message, | ||
"pr_number": pr_number, | ||
"pr_url": commit_url, | ||
"issue_number": issue, | ||
} | ||
) | ||
|
||
return commit_details | ||
|
||
# Function to generate changelog using OpenAI | ||
def generate_changelog_with_openai(commit_details): | ||
commit_messages = [] | ||
for details in commit_details: | ||
base_message = f"{details['pr_url']} - {details['message']}" | ||
# Add the issue URL if available | ||
# if details["issue_url"]: | ||
# base_message += f" (Linear Issue: {details['issue_url']})" | ||
commit_messages.append(base_message) | ||
|
||
commit_list = "\n".join(commit_messages) | ||
prompt = """ | ||
Generate a changelog for Infisical, opensource secretops | ||
The changelog should: | ||
1. Be Informative: Using the provided list of GitHub commits, break them down into categories such as Features, Fixes & Improvements, and Technical Updates. Summarize each commit concisely, ensuring the key points are highlighted. | ||
2. Have a Professional yet Friendly tone: The tone should be balanced, not too corporate or too informal. | ||
3. Celebratory Introduction and Conclusion: Start the changelog with a celebratory note acknowledging the team's hard work and progress. End with a shoutout to the team and wishes for a pleasant weekend. | ||
4. Formatting: you cannot use Markdown formatting, and you can only use emojis for the introductory paragraph or the conclusion paragraph, nowhere else. | ||
5. Links: the syntax to create links is the following: `<http://www.example.com|This message is a link>`. | ||
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: | ||
- <https://github.com/facebook/react/pull/27304/%7C#27304>: We optimize our ci to strip comments and minify production builds. (<https://linear.app/example/issue/WEB-1234/%7CWEB-1234>)) | ||
And here's an example of the full changelog: | ||
*Features* | ||
• <https://github.com/facebook/react/pull/27304/%7C#27304>: We optimize our ci to strip comments and minify production builds. (<https://linear.app/example/issue/WEB-1234/%7CWEB-1234>) | ||
*Fixes & Improvements* | ||
• <https://github.com/facebook/react/pull/27304/%7C#27304>: We optimize our ci to strip comments and minify production builds. (<https://linear.app/example/issue/WEB-1234/%7CWEB-1234>) | ||
*Technical Updates* | ||
• <https://github.com/facebook/react/pull/27304/%7C#27304>: We optimize our ci to strip comments and minify production builds. (<https://linear.app/example/issue/WEB-1234/%7CWEB-1234>) | ||
Stay tuned for more exciting updates coming soon! | ||
And here are the commits: | ||
{} | ||
""".format( | ||
commit_list | ||
) | ||
|
||
client = OpenAI(api_key=OPENAI_API_KEY) | ||
messages = [{"role": "user", "content": prompt}] | ||
response = client.chat.completions.create(model="gpt-3.5-turbo", messages=messages) | ||
|
||
if "error" in response.choices[0].message: | ||
raise Exception("Error generating changelog with OpenAI!") | ||
|
||
return response.choices[0].message.content.strip() | ||
|
||
|
||
if __name__ == "__main__": | ||
try: | ||
# Get the latest and previous release tags | ||
latest_tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]).decode("utf-8").strip() | ||
previous_tag = find_previous_release_tag(latest_tag) | ||
|
||
latest_tag_date = get_tag_creation_date(latest_tag) | ||
previous_tag_date = get_tag_creation_date(previous_tag) | ||
|
||
prs = fetch_prs_between_tags(previous_tag_date,latest_tag_date) | ||
pr_details = extract_commit_details_from_prs(prs) | ||
|
||
# Generate changelog | ||
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) | ||
|
||
except Exception as e: | ||
print(str(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
from datetime import datetime, timedelta | ||
|
||
def rename_migrations(): | ||
migration_folder = "./backend/src/db/migrations" | ||
with open("added_files.txt", "r") as file: | ||
changed_files = file.readlines() | ||
|
||
# Find the latest file among the changed files | ||
latest_timestamp = datetime.now() # utc time | ||
for file_path in changed_files: | ||
file_path = file_path.strip() | ||
# each new file bump by 1s | ||
latest_timestamp = latest_timestamp + timedelta(seconds=1) | ||
|
||
new_filename = os.path.join(migration_folder, latest_timestamp.strftime("%Y%m%d%H%M%S") + f"_{file_path.split('_')[1]}") | ||
old_filename = os.path.join(migration_folder, file_path) | ||
os.rename(old_filename, new_filename) | ||
print(f"Renamed {old_filename} to {new_filename}") | ||
|
||
if len(changed_files) == 0: | ||
print("No new files added to migration folder") | ||
|
||
if __name__ == "__main__": | ||
rename_migrations() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Build patroni | ||
on: [workflow_dispatch] | ||
|
||
jobs: | ||
patroni-image: | ||
name: Build patroni | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: ☁️ Checkout source | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: 'zalando/patroni' | ||
- name: Save commit hashes for tag | ||
id: commit | ||
uses: pr-mpt/actions-commit-hash@v2 | ||
- name: 🔧 Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: 🐋 Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- name: Set up Depot CLI | ||
uses: depot/setup-action@v1 | ||
- name: 🏗️ Build backend and push to docker hub | ||
uses: depot/build-push-action@v1 | ||
with: | ||
project: 64mmf0n610 | ||
token: ${{ secrets.DEPOT_PROJECT_TOKEN }} | ||
push: true | ||
context: . | ||
file: Dockerfile | ||
tags: | | ||
infisical/patroni:${{ steps.commit.outputs.short }} | ||
infisical/patroni:latest | ||
platforms: linux/amd64,linux/arm64 | ||
|
||
|
Oops, something went wrong.