Skip to content

Commit fa5d1fa

Browse files
authoredApr 27, 2025··
fix: Fix all the broken changes from the last pr (#36)
### Description This PR improve documentation, Adds `unittest`, that, don't use mock data, to ensure it works. Make the code work again. Fixes #35
1 parent 087ecff commit fa5d1fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+6369
-229
lines changed
 
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
name: Deploy | Publish Pypi Packages
2+
3+
on:
4+
push:
5+
branches:
6+
- '**' # All branches for Test PyPI
7+
tags:
8+
- "*"
9+
jobs:
10+
build-and-publish:
11+
runs-on: windows-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: 3.8
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
python -m pip install --upgrade setuptools wheel build twine
26+
27+
- name: Clean dist directory
28+
run: |
29+
if (Test-Path -Path dist) { Remove-Item dist -Recurse -Force }
30+
31+
- name: Extract issue number and suffix
32+
id: issue
33+
if: startsWith(github.ref, 'refs/heads/')
34+
run: |
35+
# Look for #<number> in commit message
36+
$match = git log -1 --pretty=%B | Select-String -Pattern '#(\d+)'
37+
if ($match) {
38+
$num = $match.Matches.Groups[1].Value
39+
$suffix = "rc$num"
40+
} else {
41+
# No issue number => development build
42+
$suffix = 'dev0'
43+
}
44+
echo "SUFFIX=$suffix" >> $env:GITHUB_ENV
45+
echo "suffix=$suffix" >> $env:GITHUB_OUTPUT
46+
47+
- name: Extract version from pyproject.toml
48+
id: version
49+
run: |
50+
$verLine = Get-Content pyproject.toml | Select-String -Pattern 'version = "(.*)"'
51+
$VERSION = $verLine.Matches.Groups[1].Value -replace '^v', ''
52+
echo "VERSION=$VERSION" >> $env:GITHUB_ENV
53+
echo "version=$VERSION" >> $env:GITHUB_OUTPUT
54+
if ("${{ github.ref }}".StartsWith('refs/tags/')) {
55+
$TAG_VERSION = "${{ github.ref }}".Substring(10) -replace '^v', ''
56+
echo "TAG_VERSION=$TAG_VERSION" >> $env:GITHUB_ENV
57+
}
58+
59+
- name: Create temporary pyproject.toml for test build
60+
if: startsWith(github.ref, 'refs/heads/')
61+
run: |
62+
# Read the current pyproject.toml
63+
$content = Get-Content pyproject.toml -Raw
64+
65+
# Get the current version
66+
$version = "${{ env.VERSION }}"
67+
$suffix = "${{ env.SUFFIX }}"
68+
69+
# Update the version with the suffix
70+
$newVersion = "$version.$suffix"
71+
72+
# Replace the version in the content
73+
$updatedContent = $content -replace 'version = "(.*?)"', "version = `"$newVersion`""
74+
75+
# Save to a temporary file
76+
$updatedContent | Out-File -FilePath pyproject.toml.temp -Encoding utf8
77+
78+
# Show the changes
79+
Write-Host "Original version: $version"
80+
Write-Host "Updated version: $newVersion"
81+
82+
# Backup original and replace with temp version
83+
Move-Item -Path pyproject.toml -Destination pyproject.toml.bak -Force
84+
Move-Item -Path pyproject.toml.temp -Destination pyproject.toml -Force
85+
86+
- name: Build package for Test PyPI
87+
if: startsWith(github.ref, 'refs/heads/')
88+
run: |
89+
python -m build
90+
91+
# After building, restore the original pyproject.toml
92+
Move-Item -Path pyproject.toml.bak -Destination pyproject.toml -Force
93+
94+
- name: Build package for PyPI
95+
if: startsWith(github.ref, 'refs/tags/')
96+
run: |
97+
python -m build
98+
99+
- name: Check distributions
100+
run: |
101+
twine check dist/*
102+
103+
- name: Publish to Test PyPI (branch push)
104+
if: startsWith(github.ref, 'refs/heads/')
105+
env:
106+
TWINE_USERNAME: __token__
107+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI }}
108+
run: |
109+
Write-Host "Files ready for upload:"
110+
Get-ChildItem dist/* | ForEach-Object { Write-Host " $_" }
111+
112+
# Upload with verbose output for debugging
113+
twine upload --skip-existing --verbose --repository-url https://test.pypi.org/legacy/ dist/*
114+
115+
- name: Publish to PyPI (new tag)
116+
if: startsWith(github.ref, 'refs/tags/')
117+
env:
118+
TWINE_USERNAME: __token__
119+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
120+
run: |
121+
Write-Host "Files to upload to PyPI:"
122+
Get-ChildItem dist/* | ForEach-Object { Write-Host " $_" }
123+
twine upload --verbose dist/*
124+
125+
- name: Create Step Summary
126+
run: |
127+
# Set the display version based on the ref
128+
if ("${{ github.ref }}".StartsWith("refs/tags/")) {
129+
$displayVersion = "${{ env.TAG_VERSION }}"
130+
} else {
131+
$displayVersion = "${{ env.VERSION }}.${{ env.SUFFIX }}"
132+
}
133+
134+
@"
135+
# MQPy Package
136+
137+
## Installation Instructions
138+
139+
### Important Warning ⚠️
140+
**IMPORTANT: Trading involves substantial risk of loss and is not suitable for all investors.**
141+
142+
- Always use a **demo account** with fake money when testing strategies
143+
- MQPy is provided for **educational purposes only**
144+
- Past performance is not indicative of future results
145+
- Never trade with money you cannot afford to lose
146+
- The developers are not responsible for any financial losses
147+
148+
### Windows-Only Compatibility
149+
This package is designed to work exclusively on Windows operating systems.
150+
151+
### Installation Steps
152+
153+
$( if ("${{ github.ref }}".StartsWith("refs/tags/")) {
154+
@"
155+
#### Production Release
156+
This is an official release version (${{ env.TAG_VERSION }}) published to PyPI.
157+
158+
```
159+
pip install mqpy==${{ env.TAG_VERSION }}
160+
```
161+
"@
162+
} else {
163+
@"
164+
#### Test/RC Version
165+
This is a release candidate version published to Test PyPI.
166+
167+
```
168+
pip install mqpy==$displayVersion --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/
169+
```
170+
"@
171+
})
172+
173+
### Documentation
174+
For complete documentation, visit our [GitHub repository](https://github.com/Joaopeuko/Mql5-Python-Integration).
175+
"@ | Out-File -FilePath $env:GITHUB_STEP_SUMMARY

‎.github/workflows/deploy-semantic-release.yaml

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@ name: Deploy | Semantic Release
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
dry_run:
7+
description: 'Dry run (no changes will be committed)'
8+
type: boolean
9+
default: false
10+
debug:
11+
description: 'Enable verbose debugging output'
12+
type: boolean
13+
default: false
14+
push:
15+
branches:
16+
- '**'
17+
paths-ignore:
18+
- 'docs/**'
19+
- '*.md'
20+
- '.github/workflows/deploy-pypi-packages.yaml'
521

622
jobs:
723
release:
8-
runs-on: windows-latest
24+
runs-on: ubuntu-latest
925
concurrency: release
1026
permissions:
1127
contents: write
@@ -16,9 +32,145 @@ jobs:
1632
with:
1733
fetch-depth: 0
1834

35+
- name: Set run mode
36+
id: set_mode
37+
shell: bash
38+
run: |
39+
IS_DRY_RUN=$([ "${{ github.event_name }}" = "push" ] || [ "${{ inputs.dry_run }}" = "true" ] && echo "true" || echo "false")
40+
echo "is_dry_run=$IS_DRY_RUN" >> $GITHUB_OUTPUT
41+
echo "Mode: $([ "$IS_DRY_RUN" = "true" ] && echo "Dry run" || echo "Full release")"
42+
43+
- name: Python Release - Dry Run
44+
id: release_dryrun
45+
if: steps.set_mode.outputs.is_dry_run == 'true'
46+
uses: python-semantic-release/python-semantic-release@v9.20.0
47+
with:
48+
github_token: ${{ secrets.GITHUB_TOKEN }}
49+
push: "false"
50+
commit: "false"
51+
tag: "false"
52+
changelog: "false"
53+
root_options: ${{ inputs.debug && '-vv --noop' || '-v --noop' }}
54+
55+
- name: Extract Next Version Info
56+
id: extract_next_version
57+
if: steps.set_mode.outputs.is_dry_run == 'true' && steps.release_dryrun.outputs.version == ''
58+
shell: bash
59+
run: |
60+
# When no release is needed, semantic-release doesn't output the next version
61+
# We need to determine it manually from the commit history
62+
63+
# Check if we have commits that would trigger a version bump
64+
FEAT_COMMITS=$(git log --grep="^feat:" -i --pretty=format:"%h" | wc -l)
65+
FIX_COMMITS=$(git log --grep="^fix:" -i --pretty=format:"%h" | wc -l)
66+
BREAKING_COMMITS=$(git log --grep="BREAKING CHANGE:" -i --pretty=format:"%h" | wc -l)
67+
68+
# Get current version from pyproject.toml
69+
CURRENT_VERSION=$(grep -m 1 'version = "' pyproject.toml | awk -F'"' '{print $2}' | sed 's/^v//')
70+
echo "Current version: $CURRENT_VERSION"
71+
72+
# Split current version into components
73+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
74+
75+
# Determine the next version based on conventional commits
76+
if [ "$BREAKING_COMMITS" -gt 0 ]; then
77+
# Major version bump
78+
NEXT_VERSION="$((MAJOR + 1)).0.0"
79+
elif [ "$FEAT_COMMITS" -gt 0 ]; then
80+
# Minor version bump
81+
NEXT_VERSION="$MAJOR.$((MINOR + 1)).0"
82+
elif [ "$FIX_COMMITS" -gt 0 ]; then
83+
# Patch version bump
84+
NEXT_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
85+
else
86+
# No significant changes, use development version
87+
NEXT_VERSION="${CURRENT_VERSION}.dev0"
88+
fi
89+
90+
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
91+
echo "next_tag=v$NEXT_VERSION" >> $GITHUB_OUTPUT
92+
echo "Determined next version: $NEXT_VERSION"
93+
1994
- name: Python Release
95+
id: release
96+
if: ${{ github.event_name == 'workflow_dispatch' && !inputs.dry_run }}
2097
uses: python-semantic-release/python-semantic-release@v9.20.0
2198
with:
2299
github_token: ${{ secrets.GITHUB_TOKEN }}
23100
push: "true"
24101
changelog: "true"
102+
root_options: ${{ inputs.debug && '-vv' || '-v' }}
103+
104+
- name: Create Step Summary
105+
shell: bash
106+
run: |
107+
IS_DRY_RUN="${{ steps.set_mode.outputs.is_dry_run }}"
108+
RELEASE_ID=$([ "$IS_DRY_RUN" = "true" ] && echo "release_dryrun" || echo "release")
109+
WAS_RELEASED=$([ "${{ steps.release_dryrun.outputs.released || steps.release.outputs.released }}" = "true" ] && echo "Yes" || echo "No")
110+
111+
# First try to get version from release outputs
112+
VERSION="${{ steps.release_dryrun.outputs.version || steps.release.outputs.version }}"
113+
TAG="${{ steps.release_dryrun.outputs.tag || steps.release.outputs.tag }}"
114+
115+
# If no version from release outputs, try to get from extract_next_version step
116+
if [ "$IS_DRY_RUN" = "true" ] && [ -z "$VERSION" ]; then
117+
VERSION="${{ steps.extract_next_version.outputs.next_version }}"
118+
TAG="${{ steps.extract_next_version.outputs.next_tag }}"
119+
fi
120+
121+
# Display trigger information
122+
if [ "${{ github.event_name }}" = "push" ]; then
123+
TRIGGER_INFO="Triggered by push to branch: ${{ github.ref_name }}"
124+
else
125+
TRIGGER_INFO="Triggered manually via workflow dispatch"
126+
fi
127+
128+
# Create warning text for dry run
129+
if [ "$IS_DRY_RUN" = "true" ]; then
130+
DRY_RUN_TEXT="⚠️ This is a dry run - no changes were committed"
131+
TITLE_SUFFIX=" (Dry Run)"
132+
else
133+
DRY_RUN_TEXT=""
134+
TITLE_SUFFIX=""
135+
fi
136+
137+
cat > $GITHUB_STEP_SUMMARY << EOF
138+
# MQPy Release$TITLE_SUFFIX
139+
140+
## Release Summary
141+
142+
$TRIGGER_INFO
143+
$DRY_RUN_TEXT
144+
145+
Current/Next Version: $VERSION
146+
Current/Next Tag: $TAG
147+
Release required: $WAS_RELEASED
148+
149+
## Installation Instructions
150+
151+
### Important Warning ⚠️
152+
**IMPORTANT: Trading involves substantial risk of loss and is not suitable for all investors.**
153+
154+
- Always use a **demo account** with fake money when testing strategies
155+
- MQPy is provided for **educational purposes only**
156+
- Past performance is not indicative of future results
157+
- Never trade with money you cannot afford to lose
158+
- The developers are not responsible for any financial losses
159+
160+
### Windows-Only Compatibility
161+
This package is designed to work exclusively on Windows operating systems.
162+
163+
### Installation Steps
164+
165+
#### $([ "$IS_DRY_RUN" = "true" ] && echo "Test/RC Version" || echo "Production Version")
166+
$([ "$IS_DRY_RUN" = "true" ] && echo "This is a release candidate version published to Test PyPI.
167+
168+
\`\`\`
169+
pip install mqpy==$VERSION --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/
170+
\`\`\`" || echo "\`\`\`
171+
pip install mqpy==$VERSION
172+
\`\`\`")
173+
174+
### Documentation
175+
For complete documentation, visit our [GitHub repository](https://github.com/Joaopeuko/Mql5-Python-Integration).
176+
EOF

0 commit comments

Comments
 (0)
Please sign in to comment.