Skip to content
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

ci: Migrate the release workflow from CircleCI to GitHub Actions #203

Merged
merged 9 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Check versions 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.8
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
- 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 "package_name=${{ env.package_name }}" >> $GITHUB_OUTPUT
echo "package_version=${{ env.package_version }}" >> $GITHUB_OUTPUT
outputs:
new_release: ${{ steps.version_check.outputs.new_release }}
package_name: ${{ steps.version_check.outputs.package_name }}
package_version: ${{ steps.version_check.outputs.package_version }}

test:
needs: check-version
if: ${{ needs.check-version.outputs.new_release == 'true' }}
uses: ./.github/workflows/check-plugin.yml
with:
plugin: ${{ needs.check-version.outputs.package_name }}

build-publish:
needs: [check-version, test]
if: ${{ 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.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: |
export plugin=${{ needs.check-version.outputs.package_name }}
make package
- name: Create GitHub Release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TAGGING_TOKEN }}
script: |
const package_name = "${{ needs.check-version.outputs.package_name }}"
const package_version = "${{ needs.check-version.outputs.package_version }}"
const response = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `${package_name}-${package_version}`,
target_commitish: 'main',
name: `${package_name}-${package_version}`,
body: `Release ${package_version}`,
draft: false,
prerelease: false,
});
return response.data;
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: ${{ needs.check-version.outputs.package_name }}/dist
password: ${{ secrets.PYPI_API_TOKEN }}
49 changes: 49 additions & 0 deletions tools/github_actions/github_actions_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import sys
import re
import requests
from pathlib import Path

VERSION_MATCHSTR = r'\s*__version__\s*=\s*"(\d+\.\d+\.\d+)"'
PACKAGE_PATHS = (
"kedro-datasets/kedro_datasets",
"kedro-telemetry/kedro_telemetry",
"kedro-airflow/kedro_airflow",
"kedro-docker/kedro_docker",
)


def get_package_version(base_path, package_path):
init_file_path = Path(base_path) / package_path / "__init__.py"
match_obj = re.search(VERSION_MATCHSTR, Path(init_file_path).read_text())
return match_obj.group(1)


def check_no_version_pypi(pypi_endpoint, package_name, package_version):
print(f"Check if {package_name} {package_version} is on pypi")
response = requests.get(pypi_endpoint, timeout=10)
if response.status_code == 404:
# Not exist on Pypi - do release
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
print(f"Starting the release of {package_name} {package_version}")
return True
else:
print(f"Skipped: {package_name} {package_version} already exists on PyPI")
return False


if __name__ == "__main__":
"""Check if a package needs to be released"""
base_path = Path()
for package_path in PACKAGE_PATHS:
package_name, _ = package_path.split("/")
package_version = get_package_version(base_path, package_path)
pypi_endpoint = f"https://pypi.org/pypi/{package_name}/{package_version}/json/"
env_file = os.getenv('GITHUB_ENV')

if check_no_version_pypi(pypi_endpoint, package_name, package_version):
with open(env_file, "a") as env_file:
env_file.write(f"new_release=true\npackage_name={package_name}\npackage_version={package_version}\n")
break
else:
with open(env_file, "a") as env_file:
env_file.write("new_release=false")