Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusable workflow #24

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/call-deploy-book.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: call-deploy-book

on:
push:
branches:
- '**'
# If your git repository has the Jupyter Book within some-subfolder next to
# unrelated files, you can make this run only if a file within that specific
# folder has been modified.
#
# paths:
# - some-subfolder/**
Tom-van-Woudenberg marked this conversation as resolved.
Show resolved Hide resolved
workflow_dispatch:

jobs:
call-workflow:
uses: TeachBooks/template/.github/workflows/deploy-book-ghpages.yml@main
secrets: inherit
permissions:
contents: read
pages: write
id-token: write

Tom-van-Woudenberg marked this conversation as resolved.
Show resolved Hide resolved
41 changes: 21 additions & 20 deletions .github/workflows/deploy-book-ghpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ name: deploy-book
# Based on:
# https://jupyterbook.org/en/stable/publish/gh-pages.html

# Run on a push to any branch, then deploy books from all branches.
# NOTE to template users:
# You should not need to edit this file. This is not the workflow file that is being run on every push.
# Instead, on every push workflow `call-deploy-book` calls the `deploy-book` workflow at the original template repository:
# https://github.com/TeachBooks/template

on:
push:
branches:
- '**'
# If your git repository has the Jupyter Book within some-subfolder next to
# unrelated files, you can make this run only if a file within that specific
# folder has been modified.
#
# paths:
# - some-subfolder/**
workflow_dispatch:
workflow_call:

# Inherit configuration variables in the environment, or assign default values.
# Configuration variables may be set as explained here:
Expand Down Expand Up @@ -46,10 +41,14 @@ jobs:
name: Set branches
run: |
if [ "$BRANCHES_TO_DEPLOY" == '*' ]; then
branches=$(git branch -r | sed 's,\s*origin/,,g' | jq -Rn '[inputs]')
branches=$(git branch -r | sed 's,\s*origin/,,g')
else
branches=$(echo "$BRANCHES_TO_DEPLOY" | tr ' ' '\n' | grep -E '\S' | jq -Rn '[inputs]')
branches=$(echo "$BRANCHES_TO_DEPLOY" | tr ' ' '\n' | grep -E '\S')
fi
echo "$branches" > raw.txt
echo "$branches" | tr '/":<>|*?\/\\' '-' > clean.txt
paste -d ' ' raw.txt clean.txt | sed 's/ / -> /g'
branches=$(echo "$branches" | jq -Rn '[inputs]')
echo "branches=$(echo $branches)" >> $GITHUB_OUTPUT

build-books:
Expand Down Expand Up @@ -134,19 +133,22 @@ jobs:
run: |
GLOBIGNORE=".:.."
# -i leads to a prompt in case of conflict, => a timeout
if [ -d final/$PRIMARY_BRANCH ]; then
cp -irv final/$PRIMARY_BRANCH/* final/
if [ -d final/"$PRIMARY_BRANCH" ]; then
cp -irv final/"$PRIMARY_BRANCH"/* final/
fi
ls -a final/

- name: Symlink branch aliases
run: |
echo $BRANCH_ALIASES | tr ' ' '\n' | grep -E '\S' |
echo "$BRANCH_ALIASES" | tr ' ' '\n' | grep -E '\S' |
while IFS=':' read -r key value; do
# If the target branch is to be deployed, make symlink to it.
if [ "$BRANCHES_TO_DEPLOY" == "*" ] || echo $BRANCHES_TO_DEPLOY | tr ' ' '\n' | grep "^$value$"; then
echo link $key "->" $value
ln -s $value final/$key
if [ "$BRANCHES_TO_DEPLOY" == "*" ] || echo "$BRANCHES_TO_DEPLOY" | tr ' ' '\n' | grep "^$value$"; then
# Clean branch names of special characters
clean_key=$(echo "$key" | tr '/":<>|*?\/\\' '-')
clean_value=$(echo "$key" | tr '/":<>|*?\/\\' '-')
echo link $clean_key "->" $clean_value
ln -s "$clean_value" final/"$clean_key"
fi
done

Expand All @@ -164,4 +166,3 @@ permissions:
contents: read
pages: write
id-token: write