forked from PaddlePaddle/PaddleNLP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NewFeature] add ppdiffusers CD workflow (PaddlePaddle#3604)
* add ppdiffusers version control * add ppdiffusers version control * enable should deploy checking * revert pipeline ui changes * ignore version file * π₯ update version to 0.6.2 * gi * bump version * upate * deploy package to testpypi * re-trigger the ci
- Loading branch information
Showing
13 changed files
with
248 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: PyPI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.8 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install -r docs/requirements.txt | ||
pip install -r ppdiffuers/requirements.txt | ||
ppdiffusers: | ||
name: Pack | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.8 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
make install-ppdiffusers | ||
- name: Should Deploy to Pypi Server | ||
id: should-deploy | ||
run: python scripts/should_deploy.py --name ppdiffusers >> $GITHUB_OUTPUT | ||
- name: Check Branch | ||
id: check-branch | ||
run: | | ||
if [[ ${{ github.ref }} =~ ^refs/heads/(develop)$ ]]; then | ||
echo ::set-output name=match::true | ||
fi # See: https://stackoverflow.com/a/58869470/1123955 | ||
- name: Is A Publish Branch | ||
if: steps.check-branch.outputs.match == 'true' and steps.should-deploy.outputs.should_deploy == 'true' | ||
env: | ||
TWINE_USERNAME: paddle-dev | ||
TWINE_PASSWORD: ${{ secrets.paddlenlp }} | ||
run: | | ||
make deploy-ppdiffusers | ||
- name: Should Deploy To Pypi Server | ||
if: steps.should-deploy.outputs.should_deploy != 'true' | ||
run: echo 'should not deploy pypi server' | ||
|
||
- name: Is Not A Publish Branch | ||
if: steps.check-branch.outputs.match != 'true' | ||
run: echo 'Not A Publish Branch' | ||
echo "To be add: pack testing" |
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 |
---|---|---|
|
@@ -123,3 +123,4 @@ FETCH_HEAD | |
|
||
# vscode | ||
.vscode | ||
./ppdiffusers/ppdiffusers/version.py |
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,10 @@ | ||
|
||
|
||
.PHONY: deploy-ppdiffusers | ||
deploy-ppdiffusers: | ||
cd ppdiffusers && make | ||
|
||
.PHONY: install-ppdiffusers | ||
install-ppdiffusers: | ||
cd ppdiffusers && make install | ||
|
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 @@ | ||
4.2.3 |
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 |
---|---|---|
|
@@ -253,4 +253,4 @@ def reset_results(*args): | |
st.write("___") | ||
|
||
|
||
main() | ||
main() |
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 |
---|---|---|
|
@@ -227,4 +227,4 @@ def reset_results(*args): | |
st.write("___") | ||
|
||
|
||
main() | ||
main() |
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,31 @@ | ||
|
||
.DEFAULT_GOAL := all | ||
|
||
.PHONY: all | ||
all: build deploy-version deploy | ||
|
||
.PHONY: build | ||
build: | ||
python3 setup.py sdist bdist_wheel | ||
|
||
.PHONY: deploy | ||
deploy: | ||
make deploy-version | ||
# twine upload --skip-existing dist/* | ||
twine upload --repository testpypi --skip-existing dist/* | ||
|
||
.PHONY: deploy-version | ||
deploy-version: | ||
echo "VERSION = '$$(cat VERSION)'" > ppdiffusers/version.py | ||
|
||
.PHONY: install | ||
install: | ||
pip install -r requirements.txt | ||
|
||
.PHONY: version | ||
version: | ||
@newVersion=$$(awk -F. '{print $$1"."$$2"."$$3+1}' < VERSION) \ | ||
&& echo $${newVersion} > VERSION \ | ||
&& git add VERSION \ | ||
&& git commit -m "π₯ update version to $${newVersion}" > /dev/null \ | ||
&& echo "Bumped version to $${newVersion}" |
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 @@ | ||
0.6.0.dev1 |
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,17 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed 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. | ||
|
||
# this file will be generated by tools | ||
# please not modify it. | ||
VERSION = '0.0.0' |
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,15 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed 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. | ||
|
||
from pip import main |
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 |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
# 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. | ||
import io | ||
import os | ||
from setuptools import find_packages, setup | ||
|
||
|
@@ -21,24 +20,45 @@ | |
REQUIRED_PACKAGES = fin.read() | ||
|
||
|
||
def read(*names, **kwargs): | ||
with io.open(os.path.join(os.path.dirname(__file__), *names), | ||
encoding=kwargs.get("encoding", "utf8")) as fp: | ||
return fp.read() | ||
def read(file: str): | ||
current_dir = os.path.dirname(__file__) | ||
path = os.path.join(current_dir, file) | ||
with open(path, 'r', encoding='utf-8') as f: | ||
content = f.read().strip() | ||
return content | ||
|
||
|
||
def read_version(): | ||
"""read version of ppdiffusers""" | ||
return read("VERSION") | ||
|
||
|
||
def read_readme(): | ||
return read("README.md") | ||
|
||
|
||
def read_requirements(): | ||
content = read('requirements.txt') | ||
packages = content.split("\n") | ||
return packages | ||
|
||
|
||
setup(name="ppdiffusers", | ||
packages=find_packages(), | ||
version="0.6.0", | ||
version=read_version(), | ||
author="PaddleNLP Team", | ||
author_email="[email protected]", | ||
description=description, | ||
long_description=read("README.md"), | ||
long_description=read_readme(), | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/PaddlePaddle/PaddleNLP/ppdiffusers", | ||
keywords=["ppdiffusers", "paddle", "paddlenlp"], | ||
install_requires=REQUIRED_PACKAGES, | ||
python_requires='>=3.6', | ||
entry_points={ | ||
"console_scripts": | ||
["ppdiffusers-cli=ppdiffusers.commands.ppdiffusers_cli:main"] | ||
}, | ||
classifiers=[ | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.6', | ||
|
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,80 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed 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. | ||
from __future__ import annotations | ||
|
||
import subprocess | ||
import sys | ||
import os | ||
import argparse | ||
|
||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
def read_version_of_remote_package(name: str) -> str: | ||
"""get version of remote package, | ||
apdapted from: https://stackoverflow.com/a/58649262/6894382 | ||
Args: | ||
name (str): the name of package | ||
Returns: | ||
str: the version of package | ||
""" | ||
latest_version = str( | ||
subprocess.run( | ||
[sys.executable, '-m', 'pip', 'install', '{}==random'.format(name)], | ||
capture_output=True, | ||
text=True)) | ||
latest_version = latest_version[latest_version.find('(from versions:') + | ||
15:] | ||
latest_version = latest_version[:latest_version.find(')')] | ||
latest_version = latest_version.replace(' ', '').split(',')[-1] | ||
return latest_version | ||
|
||
|
||
def read_version_of_local_package(version_file_path: str) -> str: | ||
"""get version of local package | ||
Args: | ||
version_file_path (str): the path of `VERSION` file | ||
Returns: | ||
str: the version of local package | ||
""" | ||
with open(version_file_path, 'r', encoding='utf-8') as f: | ||
version = f.read().strip() | ||
return version | ||
|
||
|
||
def should_ppdiffusers_deploy(): | ||
"""print the result to terminal""" | ||
local_version_file = os.path.join(PROJECT_ROOT, 'ppdiffusers/VERSION') | ||
remote_version = read_version_of_remote_package("ppdiffusers") | ||
local_version = read_version_of_local_package(local_version_file) | ||
|
||
should_deploy = str(remote_version != local_version).lower() | ||
print(f"should_deploy={should_deploy}") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--name', required=True) | ||
|
||
args = parser.parse_args() | ||
|
||
if args.name == 'ppdiffusers': | ||
should_ppdiffusers_deploy() | ||
else: | ||
raise ValueError(f"package<{args.name}> not supported") |