Previously, we used GitHub Actions to configure automated deployment for Hugo. Today, I’ll mainly document how to set up deployment to Tencent Cloud via SSH using GitHub Actions.
Since wnote.com uses DNS-based intelligent routing—serving GitHub Pages for overseas users and a containerized environment on a Tencent Cloud host for users in mainland China—it’s necessary to integrate GitHub Actions with Tencent Cloud.
Configuring Secrets
Here, we primarily configure the SSH-related credentials for Tencent Cloud:
We configure the following secrets:
Adding Tencent Cloud Deployment to the Workflow Configuration File
name:Deploy Hugo site to Pageson:# Runs on pushes targeting the default branchpush:branches:["master"]# Allows you to run this workflow manually from the Actions tabworkflow_dispatch:# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pagespermissions:contents:readpages:writeid-token:write# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.concurrency:group:"pages"cancel-in-progress:false# Default to bashdefaults:run:shell:bashjobs:# Build job and Deploy hugo to pagesbuild-deploy:runs-on:ubuntu-latestenv:HUGO_VERSION:0.121.0steps:- name:Install Hugo CLIrun:| 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:Install Dart Sassrun:sudo snap install dart-sass- name:Checkoutuses:actions/checkout@v4with:submodules:recursive- name:Build with Hugoenv:HUGO_CACHEDIR:${{ runner.temp }}/hugo_cacheHUGO_ENVIRONMENT:productionrun:| hugo \
--minify \
--baseURL "https://wnote.com/"
#--baseURL "${{ steps.pages.outputs.base_url }}/"- name:Upload artifactuses:actions/upload-pages-artifact@v3with:path:./public- name:Deploy to GitHub Pagesuses:peaceiris/actions-gh-pages@v4with:deploy_key:${{ secrets.ACTIONS_DEPLOY_KEY }}external_repository:wzdushu/wzdushu.github.iopublish_dir:./publicpublish_branch:mastercname:wnote.comcommit_message:${{ github.event.head_commit.message }}- name:Deploy to Tencent Clouduses:easingthemes/ssh-deploy@v5.1.0with:SSH_PRIVATE_KEY:${{ secrets.SSH_PRIVATE_KEY }}ARGS:"-avzr --delete"SSH_CMD_ARGS:"-o StrictHostKeyChecking=no"SOURCE:"public/"REMOTE_HOST:${{ secrets.TENCENT_REMOTE_HOST }}REMOTE_PORT:${{ secrets.TENCENT_REMOTE_PORT }}REMOTE_USER:${{ secrets.TENCENT_REMOTE_USR }}TARGET:${{ secrets.TENCENT_REMOTE_TARGET }}# /opt/wwwroot/xxxEXCLUDE:"/dist/, /node_modules/"SCRIPT_BEFORE:| whoami
ls -alSCRIPT_AFTER:| whoami
ls -al
echo $RSYNC_STDOUT
At this point, the GitHub Actions workflow for deploying to Tencent Cloud via SSH is complete.