Add docker and safe dir option #5
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: Build | |
| on: | |
| push: | |
| branches: [main, "release/*"] | |
| pull_request: | |
| jobs: | |
| package: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.git_version.outputs.BUILD_VERSION }} | |
| version_major: ${{ steps.git_version.outputs.BUILD_VERSION_MAJOR }} | |
| version_minor: ${{ steps.git_version.outputs.BUILD_VERSION_MINOR }} | |
| version_patch: ${{ steps.git_version.outputs.BUILD_VERSION_PATCH }} | |
| version_build: ${{ steps.git_version.outputs.BUILD_VERSION_BUILD }} | |
| tag: ${{ steps.git_version.outputs.BUILD_VERSION_TAG }} | |
| branch: ${{ steps.git_version.outputs.BUILD_VERSION_BRANCH }} | |
| commit: ${{ steps.git_version.outputs.BUILD_VERSION_COMMIT }} | |
| short: ${{ steps.git_version.outputs.BUILD_VERSION_SHORT }} | |
| full: ${{ steps.git_version.outputs.BUILD_VERSION_FULL }} | |
| extended: ${{ steps.git_version.outputs.BUILD_VERSION_EXTENDED }} | |
| default_branch: ${{ steps.git_version.outputs.BUILD_VERSION_DEFAULT_BRANCH }} | |
| release_branches: ${{ steps.git_version.outputs.BUILD_VERSION_RELEASE_BRANCHES }} | |
| steps: | |
| - uses: actions/checkout@v6.0.3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6.2.0 | |
| with: | |
| python-version: "3.13" | |
| - name: Install build tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build | |
| - name: Generate _version.py from git tags | |
| run: python tools/write_version.py | |
| - name: Build package | |
| run: python -m build | |
| - name: Install built package | |
| run: pip install dist/*.whl | |
| - name: Extract version info from built package | |
| id: git_version | |
| run: | | |
| while IFS='=' read -r key value; do | |
| echo "$key=$value" >> "$GITHUB_OUTPUT" | |
| done < <(git-version --property env) | |
| - name: Show version info | |
| run: | | |
| echo "═══════════════════════════════════════" | |
| echo " GIT VERSION INFORMATION" | |
| echo "═══════════════════════════════════════" | |
| echo " Version: ${{ steps.git_version.outputs.BUILD_VERSION }}" | |
| echo " Major: ${{ steps.git_version.outputs.BUILD_VERSION_MAJOR }}" | |
| echo " Minor: ${{ steps.git_version.outputs.BUILD_VERSION_MINOR }}" | |
| echo " Patch: ${{ steps.git_version.outputs.BUILD_VERSION_PATCH }}" | |
| echo " Build: ${{ steps.git_version.outputs.BUILD_VERSION_BUILD }}" | |
| echo " Tag: ${{ steps.git_version.outputs.BUILD_VERSION_TAG }}" | |
| echo " Branch: ${{ steps.git_version.outputs.BUILD_VERSION_BRANCH }}" | |
| echo " Commit: ${{ steps.git_version.outputs.BUILD_VERSION_COMMIT }}" | |
| echo " Short: ${{ steps.git_version.outputs.BUILD_VERSION_SHORT }}" | |
| echo " Full: ${{ steps.git_version.outputs.BUILD_VERSION_FULL }}" | |
| echo " Extended: ${{ steps.git_version.outputs.BUILD_VERSION_EXTENDED }}" | |
| echo " DefaultBranch: ${{ steps.git_version.outputs.BUILD_VERSION_DEFAULT_BRANCH }}" | |
| echo " ReleaseBranches: ${{ steps.git_version.outputs.BUILD_VERSION_RELEASE_BRANCHES }}" | |
| echo "═══════════════════════════════════════" | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v7.0.1 | |
| with: | |
| name: dist | |
| path: dist/ | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: package | |
| strategy: | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12", "3.13"] | |
| steps: | |
| - uses: actions/checkout@v6.0.3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v6.2.0 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install build tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build | |
| - name: Generate _version.py from git tags | |
| run: python tools/write_version.py | |
| - name: Build package | |
| run: python -m build | |
| - name: Install built package | |
| run: pip install dist/*.whl | |
| - name: Install test dependencies | |
| run: pip install pytest | |
| - name: Run tests from repo | |
| run: python -m pytest tests/ -v | |
| docker: | |
| runs-on: ubuntu-latest | |
| needs: package | |
| steps: | |
| - uses: actions/checkout@v6.0.3 | |
| - name: Download built package | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| - name: Build Docker image | |
| run: | | |
| docker build -t ghcr.io/synacker/git-version-utils:${{ needs.build.outputs.version }} \ | |
| --build-arg WHEEL=dist/*.whl . | |
| docker tag ghcr.io/synacker/git-version-utils:${{ needs.build.outputs.version }} \ | |
| ghcr.io/synacker/git-version-utils:latest | |
| - name: Show version info | |
| run: | | |
| docker run --rm \ | |
| -v "$(pwd):/workspace" -w /workspace \ | |
| ghcr.io/synacker/git-version-utils:latest \ | |
| git-version --safe-directory '*' --property env | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6.0.3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6.2.0 | |
| with: | |
| python-version: "3.13" | |
| - name: Install lint tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install ruff | |
| - name: Lint with ruff | |
| run: ruff check src/ tests/ |