This is the fifth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021
While Hexo’s personal blog is powerful and convenient, with commands to quickly generate static pages and deploy access, there is room for optimization to make it even better, such as putting packaged deployment environments directly into Github Actions, which is how I personally deploy my blog. Here’s an introduction.
The overall train of thought
- Configure Github Actions flow in Hexo project
- The Hexo blog project is uploaded to GIthub
- Github Actions automatically package and upload the package files to Tencent cloud server
- Tencent cloud server replaces the Nginx entry file with a new package file
Function implementation
Create a configuration
Create the.github/workflows/{workflow-name}.yml file in the project root directory. The workflow-name here is created based on the different event or actions to be implemented.
Project configuration
Modify your own configuration according to the comments
On: push: branches: -main # Job jobs: #job1 build_and_deploy: name: main # Job jobs: #job1 build_and_deploy: name: Build-and-del =ploy runs-on: ubuntu-latest steps: # pull code - name: checkout uses: actions/checkout@v2 # generate static file - name: Use Node.js uses: actions/setup-node@v2 with: node-version: "14.x" - run: npm install hexo-cli -g - run: npm install && npm run build - name: Deploy to GitHub Pages uses: crazy-max/ghaction-github-pages@v2 with: Target_branch: gh-pages build_dir: public env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} # automatic deployment to Tencent cloud server - name: Deploy to Tencent uses: easingthemes/[email protected] env: # private key SSH_PRIVATE_KEY: ${{secrets.server_ssh_key}} ARGS: "-rltgodzvo --delete" # SOURCE: public # server IP: replace your server IP REMOTE_HOST: ${{secrets.server_ip}} # user REMOTE_USER: root # TARGET address where you deploy code on the server TARGET: /workspacesCopy the code
Secrets
Add these Secrets to the Github control panel:
- GITHUB_TOKEN – Used to issue Github releases
- SERVER_IP – Internet IP address of Tencent cloud server
- SERVER_SSH_KEY – SSH private key of Tencent cloud
complete
Push code in the main branch of the project triggers the workflow, and a green tick indicates successful deployment
Click on it and you can see the flow that’s triggered at one time. I only have one flow here
Click in to see the detailed deployment log
conclusion
This is not a complete CI, because IN Tencent cloud server I use the pagoda to build the station, the file directly uploaded cannot directly cover the nginx entry file, need to operate again in the server. Leave a hole for later filling