@@ -30,52 +30,59 @@ jobs:
3030 # - name: Run linkcheck
3131 # run: make linkcheck
3232
33- - name : Prepare deploy
34- run : make deploy
33+ # Set safe branch name for preview deployments
34+ - name : Set safe branch name
35+ if : github.ref != 'refs/heads/main'
36+ id : branch
37+ run : |
38+ # Sanitize branch name: only allow alphanumeric, dots, underscores, hyphens
39+ # Replace all other characters with hyphens and limit to 50 characters
40+ SAFE_NAME=$(echo ${GITHUB_REF_NAME} | sed 's/[^a-zA-Z0-9._-]/-/g' | cut -c1-50)
41+ echo "safe=${SAFE_NAME}" >> $GITHUB_OUTPUT
3542
36- # # node setup
37- # - name: Use Node.js 16
38- # uses: actions/setup-node@v3
39- # with:
40- # node-version: '16'
41- # - name: Install Yarn
42- # run: npm install -g yarn
43- # # node cache
44- # - name: Get yarn cache directory path
45- # id: yarn-cache-dir-path
46- # working-directory: submodules/volto
47- # run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
48- # - uses: actions/cache@v3
49- # id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
50- # with:
51- # path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
52- # key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
53- # restore-keys: |
54- # ${{ runner.os }}-yarn-
43+ # Build documentation with appropriate environment variables
44+ - name : Prepare deploy (main/stable)
45+ if : github.ref == 'refs/heads/main'
46+ run : |
47+ set -e # Exit on error
48+ export DOCS_VERSION=stable
49+ export DOCS_BASEURL=https://docs.openspp.org/
50+ export IS_PREVIEW=0
51+ make deploy || { echo "Build failed"; exit 1; }
5552
56- # - name: StoryBook build
57- # run: |
58- # cd submodules/volto
59- # yarn install --immutable
60- # yarn build-storybook -o ../../_build/html/storybook
53+ - name : Prepare deploy (preview)
54+ if : github.ref != 'refs/heads/main'
55+ run : |
56+ set -e # Exit on error
57+ export DOCS_VERSION=${{ steps.branch.outputs.safe }}
58+ export DOCS_BASEURL=https://docs.openspp.org/previews/${{ steps.branch.outputs.safe }}/
59+ export IS_PREVIEW=1
60+ make deploy || { echo "Build failed"; exit 1; }
6161
62- # - name: Deploy to server
63- # id: deploy
64- # uses: Pendect/action-rsyncer@v2.0.0
65- # env:
66- # DEPLOY_KEY: ${{secrets.DEPLOY_KEY_DOCS}}
67- # with:
68- # flags: '-avzr --delete'
69- # options: ''
70- # ssh_options: '-p ${{secrets.DEPLOY_PORT}}'
71- # src: '_build/html/'
72- # dest: '${{secrets.DEPLOY_USER_DOCS}}@${{secrets.DEPLOY_SERVER_DOCS}}:${{secrets.DEPLOY_PATH_DOCS}}'
73- - name : Commit documentation changes
62+ # Deploy stable documentation (main branch)
63+ - name : Deploy stable documentation
7464 if : github.ref == 'refs/heads/main'
7565 uses : peaceiris/actions-gh-pages@v3
7666 with :
7767 github_token : ${{ secrets.GITHUB_TOKEN }}
7868 publish_dir : _build/html
79- - name : Display status from deploy
80- if : github.ref == 'refs/heads/main'
81- run : echo "${{ steps.deploy.outputs.status }}"
69+ keep_files : true # Don't delete preview versions
70+
71+ # Deploy preview documentation (non-main branches)
72+ - name : Deploy preview documentation
73+ if : github.ref != 'refs/heads/main'
74+ uses : peaceiris/actions-gh-pages@v3
75+ with :
76+ github_token : ${{ secrets.GITHUB_TOKEN }}
77+ publish_dir : _build/html
78+ destination_dir : previews/${{ steps.branch.outputs.safe }}
79+ keep_files : true # Don't delete other versions
80+
81+ - name : Display deployment status
82+ run : |
83+ if [ "${{ github.ref }}" == "refs/heads/main" ]; then
84+ echo "✅ Deployed stable documentation to https://docs.openspp.org/"
85+ else
86+ BRANCH_SAFE=$(echo ${GITHUB_REF_NAME} | sed 's/\//-/g')
87+ echo "✅ Deployed preview documentation to https://docs.openspp.org/previews/${BRANCH_SAFE}/"
88+ fi
0 commit comments