Skip to content

package

package #3

name: Deploy | Publish Pypi Packages
on:
push:
branches:
- '**' # All branches for Test PyPI
tags:
- "*"
jobs:
build-and-publish:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools wheel build twine
- name: Extract issue number
id: issue
if: startsWith(github.ref, 'refs/heads/')
run: |
$ISSUE_NUMBER = git log -1 --pretty=%B | Select-String -Pattern '#(\d+)' | ForEach-Object { $_.Matches.Groups[1].Value }
if (-not $ISSUE_NUMBER) { $ISSUE_NUMBER = "dev" }
echo "ISSUE_NUMBER=$ISSUE_NUMBER" >> $env:GITHUB_ENV
echo "issue_number=$ISSUE_NUMBER" >> $env:GITHUB_OUTPUT
- name: Extract version from pyproject.toml
id: version
run: |
$VERSION = (Get-Content pyproject.toml | Select-String -Pattern 'version = "(.*)"').Matches.Groups[1].Value
$VERSION = $VERSION -replace '^v', '' # Remove 'v' prefix if present
echo "VERSION=$VERSION" >> $env:GITHUB_ENV
echo "version=$VERSION" >> $env:GITHUB_OUTPUT
# For tags, extract the tag version
if ("${{ github.ref }}".StartsWith("refs/tags/")) {
$TAG_VERSION = "${{ github.ref }}".Substring(10) # Remove 'refs/tags/' prefix
$TAG_VERSION = $TAG_VERSION -replace '^v', '' # Remove 'v' prefix if present
echo "TAG_VERSION=$TAG_VERSION" >> $env:GITHUB_ENV
}
- name: Build package
run: |
python -m build
- name: Publish to Test PyPI (branch push)
if: startsWith(github.ref, 'refs/heads/')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI }}
run: |
# Rename dist files to include RC and issue number
Get-ChildItem -Path dist -Filter "*.whl" | ForEach-Object {
$newName = $_.Name -replace "(mqpy-\d+\.\d+\.\d+)-", "`$1.rc${{ steps.issue.outputs.issue_number }}-"
Rename-Item -Path $_.FullName -NewName $newName
}
Get-ChildItem -Path dist -Filter "*.tar.gz" | ForEach-Object {
$newName = $_.Name -replace "(mqpy-\d+\.\d+\.\d+)", "`$1.rc${{ steps.issue.outputs.issue_number }}"
Rename-Item -Path $_.FullName -NewName $newName
}
twine upload --skip-existing --repository-url https://test.pypi.org/legacy/ dist/*
- name: Publish to PyPI (new tag)
if: startsWith(github.ref, 'refs/tags/')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
twine upload dist/*
- name: Create Step Summary
run: |
@"
# MQPy Package
## Installation Instructions
### Important Warning ⚠️
!!! warning "Trading Risk Warning"
**IMPORTANT: Trading involves substantial risk of loss and is not suitable for all investors.**
- Always use a **demo account** with fake money when testing strategies
- MQPy is provided for **educational purposes only**
- Past performance is not indicative of future results
- Never trade with money you cannot afford to lose
- The developers are not responsible for any financial losses
### Windows-Only Compatibility
This package is designed to work exclusively on Windows operating systems.
### Installation Steps
$( if ("${{ github.ref }}".StartsWith("refs/tags/")) {
@"
#### Production Release
This is an official release version (${{ env.TAG_VERSION }}) published to PyPI.
```
pip install mqpy==${{ env.TAG_VERSION }}
```
"@
} else {
@"
#### Test/RC Version
This is a release candidate version published to Test PyPI.
```
pip install mqpy==${{ env.VERSION }}.rc${{ env.ISSUE_NUMBER }} --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/
```
"@
})
### Documentation
For complete documentation, visit our [GitHub repository](https://github.com/Joaopeuko/Mql5-Python-Integration).
"@ | Out-File -FilePath $env:GITHUB_STEP_SUMMARY