-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the release process to GitHub Actions (#3491)
* add github actions release scripts Signed-off-by: Sajid Alam <sajid_alam@mckinsey.com> * remove circleci release code Signed-off-by: Sajid Alam <sajid_alam@mckinsey.com> * lint Signed-off-by: Sajid Alam <sajid_alam@mckinsey.com> * Update github_actions_release.py Signed-off-by: Sajid Alam <sajid_alam@mckinsey.com> * Update check-release.yml Signed-off-by: Sajid Alam <sajid_alam@mckinsey.com> --------- Signed-off-by: Sajid Alam <sajid_alam@mckinsey.com>
- Loading branch information
1 parent
eb807c1
commit b499da0
Showing
8 changed files
with
159 additions
and
148 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,76 @@ | ||
name: Check Kedro version and build-publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
check-version: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.11' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install requests | ||
- name: Check version | ||
run: python tools/github_actions/github_actions_release.py | ||
- name: Set outputs | ||
id: version_check | ||
run: | | ||
echo "new_release=${{ env.NEW_RELEASE }}" >> $GITHUB_OUTPUT | ||
echo "kedro_version=${{ env.KEDRO_VERSION }}" >> $GITHUB_OUTPUT | ||
outputs: | ||
new_release: ${{ steps.version_check.outputs.new_release }} | ||
kedro_version: ${{ steps.version_check.outputs.kedro_version }} | ||
|
||
test-kedro: | ||
needs: check-version | ||
if: ${{ needs.check-version.outputs.new_release == 'true' }} | ||
uses: ./.github/workflows/all-checks.yml | ||
|
||
build-publish: | ||
needs: [check-version, test-kedro] | ||
if: | | ||
always() && | ||
!contains(needs.*.result, 'failure') && | ||
!contains(needs.*.result, 'cancelled') && | ||
needs.check-version.outputs.new_release == 'true' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.11' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build | ||
- name: Build package | ||
run: make package | ||
- name: Extract release notes from RELEASE.md | ||
id: extract | ||
run: | | ||
python tools/github_actions/extract_release_notes.py \ | ||
"RELEASE.md" \ | ||
"Release ${{needs.check-version.outputs.kedro_version}}" | ||
- name: Create GitHub Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: ${{needs.check-version.outputs.kedro_version}} | ||
name: ${{needs.check-version.outputs.kedro_version}} | ||
body_path: release_body.txt | ||
draft: false | ||
prerelease: false | ||
token: ${{ secrets.GH_TAGGING_TOKEN }} | ||
- name: Publish distribution to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
packages-dir: dist | ||
password: ${{ secrets.KEDRO_PYPI_TOKEN }} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
import sys | ||
|
||
ARGUMENT_COUNT = 3 | ||
|
||
def extract_section(filename, heading): | ||
with open(filename) as file: | ||
lines = file.readlines() | ||
|
||
start_line, end_line = None, None | ||
|
||
for i, line in enumerate(lines): | ||
if line.startswith('# '): | ||
current_heading = line.strip('#').replace(':', '').strip() | ||
if current_heading == heading: | ||
start_line = i | ||
elif start_line is not None: | ||
end_line = i | ||
break | ||
|
||
if start_line is not None: | ||
if end_line is None: | ||
end_line = len(lines) | ||
section_lines = lines[start_line + 1:end_line] | ||
section = ''.join(section_lines).strip() | ||
return section | ||
else: | ||
return None | ||
|
||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != ARGUMENT_COUNT: | ||
raise Exception("Usage: python extract_release_notes.py <filename> <heading>") | ||
|
||
filename = sys.argv[1] | ||
heading = sys.argv[2] | ||
section = extract_section(filename, heading) | ||
if not section: | ||
raise Exception(f"Section not found under the {heading} heading") | ||
with open("release_body.txt", "w") as text_file: | ||
text_file.write(section) |
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,43 @@ | ||
import os | ||
import re | ||
import sys | ||
from pathlib import Path | ||
|
||
import requests | ||
|
||
VERSION_MATCHSTR = r'\s*__version__\s*=\s*"(\d+\.\d+\.\d+)"' | ||
INIT_FILE_PATH = "kedro/__init__.py" | ||
HTTP_STATUS_NOT_FOUND = 404 | ||
|
||
def get_package_version(): | ||
init_file_path = Path(INIT_FILE_PATH) | ||
match_obj = re.search(VERSION_MATCHSTR, init_file_path.read_text()) | ||
if match_obj: | ||
return match_obj.group(1) | ||
|
||
|
||
def check_no_version_pypi(kedro_version): | ||
pypi_endpoint = f"https://pypi.org/pypi/kedro/{kedro_version}/json/" | ||
print(f"Check if Kedro {kedro_version} is on PyPI") | ||
response = requests.get(pypi_endpoint, timeout=10) | ||
if response.status_code == HTTP_STATUS_NOT_FOUND: | ||
print(f"Starting the release of Kedro {kedro_version}") | ||
return True | ||
else: | ||
print(f"Skipped: Kedro {kedro_version} already exists on PyPI") | ||
return False | ||
|
||
|
||
if __name__ == "__main__": | ||
kedro_version = get_package_version() | ||
new_release = check_no_version_pypi(kedro_version) | ||
|
||
env_file = os.getenv('GITHUB_ENV') | ||
if env_file is not None: | ||
with open(env_file, "a") as file: | ||
file.write(f"NEW_RELEASE={'true' if new_release else 'false'}\n") | ||
if new_release: | ||
file.write(f"KEDRO_VERSION={kedro_version}\n") | ||
else: | ||
print("Error: GITHUB_ENV environment variable is not set.") | ||
sys.exit() |