Skip to content

Commit

Permalink
Merge pull request #494 from dora-team/491-Replace-Hugo-builder-with-…
Browse files Browse the repository at this point in the history
…inline-scripts

Replace Hugo builder with inline scripts  (Fixes #491)
  • Loading branch information
davidstanke authored Jan 16, 2024
2 parents aa2f357 + ccd680e commit cb146fa
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions ci/preview-content.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,61 @@ steps:
# Copy correct Firestore config per project
cp -v ci/firebase-config.${PROJECT_ID}.js /workspace/hugo/static/js/firebase-config.js
- id: 'Hugo Build PREVIEW_CHANNEL (w/ Drafts) Site'
name: gcr.io/$PROJECT_ID/hugo
- id: 'Hugo Build'
name: 'ubuntu'
script: |
# Build draft site
hugo -v -s ./hugo -d /workspace/hugo/public --debug -D
# Install utils
apt update && apt upgrade
apt install wget -y
- id: 'Firebase deploy PREVIEW_CHANNEL (w/ Drafts) Hosting'
name: gcr.io/$PROJECT_ID/firebase
env:
- '_PR_NUMBER=$_PR_NUMBER'
- 'PROJECT_ID=$PROJECT_ID'
script: |
PREVIEW_CHANNEL="PR$_PR_NUMBER-DRAFT"
firebase hosting:channel:deploy ${PREVIEW_CHANNEL} --project=${PROJECT_ID}
# Install Hugo
HUGO_VERSION=0.114.1
HUGO_TYPE=_extended
# get the url of this preview channel
# (it returns in format `i hosting:channel: https://<url>`)
CHANNEL_DATA="$(firebase hosting:channel:open ${PREVIEW_CHANNEL} --project=${PROJECT_ID})"
HUGO_ID=hugo${HUGO_TYPE}_${HUGO_VERSION}
# Add header for communications clarity
echo "Cloud Build time: $(date)" > /workspace/gh-pr-comment-message.txt
wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/${HUGO_ID}_Linux-amd64.tar.gz -O /tmp/hugo.tar.gz && \
mkdir -p /workspace/tools && \
tar -xf /tmp/hugo.tar.gz -C /workspace/tools && \
ls -la /workspace/tools
# extract the URL from the channel data and save it to /workspace
echo "Preview this PR [including DRAFT content] at ${CHANNEL_DATA##* }" >> /workspace/gh-pr-comment-message.txt
echo ${CHANNEL_DATA##* }
# Build site w/ drafts
/workspace/tools/hugo --source=./hugo --destination=/workspace/hugo/public_drafts_on --logLevel=debug --buildDrafts
- id: 'Hugo Build PREVIEW_CHANNEL (w/o Drafts) Site'
name: gcr.io/$PROJECT_ID/hugo
script: |
# Build published site
rm -rf /workspace/hugo/public
hugo -v -s ./hugo -d /workspace/hugo/public --debug
# Build site w/o drafts
/workspace/tools/hugo --source=./hugo --destination=/workspace/hugo/public_drafts_off --logLevel=debug
- id: 'Firebase deploy PREVIEW_CHANNEL (w/o Drafts) Hosting'
- id: 'Firebase Deploy'
name: gcr.io/$PROJECT_ID/firebase
env:
- '_PR_NUMBER=$_PR_NUMBER'
- 'PROJECT_ID=$PROJECT_ID'
- 'REPO_FULL_NAME=${REPO_FULL_NAME}'
script: |
PREVIEW_CHANNEL="PR$_PR_NUMBER"
firebase hosting:channel:deploy ${PREVIEW_CHANNEL} --project=${PROJECT_ID}
echo "Using firebase version: "$(firebase --version)
# Create text file to be posted to PR message
echo "Cloud Build time: $(date)" > /workspace/gh-pr-comment-message.txt
for DRAFTS_MODE in "on" "off"; do
PREVIEW_CHANNEL="pr${_PR_NUMBER}_drafts-${DRAFTS_MODE}"
# move draft version of site into "public" folder
mkdir -p /workspace/hugo/public
rm -rf /workspace/hugo/public/*
cp -R /workspace/hugo/public_drafts_${DRAFTS_MODE}/* /workspace/hugo/public/
# deploy
firebase hosting:channel:deploy ${PREVIEW_CHANNEL} --project=${PROJECT_ID}
# get the url of this preview channel
# (it returns in format `i hosting:channel: https://<url>`)
CHANNEL_DATA="$(firebase hosting:channel:open ${PREVIEW_CHANNEL} --project=${PROJECT_ID})"
# get the url of this preview channel .
# (it returns in format `i hosting:channel: https://<url>`)
CHANNEL_DATA="$(firebase hosting:channel:open $PREVIEW_CHANNEL --project=${PROJECT_ID})"
echo "CHANNEL_DATA: $CHANNEL_DATA"
# extract the URL from the channel data and save it to /workspace
echo "Preview this PR [with drafts ${DRAFTS_MODE}] at ${CHANNEL_DATA##* }" >> /workspace/gh-pr-comment-message.txt
done
# extract the URL from the channel data and save it to /workspace
echo "Preview this PR [published content only] at ${CHANNEL_DATA##* }" >> /workspace/gh-pr-comment-message.txt
echo ${CHANNEL_DATA##* }
cat /workspace/gh-pr-comment-message.txt
- id: 'Write PR URL back to github'
name: 'bash'
Expand Down

0 comments on commit cb146fa

Please sign in to comment.