Limit caching concurrency for climsim recipe #178
Workflow file for this run
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: Deploy recipes | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
types: [opened, reopened, synchronize, labeled] | |
jobs: | |
deploy-recipes: | |
name: deploy-recipes | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v3 | |
- name: "Authenticate to Google Cloud" | |
id: "auth" | |
uses: "google-github-actions/auth@v1" | |
with: | |
credentials_json: "${{ secrets.GCP_DATAFLOW_SERVICE_KEY }}" | |
- name: "Set prune config based on github event type" | |
run: > | |
if ${{ github.event_name == 'pull_request' }}; then | |
echo prune=true >> $GITHUB_ENV | |
else | |
echo prune=false >> $GITHUB_ENV | |
fi | |
- name: "Set max_num_workers based on PR label if present" | |
# This is a little complicated, but the only way I know to retrieve labels on both | |
# `pull_request` *and* `push` events (and we want the ability to do so in both cases). | |
# Adapted from the following (note question in comment there re: external prs): | |
# https://github.com/pangeo-forge/deploy-recipe-action/blob/256da2916b5f17f358c5e5b0442458645cadb9f0/action/deploy_recipe.py#L34-L68 | |
shell: python3 {0} | |
run: | | |
import json | |
import os | |
import urllib.request | |
repository = os.environ["GITHUB_REPOSITORY"] | |
api_url = os.environ["GITHUB_API_URL"] | |
head_ref = os.environ["GITHUB_HEAD_REF"] | |
sha = os.environ["GITHUB_SHA"] | |
commit_sha = head_ref if head_ref else sha | |
pulls_url = "/".join([api_url, "repos", repository, "commits", commit_sha, "pulls"]) | |
pulls_txt = urllib.request.urlopen(pulls_url).read() | |
pulls_json = json.loads(pulls_txt) | |
labels = [label["name"] for label in pulls_json[0]["labels"]] | |
max_num_workers = [l.split(":")[-1] for l in labels if l.startswith("max_num_workers:")] | |
max_num_workers = (max_num_workers[0] if max_num_workers else "1000") | |
with open(os.environ["GITHUB_ENV"], mode="a") as f: | |
f.write(f"max_num_workers={max_num_workers}") | |
- name: "Deploy recipes" | |
uses: "pangeo-forge/deploy-recipe-action@v0.1" | |
with: | |
select_recipe_by_label: true | |
pangeo_forge_runner_config: > | |
{ | |
"Bake": { | |
"prune": ${{ env.prune }}, | |
"bakery_class": "pangeo_forge_runner.bakery.dataflow.DataflowBakery" | |
}, | |
"DataflowBakery": { | |
"use_public_ips": true, | |
"service_account_email": "julius-leap-dataflow@leap-pangeo.iam.gserviceaccount.com", | |
"project_id": "leap-pangeo", | |
"temp_gcs_location": "gs://leap-scratch/data-library/temp", | |
"max_num_workers": ${{ env.max_num_workers }} | |
}, | |
"TargetStorage": { | |
"fsspec_class": "gcsfs.GCSFileSystem", | |
"root_path": "gs://leap-persistent-ro/data-library/{job_name}" | |
}, | |
"InputCacheStorage": { | |
"fsspec_class": "gcsfs.GCSFileSystem", | |
"root_path": "gs://leap-scratch/data-library/cache" | |
} | |
} | |
env: | |
GOOGLE_APPLICATION_CREDENTIALS: "${{ steps.auth.outputs.credentials_file_path }}" |