ci-locks #119
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
# Reference: | |
# - https://github.com/actions/cache | |
# - https://github.com/actions/checkout | |
# - https://github.com/actions/download-artifact | |
# - https://github.com/actions/upload-artifact | |
# - https://github.com/conda-incubator/setup-miniconda | |
name: ci-locks | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "3 0 * * 1" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build-locks: | |
name: "Build ${{ matrix.lock }}" | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash -l {0} | |
env: | |
ENV_NAME: "ci-locks" | |
strategy: | |
matrix: | |
lock: [py39-lock, py310-lock, py311-lock] | |
steps: | |
- name: "Checkout" | |
uses: actions/checkout@v4 | |
- name: "Environment configure" | |
env: | |
# Maximum cache period (in weeks) before forcing a cache refresh. | |
CACHE_WEEKS: 2 | |
run: | | |
echo "CACHE_PERIOD=$(date +%Y).$(expr $(date +%U) / ${CACHE_WEEKS})" >> ${GITHUB_ENV} | |
- name: "Conda package cache" | |
uses: actions/[email protected] | |
env: | |
# Increment the build number to force a cache refresh. | |
CACHE_BUILD: 2 | |
with: | |
path: ~/conda_pkgs_dir | |
key: ${{ runner.os }}-conda-pkgs-${{ env.ENV_NAME }}-p${{ env.CACHE_PERIOD }}-b${{ env.CACHE_BUILD }} | |
- name: "Conda install" | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
miniforge-version: latest | |
channels: conda-forge,defaults | |
activate-environment: ${{ env.ENV_NAME }} | |
auto-update-conda: true | |
use-only-tar-bz2: true | |
- name: "Conda environment cache" | |
id: conda-env-cache | |
uses: actions/[email protected] | |
env: | |
# Increment the build number to force a cache refresh. | |
CACHE_BUILD: 2 | |
with: | |
path: ${{ env.CONDA }}/envs/${{ env.ENV_NAME }} | |
key: ${{ runner.os }}-conda-env-${{ env.ENV_NAME }}-p${{ env.CACHE_PERIOD }}-b${{ env.CACHE_BUILD }} | |
- name: "Conda environment update" | |
if: steps.conda-env-cache.outputs.cache-hit != 'true' | |
run: | | |
conda install --name ${{ env.ENV_NAME }} "tox<4" | |
- name: "Conda info" | |
run: | | |
conda info | |
conda list | |
- name: "Tox cache" | |
uses: actions/[email protected] | |
env: | |
# Increment the build number to forece a cache refresh. | |
CACHE_BUILD: 2 | |
TOX_INI: ${{ github.workspace }}/tox.ini | |
with: | |
path: ${{ github.workspace }}/.tox | |
key: ${{ runner.os }}-tox-${{ env.ENV_NAME }}-${{ matrix.lock }}-p${{ env.CACHE_PERIOD }}-b${{ env.CACHE_BUILD }}-${{ hashFiles(env.TOX_INI) }} | |
- name: "Create ${{ matrix.lock }} conda locks" | |
run: | | |
tox -e ${{ matrix.lock }} -- --platform osx-64 --platform win-64 | |
- name: "Upload lock artifacts" | |
uses: actions/upload-artifact@v3 | |
with: | |
name: lock-artifacts | |
path: ${{ github.workspace }}/requirements/locks/${{ matrix.lock }}*.txt | |
create-pr: | |
needs: build-locks | |
name: "Create pull-request" | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Checkout" | |
uses: actions/checkout@v4 | |
- name: "Download lock artifacts" | |
uses: actions/download-artifact@v3 | |
with: | |
name: lock-artifacts | |
path: ${{ github.workspace }}/requirements/locks | |
- name: "Generate token" | |
uses: tibdex/github-app-token@v2 | |
id: generate-token | |
with: | |
app_id: ${{ secrets.AUTH_APP_ID }} | |
private_key: ${{ secrets.AUTH_APP_PRIVATE_KEY }} | |
- name: "Push pull-request" | |
id: cpr | |
# v3.12.1 (release date 31 Jan 2022) | |
uses: peter-evans/create-pull-request@9153d834b60caba6d51c9b9510b087acf9f33f83 | |
with: | |
token: ${{ steps.generate-token.outputs.token }} | |
add-paths: ${{ github.workspace }}/requirements/locks/*.txt | |
commit-message: "updated conda lock files" | |
branch: conda-lock-auto-update | |
delete-branch: true | |
title: "[cf-units.ci] conda lock auto-update" | |
body: | | |
Conda lock files auto-updated to latest resolved environment for `cf-units` dependencies. | |
labels: | | |
New: Pull Request | |
Bot | |
- name: "Show pull-request" | |
if: steps.cpr.outputs.pull-request-number != '' | |
run: | | |
echo "pull-request #${{ steps.cpr.outputs.pull-request-number }}" | |
echo "pull-request URL ${{ steps.cpr.outputs.pull-request-url }}" | |
echo "pull-request operation [${{ steps.cpr.outputs.pull-request-operation }}]" | |
echo "pull-request SHA ${{ steps.cpr.outputs.pull-request-head-sha }}" |