diff --git a/.github/workflows/deploy-book-ghpages.yml b/.github/workflows/deploy-book-ghpages.yml index a2a9209..7544985 100644 --- a/.github/workflows/deploy-book-ghpages.yml +++ b/.github/workflows/deploy-book-ghpages.yml @@ -16,6 +16,20 @@ on: # - some-subfolder/** workflow_dispatch: +# Inherit configuration variables in the environment, or assign default values. +# Configuration variables may be set as explained here: +# https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-a-repository +env: + # `publish` as primary by default + PRIMARY_BRANCH: ${{ vars.PRIMARY_BRANCH != '' && vars.PRIMARY_BRANCH || 'publish' }} + # Space-separated list of alias-rules, e.g. 'draft:main alias:really-long-branch-name' + # By default, `draft` links to `main`. + # If no aliases are wanted, BRANCH_ALIASES may be set to ' ' (space). + BRANCH_ALIASES: ${{ vars.BRANCH_ALIASES != '' && vars.BRANCH_ALIASES || 'draft:main book:publish' }} + # Space-separated list of branch names, e.g. 'main second third'. + # By default, deploy all branches. This is indicated by '*'. + BRANCHES_TO_DEPLOY: ${{ vars.BRANCHES_TO_DEPLOY != '' && vars.BRANCHES_TO_DEPLOY || '*' }} + jobs: get-branches: runs-on: ubuntu-latest @@ -27,15 +41,21 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + - id: set-branches - name: Collect all remote branch names for the matrix + name: Set branches run: | - branches=$(git branch -r | sed 's,\s*origin/,,g' | jq -Rn '[inputs]') + if [ "$BRANCHES_TO_DEPLOY" == '*' ]; then + branches=$(git branch -r | sed 's,\s*origin/,,g' | jq -Rn '[inputs]') + else + branches=$(echo $BRANCHES_TO_DEPLOY | tr ' ' '\n' | jq -Rn '[inputs]') + fi echo "branches=$(echo $branches)" >> $GITHUB_OUTPUT build-books: runs-on: ubuntu-latest needs: get-branches + if: ${{ needs.get-branches.outputs.branches != '[]' }} permissions: pages: write id-token: write @@ -115,9 +135,16 @@ jobs: fi ls -a final/ - - name: Load root page to redirect to `book/` + - name: Symlink branch aliases run: | - cp redirect.html final/index.html + 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 + fi + done - name: Upload final Pages artifact uses: actions/upload-pages-artifact@v3