Skip to content

Conda Index Lock

Conda Index Lock #7

name: Conda Index Lock
on:
workflow_dispatch:
inputs:
nexus_url:
description: 'Nexus repository URL'
required: true
type: string
nexus_token:
description: 'Nexus authentication token (user:password)'
required: true
type: string
package_artifact_name:
description: 'Name of the artifact containing conda packages'
required: true
type: string
caller_run_id:
description: 'Run ID of the calling workflow'
required: true
type: string
caller_repo:
description: 'Repository that called this lock (owner/repo)'
required: true
type: string
# CRITICAL: Only one indexing operation at a time
concurrency:
group: conda-index-lock
cancel-in-progress: false
jobs:
index:
name: Index Conda Repository
runs-on: platform-builder-Debian-12
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Setup conda env dir
shell: bash -el {0}
run: |
echo "CONDA_ENVS_DIRS=$RUNNER_TEMP/envs" >> "$GITHUB_ENV"
mkdir -p "$RUNNER_TEMP/envs"
- name: Create conda environment
shell: bash -el {0}
run: |
INDEX_ENV="conda-index-lock-${GITHUB_RUN_ID}"
echo "INDEX_ENV=$INDEX_ENV" >> "$GITHUB_ENV"
mamba env create -n "$INDEX_ENV"
- name: Install dependencies
shell: bash -el {0}
run: |
eval "$(conda shell.bash hook)"
conda activate "$INDEX_ENV"
mamba install -y conda-index requests
- name: Download artifacts from caller workflow
shell: bash -el {0}
env:
GH_TOKEN: ${{ secrets.GH_REPO_READ_TOKEN }}
REPO: ${{ inputs.caller_repo }}
RUN_ID: ${{ inputs.caller_run_id }}
ARTIFACT_NAME: ${{ inputs.package_artifact_name }}
run: |
eval "$(conda shell.bash hook)"
conda activate "$INDEX_ENV"
echo "Downloading artifact '$ARTIFACT_NAME' from run $RUN_ID in $REPO"
python3 << 'EOF'
import os
import sys
import zipfile
import requests
repo = os.environ["REPO"]
run_id = os.environ["RUN_ID"]
artifact_name = os.environ["ARTIFACT_NAME"]
token = os.environ["GH_TOKEN"]
# Get artifact list
url = f"https://api.github.com/repos/{repo}/actions/runs/{run_id}/artifacts"
headers = {"Authorization": f"Bearer {token}"}
resp = requests.get(url, headers=headers)
resp.raise_for_status()
# Find artifact ID
artifact_id = None
for artifact in resp.json()["artifacts"]:
if artifact["name"] == artifact_name:
artifact_id = artifact["id"]
break
if not artifact_id:
print(f"Artifact '{artifact_name}' not found", file=sys.stderr)
sys.exit(1)
# Download artifact zip
url = f"https://api.github.com/repos/{repo}/actions/artifacts/{artifact_id}/zip"
resp = requests.get(url, headers=headers)
resp.raise_for_status()
# Extract to ./packages
os.makedirs("./packages", exist_ok=True)
with open("/tmp/artifact.zip", "wb") as f:
f.write(resp.content)
with zipfile.ZipFile("/tmp/artifact.zip") as z:
z.extractall("./packages")
os.remove("/tmp/artifact.zip")
print("Downloaded and extracted artifact")
EOF
echo "Downloaded packages:"
find ./packages -name "*.tar.bz2" | sort
- name: Rebuild conda index
shell: bash -el {0}
env:
NEXUS_URL: ${{ inputs.nexus_url }}
NEXUS_TOKEN: ${{ inputs.nexus_token }}
run: |
eval "$(conda shell.bash hook)"
conda activate "$INDEX_ENV"
echo "Indexing packages to: $NEXUS_URL"
python "${{ github.workspace }}/cd-actions/python-conda/scripts/rebuild_conda_index.py" \
--package-dir ./packages \
--nexus-url "$NEXUS_URL" \
--nexus-token "$NEXUS_TOKEN"
echo "Indexing completed successfully!"