Unverified Commit 49eacf12 authored by Anupam Bhatnagar's avatar Anupam Bhatnagar Committed by GitHub
Browse files

Release automation (#888)

* [skip ci] first commit to automate release process

* empty commit

* fix syntax

* fix next_version value

* fixing more syntax

* remove uses

* fix

* fixed path in setup.py

* trying a basic example

* adding branch

* change release to name

* adding first step

* remove push trigger

* change order in ON section

* modifying manual workflow

* adding fairscale release workflow

* removing unused workflows

* replacing values with secrets

* fixing __version__ in __init__.py

* cleanup

* restoring import statement
parent 99163d4f
name: build_wheels
on:
push:
branches:
- v[0-9]+.[0-9]+.[x0-9]+
tags:
- v*
jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macOS-10.15]
steps:
- uses: actions/checkout@v2
- name: Install Python
uses: actions/setup-python@v2
- name: Build wheel
run: pip install . && pip wheel -w wheelhouse .
- uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl
# This is a basic workflow that is manually triggered
name: New Manual workflow
# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
push:
workflow_dispatch:
# Inputs the workflow accepts.
inputs:
name:
# Friendly description to be shown in the UI instead of 'name'
description: 'Person to greet'
# Default value if no value is explicitly provided
default: 'World!!'
# Input has to be provided for the workflow to run
required: true
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "greet"
greet:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Runs a single command using the runners shell
- name: Send greeting
run: echo "Hello ${{ github.event.inputs.name }}"
name: Fairscale Release
on:
workflow_dispatch:
inputs:
name:
description: 'Release Type'
default: 'patch'
required: true
jobs:
get_next_version:
runs-on: ubuntu-latest
steps:
- name: checkout-repo-content
uses: actions/checkout@v2
- name: setup-python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: get next version and tag
id: get-next-version-and-tag
run: |
output=$(python3 release_utils.py --release-type ${{ github.event.inputs.name }})
echo $output
new_version=$(echo $output | awk '{print $1}')
new_tag=$(echo $output | awk '{print $2}')
echo "new version is $new_version"
echo "new tag is $new_tag"
echo ::set-output name=version::$new_version
echo ::set-output name=tag::$new_tag
outputs:
new_version: ${{ steps.get-next-version-and-tag.outputs.version }}
new_tag: ${{ steps.get-next-version-and-tag.outputs.tag }}
# - update the version file
# - commit it to main
# - build and upload the pypi package
# - create release on github
pypi_package_build_and_release:
runs-on: ubuntu-latest
needs: get_next_version
steps:
- name: checkout-repo-content
uses: actions/checkout@v2
- name: setup-python
uses: actions/setup-python@v2
with:
python-version: 3.9
# update the version number in version.py
- name: update version
id: update-version
run : |
echo "current folder = $PWD"
echo "current branch = $(git branch --show-current)"
output=$(python3 release_utils.py --release-type ${{ github.event.inputs.name }} --update-version)
# add and commit the updated version.py to main
- name: add and commit to main
uses: EndBug/add-and-commit@v7.5.0
with:
author_name: ${{ secrets.AUTHOR_NAME }}
author_email: ${{ secrets.AUTHOR_EMAIL }}
branch: main
default_author: github_actor
message: '${{ needs.get_next_version.outputs.new_version }} release'
pathspec_error_handling: exitAtEnd
# Arguments for the git pull command. Use NO-PULL to avoid the action pulling at all.
# Default: '--no-rebase'
pull: 'NO-PULL'
tag: '${{ needs.get_next_version.outputs.new_tag }}'
# build the PyPI package and upload it
- name: install dependencies, build and upload
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python3 -m pip install --upgrade pip
pip install setuptools wheel twine
python3 setup.py sdist
python3 -m twine upload --repository pypi dist/*
# create the release on github
- name: create release on github
uses: ncipollo/release-action@v1
with:
tag: '${{ needs.get_next_version.outputs.new_tag }}'
......@@ -28,10 +28,6 @@ project = "FairScale"
copyright = "2020-2021, Facebook/Meta AI Research"
author = "Facebook/Meta AI Research"
# The full version, including alpha/beta/rc tags
release = "0.4.3"
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
......
......@@ -3,10 +3,6 @@
# This source code is licensed under the BSD license found in the
# LICENSE file in the root directory of this source tree.
# Please update the doc version in docs/source/conf.py as well.
__version_tuple__ = (0, 4, 3)
__version__ = ".".join([str(x) for x in __version_tuple__])
################################################################################
# Import most common subpackages
################################################################################
......@@ -14,5 +10,7 @@ __version__ = ".".join([str(x) for x in __version_tuple__])
from typing import List
from . import nn
from .version import __version_tuple__
__version__ = ".".join([str(x) for x in __version_tuple__])
__all__: List[str] = []
__version_tuple__ = (0, 4, 3)
import argparse
import re
from typing import Tuple
from setup import find_version
def get_next_version(release_type) -> Tuple[Tuple[int, int, int], str, str]:
current_ver = find_version("fairscale/version.py")
version_list = [int(x) for x in current_ver.strip("'").split(".")]
major, minor, patch = version_list[0], version_list[1], version_list[2]
if release_type == "patch":
patch += 1
elif release_type == "minor":
minor += 1
patch = 0
elif release_type == "major":
major += 1
minor = patch = 0
else:
raise ValueError("Incorrect release type specified. Acceptable types are major, minor and patch.")
new_version_tuple = (major, minor, patch)
new_version_str = ".".join([str(x) for x in new_version_tuple])
new_tag_str = "v" + new_version_str
return new_version_tuple, new_version_str, new_tag_str
def update_version(new_version_tuple) -> None:
"""
given the current version, update the version to the
next version depending on the type of release.
"""
with open("fairscale/version.py", "r") as reader:
current_version_data = reader.read()
# for line in current_version_data:
version_match = re.search(r"^__version_tuple__ ", current_version_data)
if version_match:
new_version_data = "__version_tuple__ = %s\n" % str(new_version_tuple)
current_version_data = current_version_data.replace(version_match.string, new_version_data)
with open("fairscale/version.py", "w") as writer:
writer.write(current_version_data)
else:
raise RuntimeError("__version_tuple__ not found in version.py")
def main(args):
if args.release_type in ["major", "minor", "patch"]:
new_version_tuple, new_version, new_tag = get_next_version(args.release_type)
else:
raise ValueError("Incorrect release type specified")
if args.update_version:
update_version(new_version_tuple)
print(new_version, new_tag)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Versioning utils")
parser.add_argument("--release-type", type=str, required=True, help="type of release = major/minor/patch")
parser.add_argument(
"--update-version", action="store_true", required=False, help="updates the version in fairscale/version.py"
)
args = parser.parse_args()
main(args)
......@@ -20,7 +20,7 @@ def fetch_requirements():
# https://packaging.python.org/guides/single-sourcing-package-version/
def find_version(version_file_path):
def find_version(version_file_path) -> str:
with open(version_file_path) as version_file:
version_match = re.search(r"^__version_tuple__ = (.*)", version_file.read(), re.M)
if version_match:
......@@ -57,7 +57,7 @@ if __name__ == "__main__":
setuptools.setup(
name="fairscale",
description="FairScale: A PyTorch library for large-scale and high-performance training.",
version=find_version("fairscale/__init__.py"),
version=find_version("fairscale/version.py"),
setup_requires=["ninja"], # ninja is required to build extensions
install_requires=fetch_requirements(),
include_package_data=True,
......@@ -78,7 +78,3 @@ if __name__ == "__main__":
"Operating System :: OS Independent",
],
)
# Bump this number if you want to force a CI cache invalidation on the pip venv.
# CI cache version: 8
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment