|
| 1 | +name: Build & Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request: |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + name: build-test (python ${{ matrix.python-version }}) |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + python-version: ['3.10', '3.11', '3.12'] |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Python |
| 28 | + uses: actions/setup-python@v5 |
| 29 | + with: |
| 30 | + python-version: ${{ matrix.python-version }} |
| 31 | + cache: pip |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: | |
| 35 | + pip install 'tox<4' tox-gh-actions |
| 36 | +
|
| 37 | + - name: Run tests |
| 38 | + run: tox |
| 39 | + |
| 40 | + create-release: |
| 41 | + name: semantic-release |
| 42 | + if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' |
| 43 | + needs: build |
| 44 | + runs-on: ubuntu-latest |
| 45 | + |
| 46 | + permissions: |
| 47 | + contents: write |
| 48 | + |
| 49 | + steps: |
| 50 | + - name: Notify Slack - Release Started |
| 51 | + run: | |
| 52 | + curl -X POST "${{ secrets.SLACK_RELEASE_WEBHOOK_URL }}" \ |
| 53 | + -H 'Content-Type: application/json' \ |
| 54 | + -d '{ |
| 55 | + "sdk": "networking-python-sdk", |
| 56 | + "language": "python", |
| 57 | + "status": "started", |
| 58 | + "actor": "${{ github.actor }}" |
| 59 | + }' |
| 60 | +
|
| 61 | + - name: Checkout repository |
| 62 | + uses: actions/checkout@v4 |
| 63 | + with: |
| 64 | + fetch-depth: 0 |
| 65 | + persist-credentials: false |
| 66 | + |
| 67 | + - name: Setup Node.js |
| 68 | + uses: actions/setup-node@v4 |
| 69 | + with: |
| 70 | + node-version: 22 |
| 71 | + |
| 72 | + - name: Setup Python |
| 73 | + uses: actions/setup-python@v5 |
| 74 | + with: |
| 75 | + python-version: '3.10' |
| 76 | + |
| 77 | + - name: Install pandoc |
| 78 | + run: | |
| 79 | + sudo apt-get update |
| 80 | + sudo apt-get install -y pandoc |
| 81 | + pip install pypandoc |
| 82 | +
|
| 83 | + - name: Install publishing tools |
| 84 | + run: | |
| 85 | + pip install bump2version build twine |
| 86 | + npm ci |
| 87 | +
|
| 88 | + - name: Verify version consistency |
| 89 | + run: | |
| 90 | + # Extract versions from all files |
| 91 | + BUMPVERSION_VERSION=$(grep "current_version" .bumpversion.cfg | cut -d'=' -f2 | tr -d ' ') |
| 92 | + SETUP_VERSION=$(grep "__version__ = " setup.py | head -1 | cut -d"'" -f2) |
| 93 | + VERSION_PY=$(grep "__version__ = " ibm_cloud_networking_services/version.py | cut -d"'" -f2) |
| 94 | + README_VERSION=$(grep "# IBM Cloud Networking Services Python SDK Version" README.md | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') |
| 95 | + |
| 96 | + echo "Version in .bumpversion.cfg: $BUMPVERSION_VERSION" |
| 97 | + echo "Version in setup.py: $SETUP_VERSION" |
| 98 | + echo "Version in version.py: $VERSION_PY" |
| 99 | + echo "Version in README.md: $README_VERSION" |
| 100 | + |
| 101 | + # Check if all versions match |
| 102 | + if [ "$BUMPVERSION_VERSION" != "$SETUP_VERSION" ] || \ |
| 103 | + [ "$BUMPVERSION_VERSION" != "$VERSION_PY" ] || \ |
| 104 | + [ "$BUMPVERSION_VERSION" != "$README_VERSION" ]; then |
| 105 | + echo "❌ ERROR: Version mismatch detected!" |
| 106 | + echo "All version strings must match before release." |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + |
| 110 | + echo "✅ All version strings are consistent: $BUMPVERSION_VERSION" |
| 111 | +
|
| 112 | + - name: Run semantic-release |
| 113 | + env: |
| 114 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 115 | + run: npx semantic-release |
| 116 | + |
| 117 | + - name: Publish to PyPI |
| 118 | + if: success() |
| 119 | + env: |
| 120 | + TWINE_USERNAME: __token__ |
| 121 | + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |
| 122 | + run: | |
| 123 | + python -m build |
| 124 | + python -m twine upload dist/* |
| 125 | +
|
| 126 | + - name: Get package version |
| 127 | + if: success() |
| 128 | + id: get_version |
| 129 | + run: | |
| 130 | + VERSION=$(python -c "from ibm_cloud_networking_services.version import __version__; print(__version__)") |
| 131 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 132 | +
|
| 133 | + - name: Notify Slack - Release Completed |
| 134 | + if: success() |
| 135 | + run: | |
| 136 | + curl -X POST "${{ secrets.SLACK_PYPI_WEBHOOK_URL }}" \ |
| 137 | + -H 'Content-Type: application/json' \ |
| 138 | + -d '{ |
| 139 | + "version": "${{ steps.get_version.outputs.version }}", |
| 140 | + "package_name": "ibm-cloud-networking-services", |
| 141 | + "pypi_url": "https://pypi.org/project/ibm-cloud-networking-services/${{ steps.get_version.outputs.version }}/", |
| 142 | + "github_release": "${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ steps.get_version.outputs.version }}", |
| 143 | + "commit_sha": "${{ github.sha }}", |
| 144 | + "actor": "${{ github.actor }}" |
| 145 | + }' |
| 146 | +
|
| 147 | + - name: Notify Slack - Release Failed |
| 148 | + if: failure() |
| 149 | + run: | |
| 150 | + curl -X POST "${{ secrets.SLACK_RELEASE_WEBHOOK_URL }}" \ |
| 151 | + -H 'Content-Type: application/json' \ |
| 152 | + -d '{ |
| 153 | + "sdk": "networking-python-sdk", |
| 154 | + "language": "python", |
| 155 | + "status": "failed", |
| 156 | + "actor": "${{ github.actor }}" |
| 157 | + }' |
0 commit comments