Skip to content

Commit 59a5768

Browse files
committed
Prepare Main CD Python release
1 parent fb01604 commit 59a5768

File tree

5 files changed

+75
-232
lines changed

5 files changed

+75
-232
lines changed

.github/workflows/conda-index-lock-self-hosted.yml

Lines changed: 0 additions & 136 deletions
This file was deleted.

.github/workflows/conda-index-lock.yml

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,87 @@ concurrency:
3232
jobs:
3333
index:
3434
name: Index Conda Repository
35-
runs-on: ubuntu-latest
35+
runs-on: platform-builder-Debian-12
3636
steps:
3737
- name: Checkout repository
3838
uses: actions/checkout@v5
3939

40-
- name: Setup Conda
41-
uses: conda-incubator/setup-miniconda@v3
42-
with:
43-
auto-activate-base: true
44-
activate-environment: ""
40+
- name: Setup conda env dir
41+
shell: bash -el {0}
42+
run: |
43+
echo "CONDA_ENVS_DIRS=$RUNNER_TEMP/envs" >> "$GITHUB_ENV"
44+
mkdir -p "$RUNNER_TEMP/envs"
45+
46+
- name: Create conda environment
47+
shell: bash -el {0}
48+
run: |
49+
INDEX_ENV="conda-index-lock-${GITHUB_RUN_ID}"
50+
echo "INDEX_ENV=$INDEX_ENV" >> "$GITHUB_ENV"
51+
mamba env create -n "$INDEX_ENV"
4552
4653
- name: Install dependencies
4754
shell: bash -el {0}
4855
run: |
49-
conda install -y conda-index requests
56+
eval "$(conda shell.bash hook)"
57+
conda activate "$INDEX_ENV"
58+
mamba install -y conda-index requests
5059
5160
- name: Download artifacts from caller workflow
61+
shell: bash -el {0}
5262
env:
5363
GH_TOKEN: ${{ secrets.GH_REPO_READ_TOKEN }}
64+
REPO: ${{ inputs.caller_repo }}
65+
RUN_ID: ${{ inputs.caller_run_id }}
66+
ARTIFACT_NAME: ${{ inputs.package_artifact_name }}
5467
run: |
55-
echo "Downloading artifact '${{ inputs.package_artifact_name }}' from run ${{ inputs.caller_run_id }}"
56-
echo "Caller repository: ${{ inputs.caller_repo }}"
68+
eval "$(conda shell.bash hook)"
69+
conda activate "$INDEX_ENV"
70+
71+
echo "Downloading artifact '$ARTIFACT_NAME' from run $RUN_ID in $REPO"
72+
73+
python3 << 'EOF'
74+
import os
75+
import sys
76+
import zipfile
77+
import requests
5778
58-
# Download artifact from the calling workflow
59-
gh run download ${{ inputs.caller_run_id }} \
60-
--repo ${{ inputs.caller_repo }} \
61-
--name ${{ inputs.package_artifact_name }} \
62-
--dir ./packages
79+
repo = os.environ["REPO"]
80+
run_id = os.environ["RUN_ID"]
81+
artifact_name = os.environ["ARTIFACT_NAME"]
82+
token = os.environ["GH_TOKEN"]
83+
84+
# Get artifact list
85+
url = f"https://api.github.com/repos/{repo}/actions/runs/{run_id}/artifacts"
86+
headers = {"Authorization": f"Bearer {token}"}
87+
resp = requests.get(url, headers=headers)
88+
resp.raise_for_status()
89+
90+
# Find artifact ID
91+
artifact_id = None
92+
for artifact in resp.json()["artifacts"]:
93+
if artifact["name"] == artifact_name:
94+
artifact_id = artifact["id"]
95+
break
96+
97+
if not artifact_id:
98+
print(f"Artifact '{artifact_name}' not found", file=sys.stderr)
99+
sys.exit(1)
100+
101+
# Download artifact zip
102+
url = f"https://api.github.com/repos/{repo}/actions/artifacts/{artifact_id}/zip"
103+
resp = requests.get(url, headers=headers)
104+
resp.raise_for_status()
105+
106+
# Extract to ./packages
107+
os.makedirs("./packages", exist_ok=True)
108+
with open("/tmp/artifact.zip", "wb") as f:
109+
f.write(resp.content)
110+
with zipfile.ZipFile("/tmp/artifact.zip") as z:
111+
z.extractall("./packages")
112+
os.remove("/tmp/artifact.zip")
113+
114+
print("Downloaded and extracted artifact")
115+
EOF
63116
64117
echo "Downloaded packages:"
65118
find ./packages -name "*.tar.bz2" | sort
@@ -70,6 +123,9 @@ jobs:
70123
NEXUS_URL: ${{ inputs.nexus_url }}
71124
NEXUS_TOKEN: ${{ inputs.nexus_token }}
72125
run: |
126+
eval "$(conda shell.bash hook)"
127+
conda activate "$INDEX_ENV"
128+
73129
echo "Indexing packages to: $NEXUS_URL"
74130
75131
python "${{ github.workspace }}/cd-actions/python-conda/scripts/rebuild_conda_index.py" \

.github/workflows/main-cd.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ jobs:
140140

