[DOP-25348] Fix release workflow #13
Workflow file for this run
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: PyPI release | |
| on: | |
| push: | |
| tags: | |
| - '[0-9]+.[0-9]+.[0-9]+' | |
| env: | |
| DEFAULT_PYTHON: '3.13' | |
| jobs: | |
| release: | |
| name: Release package | |
| runs-on: ubuntu-latest | |
| if: github.repository == 'MobileTeleSystems/data-rentgen' # prevent running on forks | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/data-rentgen | |
| permissions: | |
| id-token: write # to auth in PyPI | |
| contents: write # to create Github release | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python ${{ env.DEFAULT_PYTHON }} | |
| id: python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.DEFAULT_PYTHON }} | |
| - name: Install system dependencies | |
| # this step is needed for successful installation of "bonsai" library in python dependencies | |
| run: sudo apt-get update && sudo apt-get install -y libldap2-dev libsasl2-dev | |
| - name: Install poetry | |
| uses: snok/install-poetry@v1 | |
| - name: Cache poetry | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pypoetry | |
| key: ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-release-${{ hashFiles('**/poetry.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-release-${{ hashFiles('**/poetry.lock') }} | |
| ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-release- | |
| ${{ runner.os }}-python- | |
| - name: Install dependencies | |
| run: | | |
| poetry install --no-root --extras server --extras consumer --extras postgres --without docs,test,dev | |
| - name: Generate OpenAPI Schema | |
| run: | | |
| source .env.local | |
| poetry run python -m data_rentgen.server.scripts.export_openapi_schema docs/_static/openapi.json | |
| - name: Fix logo in Readme | |
| run: | | |
| sed -i "s#image:: docs/#image:: https://raw.githubusercontent.com/MobileTeleSystems/data-rentgen/$GITHUB_SHA/docs/#g" README.rst | |
| sed -i "s#logo_wide_white_text.svg#logo_wide.svg#g" README.rst | |
| - name: Build package | |
| run: poetry build | |
| - name: Publish package | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| - name: Generate SBOM | |
| run: | | |
| pip install cyclonedx-bom | |
| cyclonedx-py poetry --extras server,consumer,postgres,gssapi --without dev,test,docs > sbom.cyclonedx.json | |
| - name: Get changelog | |
| run: | | |
| cat docs/changelog/$GITHUB_REF_NAME.rst > changelog.rst | |
| - name: Prepare rST syntax for conversion to Markdown | |
| run: | | |
| # Replace Github links from Sphinx syntax with Markdown | |
| sed -i -E 's/:github:issue:`(.*)`/#\1/g' changelog.rst | |
| sed -i -E 's/:github:pull:`(.*)`/#\1/g' changelog.rst | |
| sed -i -E 's/:github:user:`(.*)`/@\1/g' changelog.rst | |
| sed -i -E 's/:github:org:`(.*)`/@\1/g' changelog.rst | |
| - name: Convert rST to Markdown | |
| uses: docker://pandoc/core:2.9 | |
| with: | |
| args: >- | |
| --output=changelog.md | |
| --from=rst | |
| --to=gfm | |
| --wrap=none | |
| changelog.rst | |
| - name: Fixing Markdown syntax after conversion | |
| run: | | |
| # Replace ``` {.python caption="abc"} with ```python caption="abc" | |
| sed -i -E 's/``` \{\.(.*)\}/```\1/g' changelog.md | |
| # Replace ``` python with ```python | |
| sed -i -E 's/``` (\w+)/```\1/g' changelog.md | |
| # Replace \# with # | |
| sed -i -E 's/\\#/#/g' changelog.md | |
| - name: Get release name | |
| id: release-name | |
| run: | | |
| # Release name looks like: 0.7.0 (2023-05-15) | |
| echo -n name= > "$GITHUB_OUTPUT" | |
| cat changelog.md | head -1 | sed -E "s/#+\s*//g" >> "$GITHUB_OUTPUT" | |
| - name: Fix headers | |
| run: | | |
| # Remove header with release name | |
| sed -i -e '1,2d' changelog.md | |
| - name: Create Github release | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| draft: false | |
| prerelease: false | |
| name: ${{ steps.release-name.outputs.name }} | |
| body_path: changelog.md | |
| files: |- | |
| dist/*.tar.gz | |
| dist/*.whl | |
| docs/_static/openapi.json | |
| sbom.cyclonedx.json |