fix: http request error #22
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
name: Publish Python Package | |
on: | |
push: | |
branches: [ main, develop ] | |
pull_request: | |
types: | |
- opened | |
env: | |
PACKAGE_NAME: crawlab-sdk | |
jobs: | |
build: | |
name: Build package | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.build.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.12' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install poetry | |
poetry install --with dev | |
poetry run pip install pytest | |
- name: Build package | |
id: build | |
run: | | |
poetry build | |
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: dist/ | |
test: | |
name: Test package | |
needs: build | |
runs-on: ubuntu-latest | |
services: | |
mongo: | |
image: mongo:5 | |
options: >- | |
--health-cmd "mongosh --eval 'db.adminCommand(\"ping\")' || exit 1" | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
master: | |
image: crawlabteam/crawlab:latest | |
env: | |
CRAWLAB_NODE_MASTER: Y | |
CRAWLAB_MONGO_HOST: mongo | |
CRAWLAB_MONGO_PORT: 27017 | |
ports: | |
- 8080:8080 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install poetry | |
poetry install --with dev | |
poetry run pip install pytest | |
- name: Run tests | |
run: | | |
poetry run pytest tests/ | |
check_version: | |
name: Check version | |
needs: [build, test] | |
runs-on: ubuntu-latest | |
outputs: | |
is_new_version: ${{ steps.check.outputs.is_new_version }} | |
steps: | |
- name: Check package version | |
id: check | |
run: | | |
version="${{ needs.build.outputs.version }}" | |
status_code=$(curl -o /dev/null -s -w "%{http_code}" https://pypi.org/project/${{ env.PACKAGE_NAME }}/${version}/) | |
echo "status_code=${status_code}" | |
if [ "$status_code" = "200" ]; then | |
is_new_version=false | |
else | |
is_new_version=true | |
fi | |
echo "is_new_version=${is_new_version}" >> $GITHUB_OUTPUT | |
publish: | |
name: Publish to PyPI | |
needs: [build, check_version] | |
runs-on: ubuntu-latest | |
environment: pypi | |
permissions: | |
id-token: write | |
if: needs.check_version.outputs.is_new_version == 'true' | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist | |
path: dist/ | |
- name: Publish package | |
uses: pypa/gh-action-pypi-publish@release/v1 |