try own actions #3
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: build-book | |
on: | |
workflow_call: | |
inputs: | |
environment_name: | |
description: 'Name of conda environment to activate' | |
required: false | |
default: 'advanced-viz-cookbook' | |
type: string | |
environment_file: | |
description: 'Name of conda environment file' | |
required: false | |
default: 'environment.yml' | |
type: string | |
path_to_notebooks: | |
description: 'Location of the JupyterBook source relative to repo root' | |
required: false | |
default: './' | |
type: string | |
use_cached_environment: | |
description: 'Flag for whether we should attempt to retrieve a previously cached environment.' | |
required: false | |
default: 'false' | |
type: string # had a lot of trouble with boolean types, see https://github.com/actions/runner/issues/1483${{ github.repository }} | |
artifact_name: | |
description: 'The name to assign to the built book artifact.' | |
required: false | |
default: 'book-zip' | |
type: string | |
type: string | |
output_path: | |
description: 'Path to the built html content relative to `path_to_notebooks`' | |
required: false | |
default: '_build/html' | |
type: string | |
build_from_code_artifact: | |
description: 'Should we try to build from a previously uploaded code artifact?' | |
required: false | |
default: 'false' | |
type: string | |
code_artifact_name: | |
description: | |
required: false | |
default: 'code-zip' | |
type: string | |
secrets: | |
ARM_USERNAME: | |
description: 'Username for the ARM Data Discovery portal (https://adc.arm.gov/armlive/)' | |
required: false | |
ARM_PASSWORD: | |
description: 'Password for the ARM Data Discovery portal (https://adc.arm.gov/armlive/)' | |
required: false | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash -l {0} | |
steps: | |
- name: Checkout the code from the repo | |
if: inputs.build_from_code_artifact == 'false' | |
uses: actions/checkout@v4 | |
# The next two steps should replicated checking out the code | |
- name: Download code artifact | |
id: get_code_artifact | |
if: inputs.build_from_code_artifact == 'true' | |
uses: dawidd6/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
workflow: trigger-book-build.yaml | |
run_id: ${{ github.event.workflow_run.id }} | |
name: ${{ inputs.code_artifact_name }} | |
- name: Unzip the code | |
if: inputs.build_from_code_artifact == 'true' | |
run: | | |
unzip pr_code.zip | |
rm -f pr_code.zip | |
# - name: Fetch Repo Name | |
# id: repo-name | |
# run: echo "value=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_OUTPUT # just the repo name, not owner | |
- name: Get GitHub environment variables | |
id: get-env | |
uses: FranzDiebold/github-env-vars-action@v2 | |
- name: Check for config file | |
id: check_config | |
uses: andstor/file-existence-action@v2 | |
with: | |
files: "${{ inputs.path_to_notebooks }}/_config.yml" | |
- name: Parse config file | |
id: parse_config | |
if: steps.check_config.outputs.files_exists == 'true' | |
uses: CumulusDS/[email protected] | |
with: | |
file: ${{ inputs.path_to_notebooks }}/_config.yml | |
execute_notebooks: execute.execute_notebooks | |
binderhub_url: sphinx.config.html_theme_options.launch_buttons.binderhub_url | |
timeout: execute.timeout | |
- name: Echo values from config file | |
if: steps.check_config.outputs.files_exists == 'true' | |
run: | | |
echo ${{ steps.parse_config.outputs.execute_notebooks }} | |
echo ${{ steps.parse_config.outputs.binderhub_url }} | |
echo ${{ steps.parse_config.outputs.timeout }} | |
- name: Test for environment change | |
id: env_change | |
uses: tj-actions/changed-files@v40 | |
with: | |
files: ${{ inputs.environment_file }} | |
- name: Echo environment change test result | |
run: | | |
echo '(DEBUG) The value of steps.env_change.outputs.any_changed is:' | |
echo ${{ steps.env_change.outputs.any_changed }} | |
- name: Setup Mambaforge | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
miniforge-variant: Mambaforge | |
miniforge-version: latest | |
python-version: "3.10" # binderbot is failing with python 3.11 | |
activate-environment: ${{ inputs.environment_name }} | |
use-mamba: true | |
- name: Create book build environment | |
run: | | |
echo "Debug: Checking conditions for creating book build environment..." | |
mamba install -c conda-forge jupyter-book pip | |
echo "Debug: Environment created successfully." | |
# Add any other debugging information as needed | |
- name: Update execution environment | |
run: mamba env update -n ${{ inputs.environment_name }} -f ${{ inputs.environment_file }} | |
- name: Disable notebook execution during jupyterbook build | |
if: | | |
steps.parse_config.outputs.execute_notebooks == 'binder' | |
shell: python | |
run: | | |
import yaml | |
with open('${{ inputs.path_to_notebooks }}/_config.yml') as f: | |
data = yaml.safe_load(f) | |
data['execute']['execute_notebooks'] = 'off' | |
with open('${{ inputs.path_to_notebooks }}/_config.yml', 'w') as f: | |
yaml.dump(data, f) | |
- name: Build the book | |
# Assumption is that if execute_notebooks != 'binder' then the _config.yml file must be set to execute notebooks during build | |
env: | |
ARM_USERNAME: ${{ secrets.ARM_USERNAME }} | |
ARM_PASSWORD: ${{ secrets.ARM_PASSWORD }} | |
SECRETS_VARS: ${{ toJson(secrets) }} | |
run: | | |
jupyter-book build ../../notebooks | |
- name: Zip the book | |
run: | | |
set -x | |
set -e | |
if [ -f book.zip ]; then | |
rm -rf book.zip | |
fi | |
zip -r book.zip ${{ inputs.path_to_notebooks }}/ ${{ inputs.output_path }} | |
- name: Upload zipped book artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ inputs.artifact_name }} | |
path: ./book.zip |