Skip to content

Commit

Permalink
Add CI and Automated Rlease Process (#12)
Browse files Browse the repository at this point in the history
* CI: add build test

* CI: add clear disk script and pip cache

* CI: add release CI

* CI: fix build command

* CI:add pypi release

* CI:fix permission

* CI:fix wheel_name

* CI:fixrename not found

* CI:fix wheel_name

* CI:fix build

* CI:final test

* CI:test multi-version

* CI:revert version and add release doc

* CI:change build test gh actions name
  • Loading branch information
lausannel authored Apr 15, 2024
1 parent 87eacf7 commit 75e468c
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This workflow will upload a Python Package to Release asset
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions

name: Build Test

on:
# push or pull request to main or dev branch
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Free disk space
run: |
sudo rm -rf /usr/local/cuda-* /opt/cuda
sudo rm -rf /usr/local/cuda
bash -x .github/workflows/scripts/free-disk-space.sh
- name: Cache Python packages
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install CUDA 11.7
run: |
bash -x .github/workflows/scripts/cuda-install.sh 11.7 ubuntu-20.04
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install build
- name: Build package
run: BUILD_OPS=1 python -m build
118 changes: 118 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# This workflow will upload a Python Package to Release asset
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions

name: Create Release

on:
push:
tags:
- v*

# Needed to create release and upload assets
permissions:
contents: write

jobs:
release:
# Retrieve tag and create release
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Extract branch info
shell: bash
run: |
echo "release_tag=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: "actions/github-script@v6"
env:
RELEASE_TAG: ${{ env.release_tag }}
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const script = require('.github/workflows/scripts/create-release.js')
await script(github, context, core)
wheel:
name: Build Wheel
runs-on: ${{ matrix.os }}
needs: release
permissions: write-all

strategy:
fail-fast: false
matrix:
os: ['ubuntu-20.04']
python-version: ['3.8', '3.9', '3.10', '3.11']
cuda-version: ['11.7']

steps:
- name: Checkout
uses: actions/checkout@v3

# - name: Set up Linux Env
# if: ${{ runner.os == 'Linux' }}
# run: |
# bash -x .github/workflows/scripts/env.sh

- name: Free disk space
run: |
sudo rm -rf /usr/local/cuda-* /opt/cuda
sudo rm -rf /usr/local/cuda
bash -x .github/workflows/scripts/free-disk-space.sh
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install CUDA ${{ matrix.cuda-version }}
run: |
bash -x .github/workflows/scripts/cuda-install.sh ${{ matrix.cuda-version }} ${{ matrix.os }}
- name: Build wheel
shell: bash
run: |
sudo apt update && sudo apt install rename -y && sudo apt clean
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install build
BUILD_OPS=1 python -m build --wheel
wheel_name=$(ls dist/*whl | xargs -n 1 basename)
asset_name=${wheel_name//"linux"/"manylinux1"}
echo "wheel_name=${wheel_name}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV

# only build source when the python version is 3.8
- name: Build Source
if: ${{ matrix.python-version == '3.8' }}
run: |
python -m build --sdist
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ./dist/${{ env.wheel_name }}
asset_name: ${{ env.asset_name }}
asset_content_type: application/*

- name: Rename wheel
run: |
mv dist/${{ env.wheel_name }} dist/${{ env.asset_name }}
# (Danielkinz): This last step will publish the .whl to pypi. Warning: untested
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1.8
with:
# repository-url: https://test.pypi.org/legacy/
skip-existing: true
20 changes: 20 additions & 0 deletions .github/workflows/scripts/create-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Uses Github's API to create the release and wait for result.
// We use a JS script since github CLI doesn't provide a way to wait for the release's creation and returns immediately.

module.exports = async (github, context, core) => {
try {
const response = await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: process.env.RELEASE_TAG,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: process.env.RELEASE_TAG,
});

core.setOutput('upload_url', response.data.upload_url);
} catch (error) {
core.setFailed(error.message);
}
}
23 changes: 23 additions & 0 deletions .github/workflows/scripts/cuda-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Replace '.' with '-' ex: 11.8 -> 11-8
cuda_version=$(echo $1 | tr "." "-")
# Removes '-' and '.' ex: ubuntu-20.04 -> ubuntu2004
OS=$(echo $2 | tr -d ".\-")

# Installs CUDA
wget -nv https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
rm cuda-keyring_1.1-1_all.deb
sudo apt -qq update
sudo apt -y install cuda-${cuda_version} cuda-nvcc-${cuda_version} cuda-libraries-dev-${cuda_version}
sudo apt clean

# Test nvcc
PATH=/usr/local/cuda-$1/bin:${PATH}
nvcc --version

# Log gcc, g++, c++ versions
gcc --version
g++ --version
c++ --version
48 changes: 48 additions & 0 deletions .github/workflows/scripts/free-disk-space.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


#
# The Azure provided machines typically have the following disk allocation:
# Total space: 85GB
# Allocated: 67 GB
# Free: 17 GB
# This script frees up 28 GB of disk space by deleting unneeded packages and
# large directories.
# The Flink end to end tests download and generate more than 17 GB of files,
# causing unpredictable behavior and build failures.
#
echo "=============================================================================="
echo "Freeing up disk space on CI system"
echo "=============================================================================="

echo "Listing 100 largest packages"
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 100
df -h
echo "Removing large packages"
sudo apt-get remove -y '^ghc-8.*'
sudo apt-get remove -y '^dotnet-.*'
sudo apt-get remove -y '^llvm-.*'
sudo apt-get remove -y 'php.*'
sudo apt-get remove -y azure-cli google-cloud-sdk hhvm google-chrome-stable firefox powershell mono-devel
sudo apt-get autoremove -y
sudo apt-get clean
df -h
echo "Removing large directories"
# deleting 15GB
rm -rf /usr/share/dotnet/
rm -rf /opt/hostedtoolcache/
df -h
49 changes: 49 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Package Release Guide

This document describes the process of releasing a new version of the MoE-Infinity-Rel package.

## Automated Release Process

The release mechanism is fully automated through a GitHub Actions workflow, which is defined in the `.github/workflows/publish.yml` file. This workflow triggers upon the creation and publication of a new version tag formatted as `v*` within the repository.

### Steps to Release a New Version
To release a new version, such as version 1.0.0, please adhere to the following procedure:

1. Update Version: Modify the version number in the setup.py file to reflect the new release version.
2. Commit Changes: Commit these changes with an appropriate commit message that summarizes the update, such as "Update version for 1.0.0 release".
3. Create and Push Tag: Tag the latest commit with the new version number and push the tag to the repository. Use the following commands to accomplish this:
```bash
git tag v1.0.0
git push origin v1.0.0
```

Upon the successful push of the tag, the workflow will creata a new release draft, build the package and publish it to the GitHub Package Registry and PyPI repositories.


## Manual Package Building and Publishing

For developers who prefer to manually build and publish their package to PyPI, the following steps provide a detailed guide to execute this process effectively.

1. Start by cloning the repository and navigating to the root directory of the package:
```bash
git clone https://github.com/TorchMoE/MoE-Infinity.git
cd MoE-Infinity
```
2. Install the required dependencies to build the package:
```bash
pip install -r requirements.txt
pip install build
```
3. Build the source distribution and wheel for the package using:
```bash
BUILD_OPS=1 python -m build
```
This command generates the package files in the `dist/` directory.
4. Upload the built package to the PyPI repository using `twine`:
```bash
twine upload dist/*
```
Ensure that you have the necessary credentials configured for `twine` to authenticate to PyPI.


To build the package wheel for multiple Python versions, you should execute the build process individually for each version by specifying the corresponding Python interpreter.

0 comments on commit 75e468c

Please sign in to comment.