Merge pull request #15 from superstreamlabs/github-actions #6
This file contains hidden or 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: Release Pipeline | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - latest | |
| jobs: | |
| beta-release: | |
| name: Beta Release | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/master' | |
| outputs: | |
| version: ${{ steps.get_version.outputs.version }} | |
| status: ${{ job.status }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| pip install --quiet build twine toml | |
| - name: Modify package name for beta | |
| run: | | |
| sed -i -E 's/^(name *= *")superstream-clients(")/\1superstream-clients-beta\2/' pyproject.toml | |
| - name: Build package | |
| run: python -m build | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | |
| TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | |
| run: | | |
| twine upload dist/* | |
| - name: Get version | |
| if: always() | |
| id: get_version | |
| run: | | |
| VERSION=$(python3 -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| prod-release: | |
| name: Production Release | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/latest' | |
| outputs: | |
| version: ${{ steps.get_version.outputs.version }} | |
| status: ${{ job.status }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| pip install --quiet build twine toml | |
| - name: Build package | |
| run: python -m build | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | |
| TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | |
| run: | | |
| twine upload dist/* | |
| - name: Get version from pyproject.toml | |
| if: always() | |
| id: get_version | |
| run: | | |
| VERSION=$(python3 -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Version: $VERSION" | |
| - name: Create Git tag | |
| run: | | |
| git config user.email "[email protected]" | |
| git config user.name "GitHub Actions" | |
| git tag -a ${{ steps.get_version.outputs.version }} -m "${{ steps.get_version.outputs.version }}" | |
| git push origin ${{ steps.get_version.outputs.version }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.get_version.outputs.version }} | |
| files: dist/superstream_clients-${{ steps.get_version.outputs.version }}.tar.gz | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| notify: | |
| name: Send Notifications | |
| runs-on: ubuntu-latest | |
| needs: [beta-release, prod-release] | |
| if: always() | |
| steps: | |
| - name: Determine release type and status | |
| id: release_info | |
| run: | | |
| if [ "${{ github.ref }}" == "refs/heads/master" ]; then | |
| echo "type=Beta" >> $GITHUB_OUTPUT | |
| echo "version=${{ needs.beta-release.outputs.version }}" >> $GITHUB_OUTPUT | |
| echo "result=${{ needs.beta-release.result }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "type=Production" >> $GITHUB_OUTPUT | |
| echo "version=${{ needs.prod-release.outputs.version }}" >> $GITHUB_OUTPUT | |
| echo "result=${{ needs.prod-release.result }}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Send Slack notification on success | |
| if: steps.release_info.outputs.result == 'success' | |
| uses: slackapi/slack-github-action@v1 | |
| with: | |
| payload: | | |
| { | |
| "text": "superstream-python-clients v${{ steps.release_info.outputs.version }} ${{ steps.release_info.outputs.type }} Release SUCCESSFUL ✅", | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "*superstream-python-clients v${{ steps.release_info.outputs.version }} ${{ steps.release_info.outputs.type }} Release SUCCESSFUL* ✅\n*Branch:* ${{ github.ref_name }}\n*Commit:* <${{ github.event.head_commit.url }}|${{ github.sha }}>\n*Author:* ${{ github.event.head_commit.author.name }}\n*Message:* ${{ github.event.head_commit.message }}" | |
| } | |
| } | |
| ] | |
| } | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| continue-on-error: true | |
| - name: Send Slack notification on failure | |
| if: steps.release_info.outputs.result == 'failure' | |
| uses: slackapi/slack-github-action@v1 | |
| with: | |
| payload: | | |
| { | |
| "text": "superstream-python-clients v${{ steps.release_info.outputs.version }} ${{ steps.release_info.outputs.type }} Release FAILED ❌", | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "*superstream-python-clients v${{ steps.release_info.outputs.version }} ${{ steps.release_info.outputs.type }} Release FAILED* ❌\n*Branch:* ${{ github.ref_name }}\n*Commit:* <${{ github.event.head_commit.url }}|${{ github.sha }}>\n*Author:* ${{ github.event.head_commit.author.name }}\n*Workflow Run:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Details>" | |
| } | |
| } | |
| ] | |
| } | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| continue-on-error: true | |
| - name: Send Slack notification on cancellation | |
| if: steps.release_info.outputs.result == 'cancelled' | |
| uses: slackapi/slack-github-action@v1 | |
| with: | |
| payload: | | |
| { | |
| "text": "superstream-python-clients v${{ steps.release_info.outputs.version }} ${{ steps.release_info.outputs.type }} Release ABORTED ⚠️", | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "*superstream-python-clients v${{ steps.release_info.outputs.version }} ${{ steps.release_info.outputs.type }} Release ABORTED* ⚠️\n*Branch:* ${{ github.ref_name }}\n*Commit:* <${{ github.event.head_commit.url }}|${{ github.sha }}>\n*Author:* ${{ github.event.head_commit.author.name }}" | |
| } | |
| } | |
| ] | |
| } | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| continue-on-error: true |