|
| 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 |
0 commit comments