-
Notifications
You must be signed in to change notification settings - Fork 69
130 lines (124 loc) · 4.53 KB
/
publish_release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Upload PyPI And Release
on:
push:
tags:
- "v*"
workflow_dispatch:
env:
POETRY_VERSION: "1.8.3"
PYTHON_VERSION: "3.10.9"
jobs:
build-n-publish:
name: Build and publish to PyPI
if: github.repository == 'LazyAGI/LazyLLM'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Set up python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
- name: Extract tag from ref
id: extract_tag
run: echo "TAG=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Update version in pyproject.toml
run: |
sed -i "s/^version = \".*\"/version = \"$TAG\"/" pyproject.toml
echo $TAG
env:
TAG: ${{ env.TAG }}
- name: Install deps
shell: bash
run: pip install -e .
- name: Test import
working-directory: /tmp
shell: bash
run: python -c "import lazyllm"
- name: Copy files
shell: bash
run: cp LazyLLM-Env/poetry.lock . && cp pyproject.toml lazyllm/
- name: Build doc
run: |
set -ex
export PYTHONPATH=$PWD:$PYTHONPATH
pip install -r requirements.txt
pip install -r docs/requirements.txt
python docs/add_docstrings.py
- name: Clean cache
shell: bash
run: |
pip cache purge
pip freeze | xargs pip uninstall -y
- name: Check PyPI for existing version
id: pypi_check
run: |
VERSION=$(poetry version -s)
PACKAGE_NAME=$(poetry version | awk '{print $1}')
RESPONSE=$(curl -s https://pypi.org/pypi/$PACKAGE_NAME/json)
if echo "$RESPONSE" | jq -e ".releases | has(\"$VERSION\")"; then
echo "Version $VERSION already exists on PyPI. Skipping publish."
echo "pypi_version_exists=true" >> $GITHUB_ENV
else
echo "Version $VERSION does not exist on PyPI. Proceeding with publish."
echo "pypi_version_exists=false" >> $GITHUB_ENV
fi
- name: Build and publish to pypi
if: env.pypi_version_exists == 'false'
uses: JRubics/poetry-publish@v1.17
with:
pypi_token: ${{ secrets.LazyLLM_INDEX_PYPI_TOKEN }}
ignore_dev_requirements: "yes"
- name: Skip publish
if: env.pypi_version_exists == 'true'
shell: bash
run: echo "Skip publish"
- name: Check if GitHub Release exists
id: release_check
run: |
RELEASE_TAG=${GITHUB_REF#refs/tags/}
RELEASES=$(curl -H "Authorization: token ${{ secrets.PERSONAL_GITHUB_TOKEN }}" -s https://api.github.com/repos/${GITHUB_REPOSITORY}/releases)
if echo "$RELEASES" | jq -e ".[] | select(.tag_name == \"$RELEASE_TAG\")" > /dev/null; then
echo "Release $RELEASE_TAG already exists. Skipping release creation."
echo "release_exists=true" >> $GITHUB_ENV
UPLOAD_URL=$(echo "$RELEASES" | jq -r ".[] | select(.tag_name == \"$RELEASE_TAG\") | .upload_url")
echo "upload_url=$UPLOAD_URL" >> $GITHUB_ENV
else
echo "Release $RELEASE_TAG does not exist. Proceeding with release creation."
echo "release_exists=false" >> $GITHUB_ENV
fi
- name: Create GitHub Release
if: env.release_exists == 'false'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
- name: Set upload_url for new release
if: env.release_exists == 'false'
run: echo "upload_url=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_ENV
- name: Get Asset name
run: |
export PKG=$(ls dist/ | grep tar)
set -- $PKG
echo "name=$1" >> $GITHUB_ENV
- name: Upload Release Asset (sdist) to GitHub
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
with:
upload_url: ${{ env.upload_url }}
asset_path: dist/${{ env.name }}
asset_name: ${{ env.name }}
asset_content_type: application/zip