LRC-299: update per PR review comment #400
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
on: | |
push: | |
branches: | |
- '**' | |
jobs: | |
build_docs: | |
name: Build the production documentation site | |
runs-on: ubuntu-latest | |
env: | |
HUGO_VERSION: 0.111.2 | |
GCLOUD_VERSION: 458.0.1-linux-x86_64 | |
BUCKET: docs-prod-learn-redis-com | |
BUCKET_SERVICE_ACCOUNT: ${{ secrets.BUCKET_DOCUMENTATION_SA_PROD }} | |
BUCKET_SECRET: ${{ secrets.BUCKET_DOCUMENTATION_PROD }} | |
GCP_PROJECT: ${{ secrets.GCP_PROJECT_PROD }} | |
steps: | |
- name: Start | |
run: echo "The name of the branch is ${{ github.ref }} on ${{ github.repository }}" | |
- name: Install Hugo | |
run: | | |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ | |
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb | |
- name: Check the branch out | |
uses: actions/checkout@v4 | |
- name: List repository files | |
run: ls ${{ github.workspace }} | |
- name: Validate the branch name before using it | |
run: | | |
if [[ "${{ github.ref_name }}" =~ ^[a-zA-Z0-9_.-]+$ ]] | |
then | |
echo "The branch name ${{ github.ref_name }} is valid." | |
else | |
echo "ERROR: Invalid branch name ${{ github.ref_name }}!" | |
exit 1 | |
fi | |
- name: Configure Hugo | |
run: | | |
if [[ "${{ github.ref_name }}" == "main" ]] | |
then | |
hugo_root_path=docs/staging/dev | |
elif [[ "${{ github.ref_name }}" == "latest" ]] | |
then | |
hugo_root_path="docs/latest" | |
elif [[ "${{ endsWith(github.ref_name, '-build') }}" == "true" ]] | |
then | |
hugo_root_path=`echo docs/version/${{ github.ref_name }} | sed 's/-build$//'` | |
else | |
hugo_root_path=docs/staging/${{ github.ref_name }} | |
fi \ | |
&& sed -i "s#baseURL = \"https://redis.io\"#baseURL = \"https://redis.io/$hugo_root_path\"#g" config.toml | |
- name: Install dependencies and run Hugo | |
run: make all | |
- name: List client examples | |
run: ls "${{ github.workspace }}/examples" | |
- name: List files to be published | |
run: ls "${{ github.workspace }}/public" | |
- name: Install the Google Cloud CLI | |
run: | | |
wget -O ${{ github.workspace }}/google-cloud-cli.tar.gz "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-$GCLOUD_VERSION.tar.gz" \ | |
&& tar -xvf google-cloud-cli.tar.gz -C ${{ github.workspace }}\ | |
&& ${{ github.workspace }}/google-cloud-sdk/install.sh --quiet | |
- name: Prepare bucket authentication | |
run: echo $BUCKET_SECRET | base64 --decode > service_account.json && ls -a service_account.json | |
- name: Authenticate to the bucket | |
run: | | |
./google-cloud-sdk/bin/gcloud auth activate-service-account $BUCKET_SERVICE_ACCOUNT --key-file=./service_account.json --project=$GCP_PROJECT \ | |
&& ./google-cloud-sdk/bin/gcloud auth list | |
- name: Sync the branch to the bucket | |
run: | | |
if [[ "${{ github.ref_name }}" == "main" ]] | |
then | |
bucket_path=staging/dev | |
elif [[ "${{ github.ref_name }}" == "latest" ]] | |
then | |
bucket_path=${{ github.ref_name }} | |
elif [[ "${{ endsWith(github.ref_name, '-build') }}" == "true" ]] | |
then | |
bucket_path=`echo "version/${{ github.ref_name }}" | sed 's/-build$//'` | |
else | |
bucket_path=staging/${{ github.ref_name }} | |
fi \ | |
&& ./google-cloud-sdk/bin/gsutil -m rsync -r -c -j html -d ${{ github.workspace }}/public gs://$BUCKET/$bucket_path | |
- name: End | |
run: echo "This job's status is ${{ job.status }}." |