-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/120 change latest tag selection from time to semantic #124
Merged
miroslavpojer
merged 9 commits into
master
from
feature/120-Change-latest-tag-selection-from-time-to-semantic
Dec 9, 2024
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0d5fafe
#119 - Add ability to define RLS from which to detect changes
miroslavpojer 940fc2b
- Black tool applied.
miroslavpojer b336cbd
- Black tool applied.
miroslavpojer 7fa21b1
- New version-tag-check version used.
miroslavpojer 669302e
- Review comments fix.
miroslavpojer c8e5252
#120 - Change latest tag selection from time to semantic
miroslavpojer c00f063
Merge branch 'master' into feature/120-Change-latest-tag-selection-fr…
miroslavpojer 181c8ca
- Remove duplicated tests after merge.
miroslavpojer 379c61a
- Fix review comments.
miroslavpojer 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 |
---|---|---|
|
@@ -21,6 +21,9 @@ on: | |
tag-name: | ||
description: 'Name of git tag to be created, and then draft release created. Syntax: "v[0-9]+.[0-9]+.[0-9]+".' | ||
required: true | ||
from-tag-name: | ||
description: 'Name of the git tag from which to detect changes from. Default value: latest tag. Syntax: "v[0-9]+.[0-9]+.[0-9]+".' | ||
required: false | ||
|
||
jobs: | ||
release-draft: | ||
|
@@ -37,20 +40,32 @@ jobs: | |
|
||
- name: Check format of received tag | ||
id: check-version-tag | ||
uses: AbsaOSS/version-tag-check@v0.2.0 | ||
uses: AbsaOSS/version-tag-check@v0.3.0 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
github-repository: ${{ github.repository }} | ||
version-tag: ${{ github.event.inputs.tag-name }} | ||
|
||
- name: Check format of received from tag | ||
if: ${{ github.event.inputs.from-tag-name }} | ||
id: check-version-from-tag | ||
uses: AbsaOSS/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
github-repository: ${{ github.repository }} | ||
version-tag: ${{ github.event.inputs.from-tag-name }} | ||
should-exist: true | ||
|
||
- name: Generate Release Notes | ||
id: generate_release_notes | ||
uses: AbsaOSS/generate-release-notes@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag-name: ${{ github.event.inputs.tag-name }} | ||
from-tag-name: ${{ github.event.inputs.from-tag-name }} | ||
chapters: '[ | ||
{"title": "No entry 🚫", "label": "duplicate"}, | ||
{"title": "No entry 🚫", "label": "invalid"}, | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,9 @@ on: | |
tag-name: | ||
description: 'Name of git tag to be created, and then draft release created. Syntax: "v[0-9]+.[0-9]+.[0-9]+".' | ||
required: true | ||
from-tag-name: | ||
description: 'Name of the git tag from which to detect changes from. Default value: latest tag. Syntax: "v[0-9]+.[0-9]+.[0-9]+".' | ||
required: false | ||
|
||
jobs: | ||
release-draft: | ||
|
@@ -23,21 +26,32 @@ jobs: | |
|
||
- name: Check format of received tag | ||
id: check-version-tag | ||
uses: AbsaOSS/version-tag-check@v0.1.0 | ||
uses: AbsaOSS/version-tag-check@v0.3.0 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
github-repository: ${{ github.repository }} | ||
branch: 'master' | ||
version-tag: ${{ github.event.inputs.tag-name }} | ||
|
||
- name: Check format of received from tag | ||
if: ${{ github.event.inputs.from-tag-name }} | ||
id: check-version-from-tag | ||
uses: AbsaOSS/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
github-repository: ${{ github.repository }} | ||
version-tag: ${{ github.event.inputs.from-tag-name }} | ||
should-exist: true | ||
|
||
- name: Generate Release Notes | ||
id: generate_release_notes | ||
uses: AbsaOSS/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag-name: ${{ github.event.inputs.tag-name }} | ||
from-tag-name: ${{ github.event.inputs.from-tag-name }} | ||
chapters: '[ | ||
{"title": "No entry 🚫", "label": "duplicate"}, | ||
{"title": "No entry 🚫", "label": "invalid"}, | ||
|
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 |
---|---|---|
|
@@ -20,20 +20,23 @@ | |
""" | ||
|
||
import logging | ||
|
||
import sys | ||
from typing import Optional | ||
import semver | ||
|
||
from github import Github | ||
from github.GitRelease import GitRelease | ||
from github.Repository import Repository | ||
|
||
from release_notes_generator.action_inputs import ActionInputs | ||
from release_notes_generator.builder import ReleaseNotesBuilder | ||
from release_notes_generator.model.custom_chapters import CustomChapters | ||
from release_notes_generator.model.record import Record | ||
from release_notes_generator.builder import ReleaseNotesBuilder | ||
from release_notes_generator.record.record_factory import RecordFactory | ||
from release_notes_generator.action_inputs import ActionInputs | ||
from release_notes_generator.utils.constants import ISSUE_STATE_ALL | ||
|
||
from release_notes_generator.utils.decorators import safe_call_decorator | ||
from release_notes_generator.utils.utils import get_change_url | ||
from release_notes_generator.utils.github_rate_limiter import GithubRateLimiter | ||
from release_notes_generator.utils.utils import get_change_url | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -72,15 +75,13 @@ def generate(self) -> Optional[str]: | |
|
||
@return: The generated release notes as a string, or None if the repository could not be found. | ||
""" | ||
# get the repository | ||
repo = self._safe_call(self.github_instance.get_repo)(ActionInputs.get_github_repository()) | ||
if repo is None: | ||
return None | ||
|
||
rls = self._safe_call(repo.get_latest_release)() | ||
if rls is None: | ||
logger.info("Latest release not found for %s. 1st release for repository!", repo.full_name) | ||
else: | ||
logger.debug("RLS created_at: %s, published_at: %s", rls.created_at, rls.published_at) | ||
# get the latest release | ||
rls = self.get_latest_release(repo) | ||
|
||
# default is repository creation date if no releases OR created_at of latest release | ||
since = rls.created_at if rls else repo.created_at | ||
|
@@ -97,12 +98,12 @@ def generate(self) -> Optional[str]: | |
|
||
# filter out closed Issues before the date | ||
issues = list( | ||
filter(lambda issue: issue.closed_at is not None and issue.closed_at > since, list(issues_all)) | ||
filter(lambda issue: issue.closed_at is not None and issue.closed_at >= since, list(issues_all)) | ||
) | ||
logger.debug("Count of issues reduced from %d to %d", len(list(issues_all)), len(issues)) | ||
|
||
# filter out merged PRs and commits before the date | ||
pulls = list(filter(lambda pull: pull.merged_at is not None and pull.merged_at > since, list(pulls_all))) | ||
pulls = list(filter(lambda pull: pull.merged_at is not None and pull.merged_at >= since, list(pulls_all))) | ||
logger.debug("Count of pulls reduced from %d to %d", len(list(pulls_all)), len(pulls)) | ||
|
||
commits = list(filter(lambda commit: commit.commit.author.date > since, list(commits_all))) | ||
|
@@ -125,3 +126,59 @@ def generate(self) -> Optional[str]: | |
) | ||
|
||
return release_notes_builder.build() | ||
|
||
def get_latest_release(self, repo: Repository) -> Optional[GitRelease]: | ||
""" | ||
Get the latest release of the repository. | ||
|
||
@param repo: The repository to get the latest release from. | ||
@return: The latest release of the repository, or None if no releases are found. | ||
""" | ||
# check if from-tag name is defined | ||
if ActionInputs.is_from_tag_name_defined(): | ||
logger.info("Getting latest release by from-tag name %s", ActionInputs.get_tag_name()) | ||
rls = self._safe_call(repo.get_release)(ActionInputs.get_from_tag_name()) | ||
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. Keep. |
||
|
||
if rls is None: | ||
logger.info("Latest release not found for received tag %s. Ending!", ActionInputs.get_from_tag_name()) | ||
sys.exit(1) | ||
|
||
else: | ||
logger.info("Getting latest release by semantic ordering (could not be the last one by time).") | ||
gh_releases: list = list(self._safe_call(repo.get_releases)()) | ||
rls: GitRelease = self.__get_latest_semantic_release(gh_releases) | ||
|
||
if rls is None: | ||
logger.info("Latest release not found for %s. 1st release for repository!", repo.full_name) | ||
|
||
if rls is not None: | ||
logger.debug( | ||
"Latest release with tag:'%s' created_at: %s, published_at: %s", | ||
rls.tag_name, | ||
rls.created_at, | ||
rls.published_at, | ||
) | ||
|
||
return rls | ||
|
||
def __get_latest_semantic_release(self, releases) -> Optional[GitRelease]: | ||
published_releases = [release for release in releases if not release.draft and not release.prerelease] | ||
latest_version: Optional[semver.Version] = None | ||
rls: Optional[GitRelease] = None | ||
|
||
for release in published_releases: | ||
try: | ||
version_str = release.tag_name.lstrip("v") | ||
current_version: Optional[semver.Version] = semver.VersionInfo.parse(version_str) | ||
except ValueError: | ||
logger.debug("Skipping invalid value of version tag: %s", release.tag_name) | ||
continue | ||
except TypeError: | ||
logger.debug("Skipping invalid type of version tag: %s", release.tag_name) | ||
continue | ||
|
||
if latest_version is None or current_version > latest_version: | ||
latest_version = current_version | ||
rls = release | ||
|
||
return rls |
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
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ PyGithub==1.59.0 | |
pylint==3.2.6 | ||
requests==2.31.0 | ||
black==24.8.0 | ||
semver==3.0.2 |
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
Oops, something went wrong.
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.
Keep the type hints.