Merge pull request #57 from lsst/tickets/DM-54017 #8
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 | |
| tags: | |
| - "*" | |
| pull_request: | |
| jobs: | |
| build_and_test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.12", "3.13", "3.14"] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| # Need to clone everything to determine version from git. | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| pip install --upgrade pip | |
| pip install pytest fastavro lsst-resources | |
| - name: Build and install | |
| run: pip install --no-deps -v -e . | |
| - name: Run tests | |
| run: pytest test | |
| check-changes: | |
| outputs: | |
| skip: ${{ steps.check.outputs.skip }} | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/') | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if weekly changed | |
| id: check | |
| run: | | |
| # Get SHA hashes for all 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@v6 | |
| with: | |
| # Need to clone everything to embed the version. | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install --upgrade setuptools wheel build | |
| - name: Build and create distribution | |
| run: python -m build --skip-dependency-check | |
| - name: Upload | |
| uses: pypa/gh-action-pypi-publish@release/v1 |