diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml new file mode 100644 index 0000000..2464c17 --- /dev/null +++ b/.github/workflows/pypi-publish.yml @@ -0,0 +1,45 @@ +name: Publish package to PyPI +on: + push: + tags: + - '*' +jobs: + publish: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@master + - name: Set up Python 3.9 + uses: actions/setup-python@v1 + with: + python-version: 3.9 + - name: Get release version + run: | + echo "CHANGELOG_VERSION=$(cat CHANGELOG.md | grep -oP '(?<=##\s)(.*)(?=\])' | head -n 1 | sed 's/\[/v/g')" >> $GITHUB_ENV + echo "TAG_VERSION=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV + - name: Check changelog release version + if: ${{ env.TAG_VERSION != env.CHANGELOG_VERSION }} + run: | + echo "CHANGELOG_VERSION($CHANGELOG_VERSION) is different from TAG_VERSION($TAG_VERSION)" + exit 1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Get all git tags + run: git fetch --tags -f + - name: Build package + run: | + python -m build --sdist --wheel + - name: Get package size + run: echo "PKG_SIZE=$(find dist -maxdepth 1 -regex '.*gz' | xargs stat --format='%s')" >> $GITHUB_ENV + - name: Check package size + if: ${{ env.PKG_SIZE > 1e+8 }} + run: | + echo "PKG_SIZE($PKG_SIZE bytes) is greater than 100MB" + exit 1 + - name: Publish package + if: startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@master + with: + skip_existing: true + password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file