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
# workflow that receives updated api specifications from https://github.com/wordlift/docs, bumps version, build and publish to pypi | |
name: Publish Python π distribution π¦ to PyPI and TestPyPI | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
name: Build distribution π¦ | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the first repository | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.WORKFLOW_TOKEN }} | |
# Step 2: Set up Node.js | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" # Specify the Node.js version to use | |
# Step 3: Install openapi-merge-cli and openapi-generator-cli | |
- name: Install openapi-merge-cli | |
run: | | |
npm i openapi-merge-cli ajv uri-js | |
npm i @openapitools/openapi-generator-cli | |
# Step 4: Set up Python | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.7" | |
# Step 5: Install Python dependencies | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.pinned.txt | |
pip install build | |
# Step 6: Run the Python script to generate json for openApi-merge | |
- name: generate json for openApi-merge | |
run: python3 ./utils/json_merge_generator.py | |
# Step 7: Merge the YAML files | |
- name: Merge the yaml files | |
run: npx openapi-merge-cli --config ./openapi-merge.json | |
# Step 8: Bump version in config.json | |
- name: Bump version in config.json | |
run: python3 ./utils/bump.py | |
# Step 9: Generate the SDK | |
- name: Generate the SDK | |
run: npx @openapitools/openapi-generator-cli generate -i ./wordliftApiSpec.yaml -g python -c config.json --package-name 'wordlift_client' --library 'asyncio' | |
- name: Patch generated files | |
run: | | |
git apply -p1 .patches/1-add-str.patch | |
cp -f requirements.pinned.txt requirements.txt | |
# Step 3: Get version from setup | |
- name: Get version from setup.py | |
id: get_version | |
run: | | |
version=$(python setup.py --version) | |
echo "version=$version" >> $GITHUB_ENV # Appends the version number to the $GITHUB_ENV file, making it an environment variable for subsequent steps, need it for commit | |
# Step 4: push updated client | |
- name: Commit and Push Changes | |
env: | |
VERSION: ${{ env.version }} | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git tag -a $VERSION -m "Release version $VERSION" | |
git add . | |
git commit -m "Update client to version $VERSION [skip ci]" | |
git push --follow-tags origin main | |
# Step 10: Store the package for testing | |
- name: Store the package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: python-package | |
path: | | |
test/ | |
wordlift_client/ | |
requirements.pinned.txt | |
retention-days: 1 | |
# Step 11: Build the binary | |
- name: Build a binary wheel and a source tarball | |
run: | | |
python3 -m build | |
- name: Store the distribution packages | |
uses: actions/upload-artifact@v3 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
test: | |
name: Test client | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ] | |
steps: | |
# Step 1: Download the package | |
- name: Download the package | |
uses: actions/download-artifact@v4 | |
with: | |
name: python-package | |
# Step 2: Set up Python | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
# Step 3: Install Python dependencies | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.pinned.txt | |
pip install 'pytest>=7.4.4,<8.3.0' | |
# Step 4: Run tests | |
- name: Run tests | |
run: pytest | |
publish-to-pypi: | |
name: >- | |
Publish Python π distribution π¦ to PyPI | |
needs: | |
- test | |
runs-on: ubuntu-latest | |
environment: | |
name: pypi | |
url: https://pypi.org/p/wordlift-client | |
permissions: | |
id-token: write | |
steps: | |
- name: Download all the dists | |
uses: actions/download-artifact@v3 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: Publish distribution π¦ to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
publish-to-testpypi: | |
name: Publish Python π distribution π¦ to TestPyPI | |
needs: | |
- test | |
runs-on: ubuntu-latest | |
environment: | |
name: testpypi | |
url: https://test.pypi.org/p/wordlift-client | |
permissions: | |
id-token: write | |
steps: | |
- name: Download all the dists | |
uses: actions/download-artifact@v3 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: Publish distribution π¦ to TestPyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ |