Skip to content

Commit

Permalink
[CI] Support release-notes generator to skip cloning git (mlrun#2963)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tankilevitch authored Jan 21, 2023
1 parent 71692fc commit 1019e0e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/automatic-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,29 @@ jobs:
needs: create-releases
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r automation/requirements.txt -r dev-requirements.txt && pip install -e .
- name: Generate release notes
id: release-notes
run: |
- echo "body=$(make release-notes MLRUN_OLD_VERSION=v${{ github.event.inputs.previous_version }} MLRUN_NEW_VERSION=v${{ github.event.inputs.version }} MLRUN_RELEASE_BRANCH=${{ github.ref_name }} MLRUN_RAISE_ON_ERROR=false MLRUN_RELEASE_NOTES_OUTPUT_PATH=release_notes.md || cat release_notes.md)" >> $GITHUB_OUTPUT
make release-notes MLRUN_OLD_VERSION=v${{ github.event.inputs.previous_version }} MLRUN_VERSION=v${{ github.event.inputs.version }} MLRUN_RELEASE_BRANCH=${{ github.ref_name }} MLRUN_RAISE_ON_ERROR=false MLRUN_RELEASE_NOTES_OUTPUT_FILE=release_notes.md MLRUN_SKIP_CLONE=true
- name: resolve release notes
id: resolve-release-notes
run: |
echo "body<<EOF" >> $GITHUB_OUTPUT
cat release_notes.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- uses: ncipollo/release-action@v1
with:
tag: v${{ github.event.inputs.version }}
commit: ${{ github.ref_name }}
token: ${{ secrets.RELEASE_GITHUB_ACCESS_TOKEN }}
allowUpdates: true
prerelease: ${{ github.event.inputs.pre_release }}
body: ${{ steps.release-notes.outputs.body }}
body: ${{ steps.resolve-release-notes.outputs.body }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
- name: Generate release notes
id: release-notes
run: |
- echo "body=$(make release-notes MLRUN_OLD_VERSION=v${{ github.event.inputs.previous_version }} MLRUN_NEW_VERSION=v${{ github.event.inputs.version }} MLRUN_RELEASE_BRANCH=${{ github.ref_name }} MLRUN_RAISE_ON_ERROR=false MLRUN_RELEASE_NOTES_OUTPUT_PATH=release_notes.md || cat release_notes.md)" >> $GITHUB_OUTPUT
- echo "body=$(make release-notes MLRUN_OLD_VERSION=v${{ github.event.inputs.previous_version }} MLRUN_NEW_VERSION=v${{ github.event.inputs.version }} MLRUN_RELEASE_BRANCH=${{ github.ref_name }} MLRUN_RAISE_ON_ERROR=false MLRUN_RELEASE_NOTES_OUTPUT_FILE=release_notes.md || cat release_notes.md)" >> $GITHUB_OUTPUT
- uses: ncipollo/release-action@v1
with:
tag: v${{ github.event.inputs.version }}
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ MLRUN_PUSH_DOCKER_CACHE_IMAGE ?=
MLRUN_GIT_ORG ?= mlrun
MLRUN_RELEASE_BRANCH ?= master
MLRUN_RAISE_ON_ERROR ?= true
MLRUN_SKIP_CLONE ?= false
MLRUN_RELEASE_NOTES_OUTPUT_FILE ?=
MLRUN_SYSTEM_TESTS_CLEAN_RESOURCES ?= true
MLRUN_CUDA_VERSION = 11.7.0
Expand Down Expand Up @@ -661,7 +662,7 @@ endif
ifndef MLRUN_RELEASE_BRANCH
$(error MLRUN_RELEASE_BRANCH is undefined)
endif
python ./automation/release_notes/generate.py run $(MLRUN_VERSION) $(MLRUN_OLD_VERSION) $(MLRUN_RELEASE_BRANCH) $(MLRUN_RAISE_ON_ERROR) $(MLRUN_RELEASE_NOTES_OUTPUT_FILE)
python ./automation/release_notes/generate.py run $(MLRUN_VERSION) $(MLRUN_OLD_VERSION) $(MLRUN_RELEASE_BRANCH) $(MLRUN_RAISE_ON_ERROR) $(MLRUN_RELEASE_NOTES_OUTPUT_FILE) $(MLRUN_SKIP_CLONE)


.PHONY: pull-cache
Expand Down
48 changes: 30 additions & 18 deletions automation/release_notes/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ def __init__(
release_branch: str,
raise_on_failed_parsing: bool = True,
tmp_file_path: str = None,
skip_clone: bool = False,
):
self._logger = logger
self._release = release
self._previous_release = previous_release
self._release_branch = release_branch
self._raise_on_failed_parsing = raise_on_failed_parsing
self.tmp_file_path = tmp_file_path
self._tmp_file_path = tmp_file_path
self._skip_clone = skip_clone
# adding a map with the common contributors to prevent going to github API on every commit (better performance,
# and prevent rate limiting)
self._git_to_github_usernames_map = {
Expand Down Expand Up @@ -86,17 +88,24 @@ def run(self):
with tempfile.TemporaryDirectory(
suffix="mlrun-release-notes-clone"
) as repo_dir:
self._logger.info("Cloning repo", repo_dir=repo_dir)
self._run_command(
"git",
args=[
"clone",
"--branch",
self._release_branch,
"[email protected]:mlrun/mlrun.git",
repo_dir,
],
)
current_working_dir = repo_dir
if self._skip_clone:
current_working_dir = None
self._logger.info(
"Skipping cloning repo, assuming already cloned, using current working dir"
)
else:
self._logger.info("Cloning repo", repo_dir=current_working_dir)
self._run_command(
"git",
args=[
"clone",
"--branch",
self._release_branch,
"[email protected]:mlrun/mlrun.git",
current_working_dir,
],
)

commits_for_highlights = self._run_command(
"git",
Expand All @@ -105,7 +114,7 @@ def run(self):
'--pretty=format:"%h {%an} %s"',
f"{self._previous_release}..{self._release}",
],
cwd=repo_dir,
cwd=current_working_dir,
)

commits_for_pull_requests = self._run_command(
Expand All @@ -115,7 +124,7 @@ def run(self):
'--pretty=format:"%h %s"',
f"{self._previous_release}..{self._release}",
],
cwd=repo_dir,
cwd=current_working_dir,
)

self._generate_release_notes_from_commits(
Expand Down Expand Up @@ -168,9 +177,9 @@ def _generate_release_notes_from_commits(

def output_release_notes(self, release_notes: str):
print(release_notes)
if self.tmp_file_path:
logger.info("Writing release notes to file", path=self.tmp_file_path)
with open(self.tmp_file_path, "w") as f:
if self._tmp_file_path:
logger.info("Writing release notes to file", path=self._tmp_file_path)
with open(self._tmp_file_path, "w") as f:
f.write(release_notes)

def _generate_highlight_notes_from_commits(self, commits: str):
Expand Down Expand Up @@ -263,19 +272,22 @@ def main():
@click.argument("release-branch", type=str, required=False, default="master")
@click.argument("raise-on-failed-parsing", type=bool, required=False, default=True)
@click.argument("tmp-file-path", type=str, required=False, default=None)
@click.argument("skip-clone", type=bool, required=False, default=True)
def run(
release: str,
previous_release: str,
release_branch: str,
raise_on_failed_parsing: bool,
tmp_file_path: str = None,
tmp_file_path: str,
skip_clone: bool,
):
release_notes_generator = ReleaseNotesGenerator(
release,
previous_release,
release_branch,
raise_on_failed_parsing,
tmp_file_path,
skip_clone,
)
try:
release_notes_generator.run()
Expand Down

0 comments on commit 1019e0e

Please sign in to comment.