Merge pull request #28 from lsst/tickets/DM-53958 #120
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_and_test | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - "u/**" | |
| tags: | |
| - "*" | |
| pull_request: | |
| jobs: | |
| build_and_test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.11", "3.12"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # Need to clone everything for the git tags. | |
| fetch-depth: 0 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| version: "0.5.x" | |
| enable-cache: true | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| uv sync | |
| - name: Run tests | |
| run: >- | |
| uv run pytest -r a -v | |
| check-changes: | |
| outputs: | |
| skip: ${{ steps.check.outputs.skip }} | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/') | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if weekly changed | |
| id: check | |
| run: | | |
| # Get SHA hashes for most recent weekly tags | |
| weekly_sha=$(git tag -l 'w.*' | while read tag; do | |
| git rev-list -n 1 "${tag}" | |
| done) | |
| echo "Weekly tag SHA ${weekly_sha}" | |
| # Extract the current tag and its SHA | |
| current_tag=${GITHUB_REF#refs/tags/} | |
| echo "Current tag: ${current_tag}" | |
| current_sha=$(git rev-list -1 "${current_tag}") || echo "no_value" | |
| echo "Current sha: ${current_sha}" | |
| # Count occurrences of the current SHA in the weekly SHA list | |
| n=$(echo "${weekly_sha}" | grep -c "${current_sha}") || echo "0" | |
| echo "Current tag ${current_tag} (${current_sha}) SHA found ${n} time(s)" | |
| # Determine whether to skip the upload based on the count | |
| if [ "${n}" -gt 1 ]; then | |
| echo "Skip upload" | |
| echo "skip=true" >> "${GITHUB_OUTPUT}" | |
| else | |
| echo "Enable upload" | |
| echo "skip=false" >> "${GITHUB_OUTPUT}" | |
| fi | |
| pypi: | |
| runs-on: ubuntu-latest | |
| needs: [build_and_test, check-changes] | |
| permissions: | |
| id-token: write | |
| if: "${{ ! startsWith(github.ref, 'refs/tags/w.') || needs.check-changes.outputs.skip == 'false' }}" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # Need to clone everything to embed the version. | |
| fetch-depth: 0 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| version: "0.5.x" | |
| enable-cache: true | |
| python-version: "3.11" | |
| - name: Build and create distribution | |
| run: | | |
| uv build | |
| - name: Upload | |
| uses: pypa/gh-action-pypi-publish@release/v1 |