141141
- name: Build with Python Conda
142142
if: ${{ matrix.type == 'python-conda' }}
143-
uses: ecmwf/reusable-workflows/cd-actions/python-conda@cd-actions
143+
uses: ecmwf/reusable-workflows/cd-actions/python-conda@v2
144144
with:
145145
name: ${{ matrix.name }}
146146
config: ${{ matrix.config }}
@@ -153,7 +153,7 @@ jobs:
153153

154154
- name: Build with Python PyPI
155155
if: ${{ matrix.type == 'python-pypi' }}
156-
uses: ecmwf/reusable-workflows/cd-actions/python-pypi@cd-actions
156+
uses: ecmwf/reusable-workflows/cd-actions/python-pypi@v2
157157
with:
158158
name: ${{ matrix.name }}
159159
config: ${{ matrix.config }}
@@ -188,7 +188,7 @@ jobs:
188188
echo "EOF" >> $GITHUB_OUTPUT
189189
190190
- name: Create GitHub release
191-
uses: ecmwf/reusable-workflows/cd-actions/release@cd-actions
191+
uses: ecmwf/reusable-workflows/cd-actions/release@v2
192192
with:
193193
config: ${{ steps.prepare-config.outputs.config }}
194194
ref_name: ${{ inputs.ref_name }}

cd-actions/python-conda/action.yml

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -168,83 +168,6 @@ runs:
168168
find "$output_folder" -type f | head -20
169169
exit 1
170170
fi
171-
- name: Upload artifacts
172-
if: ${{ inputs.dry_run != 'true' }}
173-
shell: bash -el {0}
174-
run: |
175-
nexus_url="${{ steps.config.outputs.nexus_url }}"
176-
nexus_token="${{ steps.config.outputs.nexus_token }}"
177-
artifact_name="${{ github.run_id }}-${{ inputs.name }}"
178-
179-
echo "Acquiring conda index lock and uploading to Nexus: $nexus_url"
180-
echo "Artifact: $artifact_name"
181-
echo ""
182-
183-
# Run the lock acquisition script
184-
python3 "${{ github.action_path }}/scripts/acquire_lock.py" \
185-
--nexus-url "$nexus_url" \
186-
--nexus-token "$nexus_token" \
187-
--artifact-name "$artifact_name" \
188-
--caller-run-id "${{ github.run_id }}" \
189-
--caller-repo "${{ github.repository }}" \
190-
--gh-pat "${{ inputs.gh_pat }}"
191-
192-
echo ""
193-
echo "All packages and indexes uploaded to Nexus successfully!"
194-
195-
- name: Test package installation from Nexus
196-
if: ${{ inputs.dry_run != 'true' && inputs.skip_installation_test != 'true' }}
197-
shell: bash -el {0}
198-
run: |
199-
output_folder="${{ steps.config.outputs.output_folder }}"
200-
nexus_url="${{ steps.config.outputs.nexus_url }}"
201-
202-
echo "Testing package installation from Nexus..."
203-
204-
# Get package name and version from built packages
205-
packages=$(find "$output_folder" -name "*.tar.bz2" -type f)
206-
207-
for package in $packages; do
208-
package_name=$(basename "$package")
209-
echo ""
210-
echo "Testing installation of: $package_name"
211-
212-
# Extract package name without version/build info
213-
pkg_base=$(echo "$package_name" | sed 's/-.*//')
214-
215-
# Create a test environment
216-
test_env="test-install-${GITHUB_RUN_ID}-${RANDOM}"
217-
echo "Creating test environment: $test_env"
218-
219-
eval "$(conda shell.bash hook)"
220-
221-
# Create environment and install package from Nexus
222-
if mamba create -n "$test_env" -c "$nexus_url" -c conda-forge "$pkg_base" -y; then
223-
echo "✓ Successfully installed $pkg_base from Nexus"
224-
225-
# Verify package is installed
226-
conda activate "$test_env"
227-
if conda list | grep -q "$pkg_base"; then
228-
echo "✓ Package $pkg_base verified in environment"
229-
else
230-
echo "✗ Package $pkg_base not found in environment"
231-
conda deactivate
232-
conda env remove -n "$test_env" -y
233-
exit 1
234-
fi
235-
conda deactivate
236-
237-
# Clean up test environment
238-
conda env remove -n "$test_env" -y
239-
echo "Test environment removed"
240-
else
241-
echo "✗ Failed to install $pkg_base from Nexus"
242-
exit 1
243-
fi
244-
done
245-
246-
echo ""
247-
echo "All packages successfully installed from Nexus!"
248171
249172
- name: Upload artifacts
250173
uses: actions/upload-artifact@v4

cd-actions/python-conda/scripts/acquire_lock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Configuration
1313
LOCK_REPO = "ecmwf/reusable-workflows"
14-
LOCK_WORKFLOW = "conda-index-lock-self-hosted.yml"
14+
LOCK_WORKFLOW = "conda-index-lock.yml"
1515
MAX_WAIT = 1800 # 30 minutes
1616
POLL_INTERVAL = 10 # seconds
1717
GITHUB_API = "https://api.github.com"
@@ -68,7 +68,7 @@ def main():
6868
f"/repos/{LOCK_REPO}/actions/workflows/{LOCK_WORKFLOW}/dispatches",
6969
method="POST",
7070
data={
71-
"ref": "cd-actions",
71+
"ref": "v2",
7272
"inputs": {
7373
"nexus_url": args.nexus_url,
7474
"nexus_token": args.nexus_token,

0 commit comments

Comments
 (0)