Skip to content

Auto adjust alpaca data for compatibility with TradierData #1265

Auto adjust alpaca data for compatibility with TradierData

Auto adjust alpaca data for compatibility with TradierData #1265

Workflow file for this run

# .github/workflows/lumibot-ci-cd.yml
# ------------------------------------------------------------------
name: LumiBot CI/CD
# ──────────────────────────────────────────────────────────────────
# Run the workflow on:
# • every PR targeting our main branches – as before
# • every direct push to those branches – NEW (so the
# default-branch README can find a successful
# run and the workflow can commit coverage.svg)
# ──────────────────────────────────────────────────────────────────
on:
push:
branches: [dev, main]
pull_request:
branches: [dev, main]
# ──────────────────────────────────────────────────────────────────
# Give GITHUB_TOKEN write rights so the job can push coverage.svg
# (read-only is the default for workflows since Oct 2023)
# ──────────────────────────────────────────────────────────────────
permissions:
contents: write
# permissions:
# # Gives the action the necessary permissions for publishing new
# # comments in pull requests.
# pull-requests: write
# # Gives the action the necessary permissions for editing existing
# # comments (to avoid publishing multiple comments in the same PR)
# contents: write
# # Gives the action the necessary permissions for looking up the
# # workflow that launched this workflow, and download the related
# # artifact that contains the comment to be published
# actions: read
jobs:
LintAndTest:
runs-on: ubuntu-latest
timeout-minutes: 20
environment: unit-tests
env:
AIOHTTP_NO_EXTENSIONS: 1
POLYGON_API_KEY: ${{ secrets.POLYGON_API_KEY }}
POLYGON_IS_PAID_SUBSCRIPTION: $POLYGON_IS_PAID_SUBSCRIPTION
THETADATA_USERNAME: ${{ secrets.THETADATA_USERNAME }}
THETADATA_PASSWORD: ${{ secrets.THETADATA_PASSWORD }}
ALPACA_TEST_API_KEY: ${{secrets.ALPACA_TEST_API_KEY}} # Required for alpaca unit tests
ALPACA_TEST_API_SECRET: ${{secrets.ALPACA_TEST_API_SECRET}} # Required for alpaca unit tests
TRADIER_TEST_ACCESS_TOKEN: ${{secrets.TRADIER_TEST_ACCESS_TOKEN}} # Required for tradier unit tests
TRADIER_TEST_ACCOUNT_NUMBER: ${{secrets.TRADIER_TEST_ACCOUNT_NUMBER}} # Required for tradier unit tests
steps:
# ------------------------------------------------------------
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pip
- name: Install dependencies
run: |
echo "Set AIOHTTP_NO_EXTENSIONS=$AIOHTTP_NO_EXTENSIONS so that aiohttp doesn't try to install C extensions"
python -m pip install --upgrade pip
pip install requests
pip install -r requirements_dev.txt
# python setup.py install # <-- keep commented if still flaky
# ------------------------------------------------------------
- name: Run Linter
run: |
# Remove -e flag to fail the run if issues are found
ruff check . -e
# ------------------------------------------------------------
- name: Run Unit Tests with coverage
run: |
coverage run
coverage xml -o coverage.xml # -> for badge
coverage html -d Lumibot # -> output to Lumibot folder
coverage report
# Make the HTML report downloadable from the Actions artefacts tab
- name: Upload coverage HTML
uses: actions/upload-artifact@v4
with:
name: coverage-html
path: Lumibot
retention-days: 7
# ------------------------------------------------------------
# Create / update the SVG badge (only on direct pushes to our
# main branches, never on PRs/forks so we avoid permission woes)
# ------------------------------------------------------------
- name: Generate coverage badge
if: github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main')
uses: tj-actions/coverage-badge-py@v2
with:
output: coverage.svg
# Only commit if the badge actually changed
- name: Detect changed badge
if: github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main')
id: verify
uses: tj-actions/verify-changed-files@v16
with:
files: coverage.svg
# Commit updated badge to badge branch
- name: Commit updated badge to badge branch
if: steps.verify.outputs.files_changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Save the coverage.svg file temporarily
mv coverage.svg coverage.svg.tmp
# Try to fetch the badge branch, create it if it doesn't exist
git fetch origin badge || echo "Badge branch doesn't exist yet"
# Check if badge branch exists locally
if git show-ref --verify --quiet refs/heads/badge; then
git checkout badge
# Pull latest changes to avoid non-fast-forward rejection
git pull origin badge --no-rebase || echo "Could not pull from badge branch, it might be new"
else
# Create a new orphan branch if it doesn't exist
git checkout --orphan badge
git rm -rf .
fi
# Restore the coverage.svg file
mv coverage.svg.tmp coverage.svg
git add coverage.svg
git commit -m "ci: update coverage badge" || echo "No changes to commit"
# Force push with lease to handle potential conflicts while still being safe
git push --force-with-lease origin badge
git checkout $GITHUB_REF_NAME