Merge pull request #15 from lexakimov/feature #21
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - v[0-9]+.[0-9]+.[0-9]+ | |
| permissions: | |
| contents: write | |
| jobs: | |
| check-branch: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| on_master: ${{ steps.check.outputs.on_master }} | |
| steps: | |
| - name: Check out repository code on master | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: 'master' | |
| fetch-depth: 0 | |
| - name: Check if tag commit is on master branch | |
| id: check | |
| run: | | |
| # Get the commit SHA of the pushed tag | |
| TAG_COMMIT_SHA=$(git rev-parse ${{ github.ref }}) | |
| echo "Tag commit SHA: $TAG_COMMIT_SHA" | |
| # Check if this commit is an ancestor of the master branch HEAD (current checkout) | |
| # Use 'git branch --contains <commit>' is another way, but requires fetching all branches potentially | |
| if git merge-base --is-ancestor $TAG_COMMIT_SHA HEAD; then | |
| echo "Tag commit is on master branch." | |
| echo "on_master=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Tag commit is NOT on master branch." | |
| echo "on_master=false" >> $GITHUB_OUTPUT | |
| fi | |
| check-version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| versions_match: ${{ steps.check-version.outputs.versions_match }} | |
| steps: | |
| - name: Check out repository code for the tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install -e . | |
| - name: Compare tag version with setup.py version | |
| id: check-version | |
| run: | | |
| # Получаем версию из тега (убираем префикс 'v') | |
| TAG_VERSION=${GITHUB_REF#refs/tags/v} | |
| echo "Tag version: $TAG_VERSION" | |
| # Извлекаем версию из setup.py | |
| SETUP_VERSION=$(python setup.py --version) | |
| echo "Setup.py version: $SETUP_VERSION" | |
| # Сравниваем версии | |
| if [ "$TAG_VERSION" = "$SETUP_VERSION" ]; then | |
| echo "✅ Версии совпадают: $TAG_VERSION = $SETUP_VERSION" | |
| echo "versions_match=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "❌ Версии не совпадают: $TAG_VERSION ≠ $SETUP_VERSION" | |
| echo "versions_match=false" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| test: | |
| needs: [check-branch, check-version] | |
| if: needs.check-branch.outputs.on_master == 'true' && needs.check-version.outputs.versions_match == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository code for the tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install -e . | |
| - name: Run tests with pytest | |
| run: | | |
| pytest | |
| build-package: | |
| needs: | |
| - check-branch | |
| - check-version | |
| - test | |
| if: needs.check-branch.outputs.on_master == 'true' && needs.check-version.outputs.versions_match == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository code for the tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install build | |
| - name: Build package | |
| run: | | |
| python setup.py sdist bdist_wheel | |
| - name: Upload package artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-packages | |
| path: dist/ | |
| build-native: | |
| needs: | |
| - check-branch | |
| - check-version | |
| - test | |
| if: needs.check-branch.outputs.on_master == 'true' && needs.check-version.outputs.versions_match == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository code for the tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install build | |
| - name: Build native | |
| run: | | |
| python build_native.py | |
| mv dist_native/xmlgenerator dist_native/xmlgenerator-linux-amd64 | |
| - name: Upload native artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: native-binary | |
| path: dist_native/xmlgenerator-linux-amd64 | |
| create-release: | |
| needs: | |
| - check-branch | |
| - check-version | |
| - build-package | |
| - build-native | |
| if: needs.check-branch.outputs.on_master == 'true' && needs.check-version.outputs.versions_match == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download Python packages | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-packages | |
| path: dist | |
| - name: Download native binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: native-binary | |
| path: dist_native | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| id: create_release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| name: ${{ github.ref_name }} | |
| files: | | |
| dist/*.whl | |
| dist/*.tar.gz | |
| dist_native/xmlgenerator-linux-amd64 | |
| publish-package: | |
| needs: | |
| - check-branch | |
| - check-version | |
| - build-package | |
| if: needs.check-branch.outputs.on_master == 'true' && needs.check-version.outputs.versions_match == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install twine | |
| - name: Download Python packages | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-packages | |
| path: dist | |
| - name: Publish package to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: | | |
| twine upload dist/* |