mirror of
https://github.com/facebookresearch/fairseq.git
synced 2024-10-03 20:28:26 +03:00
Auto release (#4455)
Summary: # Before submitting - [ ] Was this discussed/approved via a Github issue? (no need for typos, doc improvements) - [ ] Did you read the [contributor guideline](https://github.com/pytorch/fairseq/blob/main/CONTRIBUTING.md)? - [ ] Did you make sure to update the docs? - [ ] Did you write any new necessary tests? ## What does this PR do? Automates release process and allows it to be triggered directly. Heavily inspired by fairscale's release setup. Few improvements in followup PR. ## PR review Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in Github issues there's a high chance it will not be merged. ## Did you have fun? Make sure you had fun coding � Pull Request resolved: https://github.com/facebookresearch/fairseq/pull/4455 Reviewed By: cbalioglu Differential Revision: D36993777 Pulled By: dianaml0 fbshipit-source-id: bfa9663c3a7d20dd7ebf690e182d7f8102328c08
This commit is contained in:
parent
f97cdf76d9
commit
97b2d8153b
49
.github/workflows/build_wheels.yml
vendored
49
.github/workflows/build_wheels.yml
vendored
@ -1,49 +0,0 @@
|
||||
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-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.8'
|
||||
|
||||
- name: Upgrade pip
|
||||
run: |
|
||||
python3 -m pip install --upgrade pip
|
||||
|
||||
- name: Install cibuildwheel
|
||||
run: |
|
||||
python3 -m pip install cibuildwheel
|
||||
|
||||
- name: Build wheels for CPython
|
||||
run: |
|
||||
python3 -m cibuildwheel --output-dir dist
|
||||
env:
|
||||
CIBW_BUILD: "cp36-*64 cp37-*64 cp38-*64"
|
||||
CIBW_MANYLINUX_X86_64_IMAGE: manylinux1
|
||||
CIBW_BEFORE_BUILD: git submodule update --init --recursive && pip install .
|
||||
# Install system library
|
||||
CIBW_BEFORE_BUILD_LINUX: yum install -y libffi-devel || apt-get install -y libffi-devel || apk add --update --no-cache libffi-devel || true
|
||||
CIBW_ENVIRONMENT: "PIP_ONLY_BINARY=numpy"
|
||||
CIBW_SKIP: "*musllinux*"
|
||||
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: wheels
|
||||
path: ./dist/*.whl
|
119
.github/workflows/release.yml
vendored
Normal file
119
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
name: Fairseq 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.8
|
||||
|
||||
- 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 }}
|
||||
|
||||
build_wheels:
|
||||
name: Build wheels on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
needs: get_next_version
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.8'
|
||||
|
||||
# update the version number in version.txt
|
||||
- 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)
|
||||
|
||||
- name: Upgrade pip
|
||||
run: |
|
||||
python3 -m pip install --upgrade pip
|
||||
|
||||
- name: Create Source Distribution
|
||||
run: |
|
||||
pip install setuptools wheel twine
|
||||
python3 setup.py sdist
|
||||
|
||||
- name: Install cibuildwheel
|
||||
run: |
|
||||
python3 -m pip install cibuildwheel
|
||||
|
||||
- name: Build wheels for CPython
|
||||
run: |
|
||||
python3 -m cibuildwheel --output-dir dist
|
||||
env:
|
||||
CIBW_BUILD: "cp36-*64 cp37-*64 cp38-*64"
|
||||
CIBW_MANYLINUX_X86_64_IMAGE: manylinux1
|
||||
CIBW_BEFORE_BUILD: git submodule update --init --recursive && pip install .
|
||||
# Install system library
|
||||
CIBW_BEFORE_BUILD_LINUX: yum install -y libffi-devel || apt-get install -y libffi-devel || apk add --update --no-cache libffi-devel || true
|
||||
CIBW_ENVIRONMENT: "PIP_ONLY_BINARY=numpy"
|
||||
CIBW_SKIP: "*musllinux*"
|
||||
|
||||
# build the PyPI package and upload it
|
||||
- name: upload
|
||||
env:
|
||||
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
|
||||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
||||
run: |
|
||||
python3 -m twine upload --repository pypi dist/*
|
||||
|
||||
# add and commit the updated version.py to main
|
||||
- name: add and commit
|
||||
if: ${{ matrix.os=='ubuntu-latest' }}
|
||||
uses: EndBug/add-and-commit@v9
|
||||
with:
|
||||
author_name: ${{ secrets.AUTHOR_NAME }}
|
||||
author_email: ${{ secrets.AUTHOR_EMAIL }}
|
||||
|
||||
# TODO: change this to main once shipit is disabled.
|
||||
new_branch: ${{ needs.get_next_version.outputs.new_version }}
|
||||
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.
|
||||
# pull: 'NO-PULL'
|
||||
tag: '${{ needs.get_next_version.outputs.new_tag }}'
|
||||
|
||||
# create the release on github
|
||||
- name: create release on github
|
||||
if: ${{ matrix.os=='ubuntu-latest' }}
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
tag: '${{ needs.get_next_version.outputs.new_tag }}'
|
72
release_utils.py
Normal file
72
release_utils.py
Normal file
@ -0,0 +1,72 @@
|
||||
import argparse
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
def get_next_version(release_type) -> Tuple[Tuple[int, int, int], str, str]:
|
||||
current_ver = find_version("fairseq/version.txt")
|
||||
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 find_version(version_file_path) -> str:
|
||||
with open(version_file_path) as f:
|
||||
version = f.read().strip()
|
||||
return version
|
||||
|
||||
|
||||
def update_version(new_version_str) -> None:
|
||||
"""
|
||||
given the current version, update the version to the
|
||||
next version depending on the type of release.
|
||||
"""
|
||||
|
||||
with open("fairseq/version.txt", "w") as writer:
|
||||
writer.write(new_version_str)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
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 fairseq/version.txt",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
main(args)
|
Loading…
Reference in New Issue
Block a user