Lint / Test / Publish #99
Workflow file for this run
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
name: Build and Publish | |
on: | |
push: | |
branches: ["main"] | |
# We only deploy on tags and main branch | |
tags: | |
# Only run on tags that match the following regex | |
# This will match tags like 1.0.0, 1.0.1, etc. | |
- "[0-9]+.[0-9]+.[0-9]+" | |
# Build on pull requests | |
pull_request: | |
jobs: | |
lint_and_test: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Set python version to 3.11 | |
- name: set python version | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
# Install Build stuff | |
- name: Install Dependencies | |
run: | | |
pip install poetry \ | |
&& poetry config virtualenvs.create false \ | |
&& poetry install | |
# Ruff | |
- name: Ruff check | |
run: | | |
poetry run ruff . | |
# Mypy | |
- name: Mypy Check | |
run: | | |
poetry run mypy . | |
# Tests | |
- name: Run Tests | |
run: | | |
poetry run pytest . | |
create_pr_on_public: | |
if: startsWith(github.ref, 'refs/tags') | |
runs-on: ubuntu-latest | |
needs: lint_and_test | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.PUBLIC_CLIENT_WRITE_TOKEN }} | |
- name: Pull public updates | |
env: # We cannot use the github bot token to push to the public repo, we have to use one with more permissions | |
GITHUB_TOKEN: ${{ secrets.PUBLIC_CLIENT_WRITE_TOKEN }} | |
run: | | |
set -x | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "mayo@mistral.ai" | |
git remote add public https://github.com/mistralai/client-python.git | |
git remote update | |
# Create a diff of the changes, ignoring the ci workflow | |
git merge public/main --no-commit --no-ff --no-edit --allow-unrelated-histories | |
# If there are changes, commit them | |
if ! git diff-index --cached --quiet HEAD; then | |
git commit -m "Update from public repo" | |
git push origin ${{github.ref}} | |
else | |
echo "No changes to apply" | |
fi | |
- name: Push to public repo | |
env: | |
GITHUB_TOKEN: ${{ secrets.PUBLIC_CLIENT_WRITE_TOKEN }} | |
run: | | |
git checkout public/main | |
git checkout -b update/${{github.ref_name}} | |
# write version number to version file | |
echo ${{github.ref_name}} > version.txt | |
git add . | |
git commit -m "Bump version file" | |
# create a diff of this ref and the public repo | |
git diff update/${{github.ref_name}} ${{github.ref_name}} --binary -- . ':!.github' > changes.diff | |
# apply the diff to the current branch | |
git apply changes.diff | |
# commit the changes | |
git add . | |
git commit -m "Update version to ${{github.ref_name}}" | |
# push the changes | |
git push public update/${{github.ref_name}} | |
# Create a PR from this branch to the public repo | |
gh pr create --title "Update client to ${{github.ref_name}}" --body "This PR was automatically created by a GitHub Action" --base main --head update/${{github.ref_name}} --repo mistralai/client-python |