Update conda CI #15
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: Bump conda-forge feedstock | ||
| on: | ||
| release: | ||
| types: [published] | ||
| workflow_dispatch: {} | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| env: | ||
| PACKAGE_NAME: biapy | ||
| GH_TOKEN: ${{ secrets.CF_GH_TOKEN }} | ||
| FEEDSTOCK_FORK: ${{ secrets.CF_FEEDSTOCK_FORK }} | ||
| jobs: | ||
| bump-feedstock: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check out this repo | ||
| uses: actions/checkout@v4 | ||
| - name: Determine version from release tag (fallback to PyPI latest on manual run) | ||
| id: ver | ||
| shell: bash | ||
| run: | | ||
| if [ "${{ github.event_name }}" = "release" ]; then | ||
| RAW_TAG="${{ github.event.release.tag_name }}" | ||
| VERSION="${RAW_TAG#v}" | ||
| else | ||
| VERSION="$(python -c "import json,urllib.request;print(json.load(urllib.request.urlopen('https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json'))['info']['version'])")" | ||
| fi | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| - name: Fetch PyPI sdist URL and SHA256 (with short retry to avoid race) | ||
| id: sdist | ||
| shell: bash | ||
| env: | ||
| VERSION: ${{ steps.ver.outputs.version }} | ||
| run: | | ||
| PYPI_JSON="https://pypi.org/pypi/${PACKAGE_NAME}/${VERSION}/json" | ||
| OUT=$(python -c "import json,urllib.request,hashlib,os; d=json.load(urllib.request.urlopen('${PYPI_JSON}')); sd=[u for u in d['urls'] if u.get('packagetype')=='sdist']; u=sd[0]['url'] if sd else (_ for _ in ()).throw(SystemExit(1)); h=hashlib.sha256(urllib.request.urlopen(u).read()).hexdigest(); print(u); print(h)") | ||
| SDIST_URL="$(echo "$OUT" | sed -n '1p')" | ||
| SDIST_SHA256="$(echo "$OUT" | sed -n '2p')" | ||
| { | ||
| echo "sdist_url=$SDIST_URL" | ||
| echo "sha256=$SDIST_SHA256" | ||
| } >> "$GITHUB_OUTPUT" | ||
| - name: Set up conda (Miniforge) | ||
| uses: conda-incubator/setup-miniconda@v3 | ||
| with: | ||
| miniforge-version: latest | ||
| use-mamba: true | ||
| auto-activate-base: true | ||
| channels: conda-forge | ||
| - name: Create env for conda-smithy | ||
| run: mamba create -n cf -y conda-smithy ruamel.yaml | ||
| - name: Authenticate gh CLI | ||
| run: gh auth status | ||
| - name: Clone your feedstock fork | ||
| run: | | ||
| test -n "$FEEDSTOCK_FORK" | ||
| gh repo clone "$FEEDSTOCK_FORK" feedstock | ||
| cd feedstock | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| - name: Copy your meta.yaml into the feedstock | ||
| working-directory: feedstock | ||
| run: | | ||
| cp ../biapy/utils/env/conda_forge_meta.yaml recipe/meta.yaml | ||
| git add recipe/meta.yaml | ||
| git commit -m "Import project's conda_forge_meta.yaml as recipe/meta.yaml" | ||
| - name: Create bump branch and update version + sha256 | ||
| working-directory: feedstock | ||
| env: | ||
| VERSION: ${{ steps.ver.outputs.version }} | ||
| SDIST_SHA256: ${{ steps.sdist.outputs.sha256 }} | ||
| shell: bash | ||
| run: | | ||
| BRANCH="bump-v$VERSION" | ||
| git switch -c "$BRANCH" | ||
| # Update recipe/meta.yaml using Python (more robust than sed for Jinja) | ||
| python - <<'PY' | ||
| import os, re, pathlib, sys | ||
| p = pathlib.Path("recipe") / "meta.yaml" | ||
| s = p.read_text(encoding="utf-8") | ||
| ver = os.environ["VERSION"] | ||
| sha = os.environ["SDIST_SHA256"] | ||
| # Update Jinja version line like: {% set version = "X.Y.Z" %} | ||
| s, n1 = re.subn(r'{%\s*set\s+version\s*=\s*"[^"]+"\s*%}', | ||
| '{% set version = "' + ver + '" %}', s) | ||
| # Update sha256 under source: | ||
| s, n2 = re.subn(r'(sha256:\s*)([0-9a-fA-F]+)', r'\1' + sha, s) | ||
| p.write_text(s, encoding="utf-8") | ||
| print(f"updated version: {n1} match(es); updated sha256: {n2} match(es)") | ||
| if n1 == 0 or n2 == 0: | ||
| sys.exit("regex did not match expected lines in recipe/meta.yaml") | ||
| PY | ||
| git add recipe/meta.yaml | ||
| git commit -m "Bump to v$VERSION (update version and sha256)" | ||
| - name: name: (Optional) conda-smithy rerender | ||
| working-directory: feedstock | ||
| run: | | ||
| conda run -n cf conda-smithy rerender -c auto || true | ||
| if ! git diff --quiet; then | ||
| git add . | ||
| git commit -m "conda-smithy rerender" | ||
| fi | ||
| - name: Configure git auth for push | ||
| working-directory: feedstock | ||
| run: | | ||
| # Configure git to use gh's credential helper (respects GH_TOKEN) | ||
| gh auth setup-git | ||
| # Make sure "origin" uses a tokenized HTTPS URL | ||
| git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${FEEDSTOCK_FORK}.git" | ||
| - name: Push branch to your fork | ||
| working-directory: feedstock | ||
| run: git push --set-upstream origin HEAD | ||
| - name: Open PR to conda-forge feedstock | ||
| working-directory: feedstock | ||
| env: | ||
| VERSION: ${{ steps.ver.outputs.version }} | ||
| run: | | ||
| TITLE="biapy v$VERSION" | ||
| BODY="Automated bump to $VERSION after GitHub Release.\n\n- Recipe copied from project: \`biapy/utils/env/conda_forge_meta.yaml\`\n- Version and sha256 updated from PyPI sdist." | ||
| OWNER="${FEEDSTOCK_FORK%%/*}" | ||
| BRANCH="bump-v$VERSION" | ||
| gh pr create \ | ||
| --repo conda-forge/biapy-feedstock \ | ||
| --title "$TITLE" \ | ||
| --body "$BODY" \ | ||
| --head "${OWNER}:${BRANCH}" \ | ||
| --base "main" | ||