Skip to content

Refactor MAB and Strategy Classes with Cold Start Methods and Enhance… #26

Refactor MAB and Strategy Classes with Cold Start Methods and Enhance…

Refactor MAB and Strategy Classes with Cold Start Methods and Enhance… #26

name: CD
on:
push:
branches:
- main
jobs:
check_version_and_publish:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.8", "3.9", "3.10" ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.poetry/bin:$PATH"
- name: Install project dependencies with Poetry
run: |
poetry install
- name: Style check
run: |
# run pre-commit hooks
poetry run pre-commit run --all-files
- name: Run tests
run: |
poetry run pytest -vv -k 'not time and not update_parallel'
- name: Extract version from pyproject.toml
id: extract_version
run: |
VERSION=v$(poetry version -s)
echo "PACKAGE_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Verify if version has changed
id: version_check
run: |
if [ $(git tag -l "${{ env.PACKAGE_VERSION }}") ]; then
echo "Version ${{ env.PACKAGE_VERSION }} already exists."
echo "VERSION_CHANGED=false" >> $GITHUB_ENV
else
echo "VERSION_CHANGED=true" >> $GITHUB_ENV
fi
- name: Create a Git tag
if: ${{ env.VERSION_CHANGED == 'true' && matrix.python-version == '3.8' }}
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
git tag "${{ env.PACKAGE_VERSION }}"
git push origin "${{ env.PACKAGE_VERSION }}"
- name: Publish Draft Release
if: ${{ env.VERSION_CHANGED == 'true' && matrix.python-version == '3.8' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
const draftRelease = releases.find(r => r.draft && r.name === 'Draft');
if (draftRelease) {
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: draftRelease.id,
tag_name: process.env.PACKAGE_VERSION,
name: process.env.PACKAGE_VERSION,
draft: false
});
} else {
core.setFailed(`Draft release named "Draft" not found.`);
};
- name: Build and publish to pypi
if: ${{ env.VERSION_CHANGED == 'true' && matrix.python-version == '3.8' }}
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish --build