content-update #514
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
# Sample workflow for building and deploying a Gatsby site to GitHub Pages | |
# | |
# To get started with Gatsby see: https://www.gatsbyjs.com/docs/quick-start/ | |
# | |
name: Deploy Gatsby site to Pages | |
on: | |
# Runs on pushes targeting the default branch | |
push: | |
branches: ["master"] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
repository_dispatch: | |
type: ["content-update"] | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
# Allow one concurrent deployment | |
concurrency: | |
group: "pages" | |
cancel-in-progress: true | |
# Default to bash | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
# deploy: | |
# name: Deploy on my server (sponsored by @Qingyu-Shi) | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Execute deployment script | |
# uses: appleboy/ssh-action@v1.0.3 | |
# with: | |
# host: ${{ secrets.SERVER_IP }} | |
# username: ${{ secrets.SERVER_USERNAME }} | |
# password: ${{ secrets.SERVER_PASSWORD }} | |
# port: 22 | |
# script: cd /www/mem.ac && bash deploy.sh | |
# Build job | |
build: | |
runs-on: ubuntu-latest | |
name: Build with Gatsby | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Checkout blog content | |
uses: actions/checkout@v4 | |
with: | |
repository: memset0/blog-posts | |
path: content | |
ref: master | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
# cache: ${{ steps.detect-package-manager.outputs.manager }} | |
- name: Setup Pages | |
id: pages | |
uses: actions/configure-pages@v2 | |
# with: | |
# # Automatically inject pathPrefix in your Gatsby configuration file. | |
# # You may remove this line if you want to manage the configuration yourself. | |
# static_site_generator: gatsby | |
- name: Restore NPM cache | |
id: cache-node-modules | |
uses: actions/cache@v3 | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-node-modules-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }} | |
# true代表缓存命中,node_modules没有变化,而''代表没有命中,node_modules发生变化 | |
- name: "Debug: is cache hit?" | |
run: echo "${{ steps.cache-node-modules.outputs.cache-hit }}" | |
# 只有结果是''时才执行 | |
- name: Install dependencies | |
if: steps.cache-node-modules.outputs.cache-hit == '' | |
run: npm ci | |
- name: Restore Gatsby cache | |
uses: actions/cache@v3 | |
with: | |
path: public | |
key: ${{ runner.os }}-gatsby-build-${{ hashFiles('public') }} | |
restore-keys: ${{ runner.os }}-gatsby-build- | |
- name: Build with Gatsby | |
env: | |
PREFIX_PATHS: "true" | |
GATSBY_CPU_COUNT: 1 | |
run: npm run build | |
- name: Push to the static repository | |
uses: cpina/github-action-push-to-another-repository@main | |
env: | |
API_TOKEN_GITHUB: ${{ secrets.GH_TOKEN }} | |
with: | |
source-directory: ./public | |
destination-github-username: mem-static | |
destination-repository-name: blog-ng | |
target-branch: main | |
user-email: ci@memset0.cn | |
- name: Deploy on the server | |
uses: appleboy/ssh-action@v1.0.3 | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
port: 22 | |
script: cd /www/mem.ac/tmp && git pull -f | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ./public | |
pages: | |
name: Deploy with Github Pages | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |