Restore environment (#1048) #21
This file contains 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: Update pinned envs | |
on: | |
push: | |
paths: | |
- envs/environment.yaml | |
# Run every Sunday at 5:00 UTC | |
schedule: | |
- cron: "0 5 * * 0" | |
workflow_dispatch: | |
jobs: | |
update-pinned-environment: | |
# the update is always needed for env changes in main and sometimes for other branches | |
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }} | |
name: Update pinned envs | |
runs-on: ${{ matrix.os }}-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu, macos, windows] | |
include: | |
- os: ubuntu | |
suffix: "linux" | |
- os: macos | |
suffix: "macos" | |
- os: windows | |
suffix: "windows" | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup conda | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
activate-environment: ${{ github.event.repository.name }} | |
environment-file: envs/environment.yaml | |
- name: Update pinned environment per OS | |
run: | | |
conda env export --name ${{ github.event.repository.name }} --no-builds > envs/${{ matrix.suffix }}-pinned.yaml | |
- name: Add SPDX header | |
if: ${{ matrix.suffix != 'windows' }} | |
run: | | |
SPDX_HEADER="# SPDX-FileCopyrightText: PyPSA-Earth and PyPSA-Eur Authors\n#\n# SPDX-License-Identifier: CC0-1.0\n" | |
echo -e "$SPDX_HEADER" | cat - envs/${{ matrix.suffix }}-pinned.yaml > temp && mv temp envs/${{ matrix.suffix }}-pinned.yaml | |
- name: Add SPDX header (windows) | |
if: ${{ matrix.suffix == 'windows' }} | |
run: | | |
$SPDX_HEADER = "# SPDX-FileCopyrightText: PyPSA-Earth and PyPSA-Eur`r`n#`r`n# SPDX-License-Identifier: CC0-1.0`r`n`r`n" | |
$CurrentContent = Get-Content "envs/${{ matrix.suffix }}-pinned.yaml" -Raw | |
$NewContent = $SPDX_HEADER + $CurrentContent | |
$NewContent | Set-Content "envs/${{ matrix.suffix }}-pinned.yaml" | |
- name: Cache environment files | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.suffix }}-pinned | |
path: envs/${{ matrix.suffix }}-pinned.yaml | |
create-pull-request: | |
needs: update-pinned-environment | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
- name: Prepare files for commit | |
run: | | |
mkdir -p envs | |
mv linux-pinned/* envs/linux-pinned.yaml | |
mv macos-pinned/* envs/macos-pinned.yaml | |
mv windows-pinned/* envs/windows-pinned.yaml | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
branch: update-pinned-environment | |
title: "[github-actions.ci] Update pinned envs" | |
body: "Automatically generated PR to update pinned environment files for Windows, macOS, and Linux." | |
commit-message: "Update pinned environment files for all platforms" |