name: Update locked envs on: push: paths: - envs/environment.yaml - pixi.toml schedule: - cron: "0 8 1,16 * *" # Bi-weekly workflow_dispatch: env: BASE_ENV: envs/environment.yaml jobs: update-locked-environment: if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }} name: Update pinned envs runs-on: ubuntu-latest defaults: run: shell: bash -l {0} steps: - uses: actions/checkout@v7 - name: Setup conda uses: conda-incubator/setup-miniconda@v4 with: miniforge-version: latest activate-environment: ${{ github.event.repository.name }} channel-priority: strict environment-file: ${{ env.BASE_ENV }} - name: Install conda-lock run: | conda install -c conda-forge conda-lock - name: Generate lockfiles for all platforms run: | conda-lock -f ${{ env.BASE_ENV }} \ -p linux-64 -p osx-64 -p win-64 -p osx-arm64 \ -k env --filename-template "envs/{platform}.lock" # Rename to .yaml extension for file in envs/*.lock.yml; do mv "$file" "${file%.yml}.yaml" done - name: Add SPDX headers to lock files run: | SPDX_HEADER="# SPDX-FileCopyrightText: PyPSA-Earth and PyPSA-Eur Authors\n#\n# SPDX-License-Identifier: CC0-1.0\n" # Add header to all generated lock files for file in envs/*.lock.yaml; do echo "Adding header to $file" echo -e "$SPDX_HEADER" | cat - "$file" > temp && mv temp "$file" done - name: Insert environment name in lock files run: | for file in envs/*.lock.yaml; do if [ -f "$file" ]; then echo "Processing $file" if ! grep -q "name: pypsa-earth" "$file"; then # Insert name: pypsa-earth before channels section sed -i '7a name: pypsa-earth' "$file" else echo "name: pypsa-earth already exists in $file" fi fi done - name: Upload conda lockfile artifacts uses: actions/upload-artifact@v7 with: name: lockfiles path: envs/*.lock.yaml - name: Update pixi.lock uses: prefix-dev/setup-pixi@v0.10.0 with: pixi-version: latest run-install: false - name: Run pixi update run: pixi update - name: Upload pixi lockfile artifact uses: actions/upload-artifact@v7 with: name: pixi-lockfile path: pixi.lock create-pull-request: needs: update-locked-environment runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - name: Download conda lockfile artifacts uses: actions/download-artifact@v8 with: name: lockfiles path: envs/ - name: Download pixi lockfile artifact uses: actions/download-artifact@v8 with: name: pixi-lockfile path: . - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.GITHUB_TOKEN }} branch: update-locked-environment title: "[github-actions.ci] Update locked envs" body: | Automatically generated PR to update locked environment files for Windows, macOS, and Linux. These files were generated using conda-lock for improved dependency resolution and reproducibility. The `pixi.lock` file was also updated using `pixi update` to keep both package managers in sync. **Note: Check before merging this PR that the updated environment are tested by choosing one of the following options: (1) by performing a local testing or (2) by checking that the locked files are used in the CI. Note that the CI log has the step `Use base env file if it was changed` that reports what environment has been used for the run.** commit-message: "Update locked environment files for all platforms"