Skip to content

Auto Bioconda PR with Test & meta.yaml generation (Manual Only) #18

Auto Bioconda PR with Test & meta.yaml generation (Manual Only)

Auto Bioconda PR with Test & meta.yaml generation (Manual Only) #18

name: Auto Bioconda PR with Test & meta.yaml generation (Manual Only)
on:
workflow_dispatch:
jobs:
bioconda_pr:
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v3
- name: Set GH_PAT as env var
run: echo "GH_PAT=${{ secrets.GH_PAT }}" >> $GITHUB_ENV
- name: Extract version and package name using ast
id: vars
run: |
set -e
INIT_PATH=$(find . -type f -name '__init__.py' | head -n1)
echo "📄 Found __init__.py at: $INIT_PATH"
echo 'import ast' > get_version.py
echo 'with open("'$INIT_PATH'") as f:' >> get_version.py
echo ' tree = ast.parse(f.read())' >> get_version.py
echo 'for node in ast.walk(tree):' >> get_version.py
echo ' if isinstance(node, ast.Assign):' >> get_version.py
echo ' if getattr(node.targets[0], "id", None) == "__version__":' >> get_version.py
echo ' print(node.value.s)' >> get_version.py
echo ' break' >> get_version.py
VERSION=$(python3 get_version.py)
PACKAGE=$(basename $(dirname "$INIT_PATH"))
if [ -z "$VERSION" ]; then
echo "❌ __version__ not found in $INIT_PATH"
cat "$INIT_PATH"
exit 1
fi
echo "📦 PACKAGE: $PACKAGE"
echo "📌 VERSION: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "PACKAGE=$PACKAGE" >> $GITHUB_ENV
- name: Generate meta.yaml in recipes/${PACKAGE}
run: |
mkdir -p recipes/${PACKAGE}
SUMMARY=$(awk '
found && NF {
line = $0
gsub(/!\[[^]]*\]\([^)]*\)/, "", line)
gsub(/\[[^]]+\]\([^)]*\)/, "", line)
gsub(/\*\*/, "", line)
gsub(/__/, "", line)
gsub(/^[ \t*-]+/, "", line)
gsub(/"/, "\\\"", line)
print line; exit
}
/^##[ \t]+Overview/ { found = 1 }
' README.md)
echo "{% set name = \"${PACKAGE}\" %}" > recipes/${PACKAGE}/meta.yaml
echo "{% set version = \"${VERSION}\" %}" >> recipes/${PACKAGE}/meta.yaml
echo "" >> recipes/${PACKAGE}/meta.yaml
echo "package:" >> recipes/${PACKAGE}/meta.yaml
echo " name: \"{{ name|lower }}\"" >> recipes/${PACKAGE}/meta.yaml
echo " version: \"{{ version }}\"" >> recipes/${PACKAGE}/meta.yaml
echo "" >> recipes/${PACKAGE}/meta.yaml
echo "source:" >> recipes/${PACKAGE}/meta.yaml
echo " url: https://github.com/kamome1201/${PACKAGE}/archive/refs/tags/v{{ version }}.tar.gz" >> recipes/${PACKAGE}/meta.yaml
echo " sha256: \"TO_BE_REPLACED\"" >> recipes/${PACKAGE}/meta.yaml
echo "" >> recipes/${PACKAGE}/meta.yaml
echo "build:" >> recipes/${PACKAGE}/meta.yaml
echo " number: 0" >> recipes/${PACKAGE}/meta.yaml
echo " noarch: python" >> recipes/${PACKAGE}/meta.yaml
echo " script: \"{{ PYTHON }} -m pip install . -vv --ignore-installed --no-deps\"" >> recipes/${PACKAGE}/meta.yaml
echo "" >> recipes/${PACKAGE}/meta.yaml
echo "requirements:" >> recipes/${PACKAGE}/meta.yaml
echo " host:" >> recipes/${PACKAGE}/meta.yaml
echo " - python >=3.8" >> recipes/${PACKAGE}/meta.yaml
echo " - pip" >> recipes/${PACKAGE}/meta.yaml
echo " - setuptools" >> recipes/${PACKAGE}/meta.yaml
echo " - wheel" >> recipes/${PACKAGE}/meta.yaml
echo " run:" >> recipes/${PACKAGE}/meta.yaml
echo " - python >=3.8" >> recipes/${PACKAGE}/meta.yaml
echo "" >> recipes/${PACKAGE}/meta.yaml
echo "test:" >> recipes/${PACKAGE}/meta.yaml
echo " imports:" >> recipes/${PACKAGE}/meta.yaml
echo " - ${PACKAGE}" >> recipes/${PACKAGE}/meta.yaml
echo "" >> recipes/${PACKAGE}/meta.yaml
echo "about:" >> recipes/${PACKAGE}/meta.yaml
echo " home: \"https://github.com/kfuku52/${PACKAGE}\"" >> recipes/${PACKAGE}/meta.yaml
echo " license: \"BSD-3-Clause\"" >> recipes/${PACKAGE}/meta.yaml
echo " license_file: \"LICENSE\"" >> recipes/${PACKAGE}/meta.yaml
echo " summary: \"${SUMMARY}\"" >> recipes/${PACKAGE}/meta.yaml
- name: Download source archive and compute SHA256
run: |
url="https://github.com/kamome1201/${PACKAGE}/archive/refs/tags/v${VERSION}.tar.gz"
wget -O source.tar.gz "$url"
sha256=$(sha256sum source.tar.gz | awk '{print $1}')
echo "SHA256=$sha256" >> $GITHUB_ENV
- name: Clone your fork of bioconda-recipes
run: |
git clone https://github.com/kamome1201/bioconda-recipes.git
cd bioconda-recipes
git remote add upstream https://github.com/bioconda/bioconda-recipes.git
git fetch upstream
git checkout -B add-${PACKAGE}-${VERSION} upstream/master
- name: Copy recipe into bioconda-recipes
run: |
cp -r recipes/${PACKAGE} bioconda-recipes/recipes/
- name: Replace sha256 in meta.yaml
run: |
sed -i "s/sha256: .*/sha256: \"${SHA256}\"/" bioconda-recipes/recipes/${PACKAGE}/meta.yaml
- name: Create config.yml and conda_build_config.yaml
run: |
echo "channels:" > bioconda-recipes/config.yml
echo " - bioconda" >> bioconda-recipes/config.yml
echo " - conda-forge" >> bioconda-recipes/config.yml
echo " - defaults" >> bioconda-recipes/config.yml
echo "conda_build_config: conda_build_config.yaml" >> bioconda-recipes/config.yml
touch bioconda-recipes/conda_build_config.yaml
- name: Show config.yml and conda_build_config.yaml
run: |
cat bioconda-recipes/config.yml
echo "---"
cat bioconda-recipes/conda_build_config.yaml
- name: Set authenticated remote URL
run: |
cd bioconda-recipes
git remote set-url origin https://x-access-token:[email protected]/kamome1201/bioconda-recipes.git
- name: Commit and push
run: |
cd bioconda-recipes
git config user.name "github-actions"
git config user.email "[email protected]"
git add recipes/${PACKAGE}
git commit -m "Add ${PACKAGE} v${VERSION} [auto-generated]"
git push --force origin add-${PACKAGE}-${VERSION}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GH_PAT }}
title: "Add ${{ env.PACKAGE }} recipe"
commit-message: "Auto PR: ${{ env.PACKAGE }} ${{ env.VERSION }}"
base: master
branch: add-${{ env.PACKAGE }}-${{ env.VERSION }}
body: |
This PR was automatically generated by GitHub Actions.
- **Package**: `${{ env.PACKAGE }}`
- **Version**: `${{ env.VERSION }}`
- **SHA256**: `${{ env.SHA256 }}`
----
Please read the [guidelines for Bioconda recipes](https://bioconda.github.io/contributor/guidelines.html) before opening a pull request (PR).
### General instructions
* If this PR adds or updates a recipe, use "Add" or "Update" appropriately as the first word in its title.
* New recipes not directly relevant to the biological sciences need to be submitted to the [conda-forge channel](https://conda-forge.org/docs/) instead of Bioconda.
* PRs require reviews prior to being merged. Once your PR is passing tests and ready to be merged, please issue the `@BiocondaBot please add label` command.
* Please post questions [on Gitter](https://gitter.im/bioconda/Lobby) or ping `@bioconda/core` in a comment.
### Instructions for avoiding API, ABI, and CLI breakage issues
Conda is able to record and lock (a.k.a. pin) dependency versions used at build time of other recipes.
This way, one can avoid that expectations of a downstream recipe with regards to API, ABI, or CLI are violated by later changes in the recipe.
If not already present in the meta.yaml, make sure to specify `run_exports` (see [here](https://bioconda.github.io/contributor/linting.html#missing-run-exports) for the rationale and comprehensive explanation).
Add a `run_exports` section like this:
```yaml
build:
run_exports:
- ...