Release on PyPI and GitHub #37
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 on PyPI and GitHub | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release-type: | |
| description: "Release type" | |
| required: true | |
| default: "tag-num" | |
| type: choice | |
| options: | |
| - major | |
| - minor | |
| - patch | |
| - upgrade-beta | |
| - new-beta-major | |
| - new-beta-minor | |
| - new-beta-patch | |
| - final | |
| skip-pypi: | |
| description: "If true, skip publishing to PyPI" | |
| default: false | |
| type: boolean | |
| jobs: | |
| bumpver-pyproject: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.current-version.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install bumpver | |
| run: python -m pip install bumpver | |
| # Evaluate input and bumpver accordingly | |
| - name: Execute script bumpver | |
| run: ./.github/scripts/bump.sh ${{ inputs.release-type }} | |
| # Store current version for later use | |
| - name: Current version | |
| id: current-version | |
| run: | | |
| ver=$(bumpver show -n --environ | grep CUR | awk '{gsub(/CURRENT_VERSION=/, ""); print}') | |
| echo "version=${ver}" >> "$GITHUB_OUTPUT" | |
| # Commit modifications to pyproject.toml | |
| - name: Commit changes | |
| run: | | |
| git config user.name "$GITHUB_ACTOR" | |
| git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | |
| git commit -a -m "bump: new version ${{ steps.current-version.outputs.version }}" | |
| git push | |
| build-n-publish: | |
| name: Build and publish | |
| if: ${{ !inputs.skip-pypi }} | |
| needs: bumpver-pyproject | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Force with ref as https://github.com/orgs/community/discussions/110853 | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| # Build wheel to upload | |
| - name: Install build and build a binary wheel | |
| run: python -m pip install build && python -m build | |
| # Publish to PyPI | |
| - name: Publish distribution to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_TOKEN }} | |
| tag-and-release: | |
| name: Tag and release on Github | |
| needs: [bumpver-pyproject] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| fetch-depth: 0 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install cliff | |
| run: python -m pip install git-cliff | |
| - name: Generate a changelog | |
| env: | |
| VERSION: ${{ needs.bumpver-pyproject.outputs.version }} | |
| BETA: ${{ inputs.release-type == 'upgrade-beta' || startsWith(inputs.release-type, 'new-beta')}} | |
| run: ./.github/scripts/changelog.sh ${{ env.VERSION }} ${{ env.BETA }} | |
| - name: Create Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ needs.bumpver-pyproject.outputs.version }} | |
| BETA: ${{ inputs.release-type == 'upgrade-beta' || startsWith(inputs.release-type, 'new-beta')}} | |
| with: | |
| name: ${{ env.VERSION }} | |
| tag_name: ${{ env.VERSION }} | |
| body_path: CHANGELOG.md | |
| draft: false | |
| prerelease: ${{ env.BETA }} | |
| # Send a trigger to python wrapper repo | |
| trigger: | |
| runs-on: ubuntu-latest | |
| needs: [bumpver-pyproject, build-n-publish] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Trigger Workflow in Another Repository | |
| run: | | |
| # Set the required variables | |
| repo_owner="scc-digitalhub" | |
| event_type="trigger-workflow" | |
| lib_name="python" | |
| lib_vers=${{ needs.bumpver-pyproject.outputs.version }} | |
| branch=${{ github.ref }} | |
| # Define the repositories to trigger | |
| repos=( "digitalhub-tests" "digitalhub-serverless" "digitalhub-sdk-wrapper-hera") | |
| # Loop over the repositories and trigger the workflow | |
| for repo in "${repos[@]}"; do | |
| curl -L \ | |
| -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.TRIGGER_PAT }}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/$repo_owner/$repo/dispatches \ | |
| -d "{\"event_type\": \"$event_type\", \"client_payload\": {\"lib_name\": \"$lib_name\", \"lib_vers\": \"$lib_vers\", \"branch\": \"$branch\"}}" | |
| done |