Repository navigation
feat: select fastest install mirrors #38
Workflow file for this run
This file contains hidden or 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: Test dp1s.sh | |
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| branches: [ master ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| test-channel-args: | |
| name: Test channel args (${{ matrix.name }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: default | |
| rc: false | |
| conda_channel: conda-forge | |
| expected_channels: "--channel=conda-forge --channel=njzjz" | |
| - name: default RC | |
| rc: true | |
| conda_channel: conda-forge | |
| expected_channels: "--channel=conda-forge --channel=conda-forge/label/deepmd-kit_rc --channel=njzjz" | |
| - name: forced mirror | |
| rc: false | |
| conda_channel: https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ | |
| expected_channels: "--channel=https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ --channel=njzjz" | |
| - name: forced mirror RC | |
| rc: true | |
| conda_channel: https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ | |
| expected_channels: "--channel=https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ --channel=conda-forge/label/deepmd-kit_rc --channel=njzjz" | |
| env: | |
| DP1S_NO_PATH_UPDATE: 1 | |
| DP1S_CONDA_CHANNEL: ${{ matrix.conda_channel }} | |
| DP1S_PIXI_REPOURL: https://github.com/prefix-dev/pixi | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install mocks | |
| run: | | |
| set -euo pipefail | |
| mock_bin="${RUNNER_TEMP}/mock-bin" | |
| mkdir -p "${mock_bin}" | |
| cat > "${mock_bin}/curl" <<'EOF' | |
| #!/bin/sh | |
| cat <<'INSTALLER' | |
| #!/bin/sh | |
| set -eu | |
| mkdir -p "${PIXI_HOME}/bin" | |
| cat > "${PIXI_HOME}/bin/pixi" <<'PIXI' | |
| #!/bin/sh | |
| set -eu | |
| printf '%s\n' "$@" > "${DP1S_PIXI_ARGS_FILE}" | |
| mkdir -p "${PIXI_HOME}/bin" | |
| cat > "${PIXI_HOME}/bin/dp" <<'DP' | |
| #!/bin/sh | |
| echo "DeepMD-kit mock" | |
| DP | |
| chmod +x "${PIXI_HOME}/bin/dp" | |
| cat > "${PIXI_HOME}/bin/lmp" <<'LMP' | |
| #!/bin/sh | |
| echo "pair deepmd" | |
| LMP | |
| chmod +x "${PIXI_HOME}/bin/lmp" | |
| cat > "${PIXI_HOME}/bin/mpirun" <<'MPIRUN' | |
| #!/bin/sh | |
| echo "mpirun mock" | |
| MPIRUN | |
| chmod +x "${PIXI_HOME}/bin/mpirun" | |
| PIXI | |
| chmod +x "${PIXI_HOME}/bin/pixi" | |
| INSTALLER | |
| EOF | |
| chmod +x "${mock_bin}/curl" | |
| echo "${mock_bin}" >> "${GITHUB_PATH}" | |
| - name: Run script with mocked installer | |
| run: | | |
| set -euo pipefail | |
| export DP1S_HOME="${RUNNER_TEMP}/dp1s" | |
| export DP1S_PIXI_ARGS_FILE="${RUNNER_TEMP}/pixi-args.txt" | |
| if [[ "${{ matrix.rc }}" == "true" ]]; then | |
| export DP1S_DEEPMD_RC=1 | |
| fi | |
| bash dp1s.sh | |
| actual_channels=$(grep '^--channel=' "${DP1S_PIXI_ARGS_FILE}" | tr '\n' ' ' | sed 's/ $//') | |
| expected_channels='${{ matrix.expected_channels }}' | |
| if [[ "${actual_channels}" != "${expected_channels}" ]]; then | |
| echo "Expected channels: ${expected_channels}" | |
| echo "Actual channels: ${actual_channels}" | |
| exit 1 | |
| fi | |
| test-auto-mirror: | |
| name: Test automatic mirror selection | |
| runs-on: ubuntu-latest | |
| env: | |
| DP1S_NO_PATH_UPDATE: 1 | |
| DP1S_CONDA_MIRRORS: https://conda-slow.example/repo,https://conda-fast.example/repo | |
| DP1S_PIXI_MIRRORS: https://pixi-slow.example/repo,https://pixi-fast.example/repo | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install mocks | |
| run: | | |
| set -euo pipefail | |
| mock_bin="${RUNNER_TEMP}/mock-bin" | |
| mkdir -p "${mock_bin}" | |
| cat > "${mock_bin}/curl" <<'EOF' | |
| #!/bin/sh | |
| url="" | |
| while [ "$#" -gt 0 ]; do | |
| case "$1" in | |
| http://*|https://*) url="$1" ;; | |
| esac | |
| shift | |
| done | |
| case "$url" in | |
| https://conda-slow.example/*current_repodata.json) | |
| sleep 1 | |
| printf '1.000' | |
| exit 0 | |
| ;; | |
| https://conda-fast.example/*current_repodata.json) | |
| printf '0.100' | |
| exit 0 | |
| ;; | |
| https://pixi-slow.example/*releases/latest) | |
| sleep 1 | |
| printf '1.000' | |
| exit 0 | |
| ;; | |
| https://pixi-fast.example/*releases/latest) | |
| printf '0.200' | |
| exit 0 | |
| ;; | |
| https://pixi.sh/install.sh) | |
| cat <<'INSTALLER' | |
| #!/bin/sh | |
| set -eu | |
| mkdir -p "${PIXI_HOME}/bin" | |
| printf '%s\n' "${PIXI_REPOURL:-}" > "${DP1S_PIXI_REPO_FILE}" | |
| cat > "${PIXI_HOME}/bin/pixi" <<'PIXI' | |
| #!/bin/sh | |
| set -eu | |
| printf '%s\n' "$@" > "${DP1S_PIXI_ARGS_FILE}" | |
| mkdir -p "${PIXI_HOME}/bin" | |
| cat > "${PIXI_HOME}/bin/dp" <<'DP' | |
| #!/bin/sh | |
| echo "DeepMD-kit mock" | |
| DP | |
| chmod +x "${PIXI_HOME}/bin/dp" | |
| cat > "${PIXI_HOME}/bin/lmp" <<'LMP' | |
| #!/bin/sh | |
| echo "pair deepmd" | |
| LMP | |
| chmod +x "${PIXI_HOME}/bin/lmp" | |
| cat > "${PIXI_HOME}/bin/mpirun" <<'MPIRUN' | |
| #!/bin/sh | |
| echo "mpirun mock" | |
| MPIRUN | |
| chmod +x "${PIXI_HOME}/bin/mpirun" | |
| PIXI | |
| chmod +x "${PIXI_HOME}/bin/pixi" | |
| INSTALLER | |
| exit 0 | |
| ;; | |
| *) | |
| exit 1 | |
| ;; | |
| esac | |
| EOF | |
| chmod +x "${mock_bin}/curl" | |
| echo "${mock_bin}" >> "${GITHUB_PATH}" | |
| - name: Run script with mocked mirror probes | |
| run: | | |
| set -euo pipefail | |
| export DP1S_HOME="${RUNNER_TEMP}/dp1s" | |
| export DP1S_PIXI_ARGS_FILE="${RUNNER_TEMP}/pixi-args.txt" | |
| export DP1S_PIXI_REPO_FILE="${RUNNER_TEMP}/pixi-repo.txt" | |
| bash dp1s.sh 2>&1 | tee "${RUNNER_TEMP}/dp1s-output.txt" | |
| actual_channels=$(grep '^--channel=' "${DP1S_PIXI_ARGS_FILE}" | tr '\n' ' ' | sed 's/ $//') | |
| expected_channels='--channel=https://conda-fast.example/repo --channel=njzjz' | |
| if [[ "${actual_channels}" != "${expected_channels}" ]]; then | |
| echo "Expected channels: ${expected_channels}" | |
| echo "Actual channels: ${actual_channels}" | |
| exit 1 | |
| fi | |
| actual_pixi_repo=$(cat "${DP1S_PIXI_REPO_FILE}") | |
| if [[ "${actual_pixi_repo}" != "https://pixi-fast.example/repo" ]]; then | |
| echo "Expected pixi repo: https://pixi-fast.example/repo" | |
| echo "Actual pixi repo: ${actual_pixi_repo}" | |
| exit 1 | |
| fi | |
| grep -q 'Use fastest conda channel: https://conda-fast.example/repo (https://conda-fast.example/repo, 0.100s)' "${RUNNER_TEMP}/dp1s-output.txt" | |
| grep -q 'Use fastest pixi repo: https://pixi-fast.example/repo (https://pixi-fast.example/repo, 0.200s)' "${RUNNER_TEMP}/dp1s-output.txt" | |
| ! grep -q 'conda-slow.example' "${RUNNER_TEMP}/dp1s-output.txt" | |
| ! grep -q 'pixi-slow.example' "${RUNNER_TEMP}/dp1s-output.txt" | |
| test -f "${DP1S_HOME}/cache/mirror-choice" | |
| test: | |
| name: Test dp1s.sh (${{ matrix.name }}) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Run script | |
| run: bash dp1s.sh |