-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENG-1235: Push release tags automatically on rasa-sdk
#1139
Merged
AsadHasan-Rasa
merged 6 commits into
main
from
ENG-1235-push-release-tags-automatically-on-rasa-sdk
Aug 27, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e364820
ENG-1235: Create and push release tags automatically
AsadHasan-Rasa e1b7666
ENG-1235: Fixed tag-done message
AsadHasan-Rasa 028ebf6
ENG-1235: Added more info to module docstring, about release tagging
AsadHasan-Rasa 18b08a2
ENG-1235: Increased docstring info
AsadHasan-Rasa 267b0e8
ENG-1235: Updated readme/docs accordingly
AsadHasan-Rasa 5062468
ENG-1235: Address PR feedback, to not generate changelog on Dev versi…
AsadHasan-Rasa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: Tag Release Version | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- '[0-9]+.[0-9]+.x' | ||
types: [closed] | ||
|
||
env: | ||
COMMIT_EMAIL: [email protected] | ||
DEFAULT_PYTHON_VERSION: "3.10" | ||
|
||
jobs: | ||
if_merged_tag_release: | ||
name: Tag Release Version | ||
if: startsWith(github.head_ref, 'prepare-release-') && github.event.pull_request.merged == true | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout git repository 🕝 | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | ||
with: | ||
token: ${{ secrets.RELEASE_TAGGER_PAT }} | ||
|
||
- name: Set up Python ${{ env.DEFAULT_PYTHON_VERSION }} 🐍 | ||
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 | ||
with: | ||
python-version: ${{ env.DEFAULT_PYTHON_VERSION }} | ||
|
||
- name: Read Poetry Version 🔢 | ||
run: | | ||
echo "POETRY_VERSION=$(scripts/poetry-version.sh)" >> $GITHUB_ENV | ||
shell: bash | ||
|
||
- name: Install poetry 🦄 | ||
uses: Gr1N/setup-poetry@15821dc8a61bc630db542ae4baf6a7c19a994844 # v8 | ||
with: | ||
poetry-version: ${{ env.POETRY_VERSION }} | ||
|
||
- name: Load Poetry Cached Libraries ⬇ | ||
id: cache-poetry | ||
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 #v4.0.0 | ||
with: | ||
path: .venv | ||
key: ${{ runner.os }}-poetry-${{ env.POETRY_VERSION }}-${{ env.DEFAULT_PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}-${{ secrets.POETRY_CACHE_VERSION }} | ||
restore-keys: ${{ runner.os }}-poetry-${{ env.DEFAULT_PYTHON_VERSION }} | ||
|
||
- name: Clear Poetry cache | ||
if: steps.cache-poetry.outputs.cache-hit == 'true' && contains(github.event.pull_request.labels.*.name, 'tools:clear-poetry-cache-unit-tests') | ||
run: rm -r .venv | ||
|
||
- name: Create virtual environment | ||
if: steps.cache-poetry.outputs.cache-hit != 'true' || contains(github.event.pull_request.labels.*.name, 'tools:clear-poetry-cache-unit-tests') | ||
run: python -m venv create .venv | ||
|
||
- name: Set up virtual environment | ||
run: poetry config virtualenvs.in-project true | ||
|
||
- name: Install Dependencies 📦 | ||
# Poetry intermittently fails to install dependency if it is not PEP 517 compliant | ||
# This is a workaround for that issue | ||
run: | | ||
sudo apt-get -y install libpq-dev | ||
make install-full | ||
|
||
- name: Configure git | ||
run: | | ||
git config --global user.email ${{ env.COMMIT_EMAIL }} | ||
git config --global user.name "Github Actions" | ||
|
||
- name: Tag Release | ||
run: make tag-release |
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 |
---|---|---|
|
@@ -3,7 +3,12 @@ | |
- creates a new changelog section in CHANGELOG.mdx based on all collected changes | ||
- increases the version number | ||
- pushes the new branch to GitHub | ||
|
||
When run with `--tag`: | ||
- tags the current commit with the version number found in the version module | ||
- and pushes the tag to GitHub. | ||
""" | ||
|
||
import argparse | ||
import os | ||
import re | ||
|
@@ -32,12 +37,15 @@ | |
def create_argument_parser() -> argparse.ArgumentParser: | ||
"""Parse all the command line arguments for the release script.""" | ||
|
||
parser = argparse.ArgumentParser(description="prepare the next library release") | ||
parser = argparse.ArgumentParser( | ||
description="Prepare or tag the next library release" | ||
) | ||
parser.add_argument( | ||
"--next_version", | ||
type=str, | ||
help="Either next version number or 'major', 'minor', 'micro', 'alpha', 'rc'", | ||
) | ||
parser.add_argument("--tag", help="Tag the next release", action="store_true") | ||
|
||
return parser | ||
|
||
|
@@ -284,39 +292,97 @@ def print_done_message_same_branch(version: Version) -> None: | |
) | ||
|
||
|
||
def main(args: argparse.Namespace) -> None: | ||
"""Start a release preparation.""" | ||
def tag_commit(tag: Text) -> None: | ||
"""Tags a git commit.""" | ||
print(f"Applying tag '{tag}' to commit.") | ||
check_call(["git", "tag", tag, "-m", "next release"]) | ||
|
||
|
||
def push_tag(tag: Text) -> None: | ||
"""Pushes a tag to the remote.""" | ||
print(f"Pushing tag '{tag}' to origin.") | ||
check_call(["git", "push", "origin", tag, "--tags"]) | ||
|
||
|
||
def print_tag_release_done_message(version: Version) -> None: | ||
"""Print final information for the user about the tagged commit.""" | ||
print() | ||
print( | ||
f"\033[94m All done - tag for version {version} " | ||
"was added and pushed to the remote \033[0m" | ||
) | ||
|
||
|
||
def tag_release() -> None: | ||
"""Tag the current commit with the current version.""" | ||
print( | ||
"The release script will increase the version number, " | ||
"create a changelog and create a release branch. Let's go!" | ||
""" | ||
The release tag script will tag the current commit with the current version. | ||
|
||
This should be done on the applicable *.x branch after running | ||
`make release` and merging the prepared release branch. | ||
""" | ||
) | ||
|
||
branch = git_current_branch() | ||
version = Version(get_current_version()) | ||
|
||
if ( | ||
not version.is_alpha | ||
and not version.is_beta | ||
and not git_current_branch_is_main_or_release() | ||
): | ||
print( | ||
f""" | ||
You are currently on branch {branch}. | ||
You should only apply release tags to release branches (e.g. 1.x) or main. | ||
""" | ||
) | ||
sys.exit(1) | ||
ensure_clean_git() | ||
version = next_version(args) | ||
confirm_version(version) | ||
tag = str(version) | ||
tag_commit(tag) | ||
push_tag(tag) | ||
|
||
print_tag_release_done_message(version) | ||
|
||
write_version_file(version) | ||
write_version_to_pyproject(version) | ||
|
||
if not version.pre: | ||
# never update changelog on a prerelease version | ||
generate_changelog(version) | ||
def main(args: argparse.Namespace) -> None: | ||
"""Start a release preparation, or tag release.""" | ||
|
||
# alpha workflow on feature branch when a version bump is required | ||
if version.is_alpha and not git_current_branch_is_main_or_release(): | ||
create_commit(version) | ||
push_changes() | ||
if not args.tag: | ||
print( | ||
"The release script will increase the version number, " | ||
"create a changelog and create a release branch. Let's go!" | ||
) | ||
|
||
print_done_message_same_branch(version) | ||
else: | ||
base = git_current_branch() | ||
branch = create_release_branch(version) | ||
ensure_clean_git() | ||
version = next_version(args) | ||
confirm_version(version) | ||
|
||
create_commit(version) | ||
push_changes() | ||
write_version_file(version) | ||
write_version_to_pyproject(version) | ||
|
||
print_done_message(branch, base, version) | ||
if not version.pre: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to your changes but just noticed this was missing. Can you also add |
||
# never update changelog on a prerelease version | ||
generate_changelog(version) | ||
|
||
# alpha workflow on feature branch when a version bump is required | ||
if version.is_alpha and not git_current_branch_is_main_or_release(): | ||
create_commit(version) | ||
push_changes() | ||
|
||
print_done_message_same_branch(version) | ||
else: | ||
base = git_current_branch() | ||
branch = create_release_branch(version) | ||
|
||
create_commit(version) | ||
push_changes() | ||
|
||
print_done_message(branch, base, version) | ||
else: | ||
tag_release() | ||
|
||
|
||
if __name__ == "__main__": | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PAT token doesnot exist for the repo. @rasa-aadlv can you help with this please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RELEASE_TAGGER_PAT
now added to this repo's secrets (thanks @rasa-aadlv !)