Skip to content

Commit

Permalink
[NewFeature] add ppdiffusers CD workflow (PaddlePaddle#3604)
Browse files Browse the repository at this point in the history
* 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
wj-Mcat authored Oct 31, 2022
1 parent b90ed42 commit 3e2ddd1
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 10 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/pypi.yml
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"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ FETCH_HEAD

# vscode
.vscode
./ppdiffusers/ppdiffusers/version.py
10 changes: 10 additions & 0 deletions Makefile
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

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.2.3
2 changes: 1 addition & 1 deletion pipelines/ui/webapp_question_answering.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,4 @@ def reset_results(*args):
st.write("___")


main()
main()
2 changes: 1 addition & 1 deletion pipelines/ui/webapp_semantic_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,4 @@ def reset_results(*args):
st.write("___")


main()
main()
31 changes: 31 additions & 0 deletions ppdiffusers/Makefile
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}"
1 change: 1 addition & 0 deletions ppdiffusers/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.6.0.dev1
3 changes: 2 additions & 1 deletion ppdiffusers/ppdiffusers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
is_paddlenlp_available,
is_unidecode_available,
)
from .version import VERSION

__version__ = "0.6.0"
__version__ = VERSION

from .configuration_utils import ConfigMixin
from .onnx_utils import OnnxRuntimeModel
Expand Down
17 changes: 17 additions & 0 deletions ppdiffusers/ppdiffusers/version.py
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'
15 changes: 15 additions & 0 deletions ppdiffusers/scripts/should_deploy.py
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
34 changes: 27 additions & 7 deletions ppdiffusers/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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',
Expand Down
80 changes: 80 additions & 0 deletions scripts/should_deploy.py
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")

0 comments on commit 3e2ddd1

Please sign in to comment.