Repository navigation
Create 让 QQ Bot 主动给你发消息-关键不是 QQ 号而是 openid.md #105
This file contains hidden or 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
| name: Hugo build and deploy | |
| on: | |
| push: | |
| branches: ["main"] | |
| workflow_dispatch: | |
| inputs: | |
| deploy_pages: | |
| description: "Deploy to GitHub Pages" | |
| required: false | |
| default: "false" | |
| type: choice | |
| options: | |
| - "false" | |
| - "true" | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "site" | |
| cancel-in-progress: false | |
| jobs: | |
| server-deploy-config: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| deploy_server: ${{ steps.read-config.outputs.deploy_server }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Read server deploy config | |
| id: read-config | |
| run: | | |
| set -e | |
| deploy_server=false | |
| if [ -f .github/server-deploy.env ]; then | |
| . .github/server-deploy.env | |
| deploy_server="${DEPLOY_SERVER:-false}" | |
| fi | |
| case "$deploy_server" in | |
| true|false) ;; | |
| *) | |
| echo "DEPLOY_SERVER must be true or false, got: $deploy_server" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| echo "deploy_server=$deploy_server" >> "$GITHUB_OUTPUT" | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: server-deploy-config | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| fetch-depth: 0 | |
| - name: Setup Hugo | |
| uses: peaceiris/actions-hugo@v3 | |
| with: | |
| hugo-version: "latest" | |
| extended: true | |
| - name: Build site | |
| env: | |
| GITALK_CLIENT_ID: ${{ secrets.GITALK_CLIENT_ID }} | |
| GITALK_CLIENT_SECRET: ${{ secrets.GITALK_CLIENT_SECRET }} | |
| HUGO_MOMENTS_PASSWORD_HASH: ${{ secrets.HUGO_MOMENTS_PASSWORD_HASH }} | |
| HUGO_MOMENTS_RECOVERY_EMAIL: ${{ secrets.HUGO_MOMENTS_RECOVERY_EMAIL }} | |
| run: npm run build | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./public | |
| - name: Upload site artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: site-public | |
| path: ./public | |
| if-no-files-found: error | |
| retention-days: 1 | |
| deploy-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 | |
| deploy-server: | |
| if: needs.server-deploy-config.outputs.deploy_server == 'true' | |
| runs-on: ubuntu-latest | |
| needs: [build, server-deploy-config] | |
| steps: | |
| - name: Download site artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: site-public | |
| path: ./site-public | |
| - name: Deploy to june-server | |
| env: | |
| SERVER_SSH_HOST: ${{ secrets.SERVER_SSH_HOST }} | |
| SERVER_SSH_PORT: ${{ secrets.SERVER_SSH_PORT }} | |
| SERVER_SSH_USER: ${{ secrets.SERVER_SSH_USER }} | |
| SERVER_DEPLOY_PATH: ${{ secrets.SERVER_DEPLOY_PATH }} | |
| SERVER_SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_PRIVATE_KEY }} | |
| SERVER_SSH_KNOWN_HOSTS: ${{ secrets.SERVER_SSH_KNOWN_HOSTS }} | |
| run: | | |
| set -e | |
| if [ -z "$SERVER_SSH_HOST" ] || [ -z "$SERVER_SSH_USER" ] || [ -z "$SERVER_DEPLOY_PATH" ] || [ -z "$SERVER_SSH_PRIVATE_KEY" ]; then | |
| echo "Server deploy secrets are not configured; skipping." | |
| exit 0 | |
| fi | |
| mkdir -p ~/.ssh | |
| chmod 700 ~/.ssh | |
| key_file=~/.ssh/id_ed25519 | |
| printf '%s' "$SERVER_SSH_PRIVATE_KEY" | tr -d '\r\n' | base64 -d > "$key_file" | |
| chmod 600 "$key_file" | |
| ssh-keygen -y -f "$key_file" >/dev/null 2>&1 | |
| if [ -n "$SERVER_SSH_KNOWN_HOSTS" ]; then | |
| printf '%s' "$SERVER_SSH_KNOWN_HOSTS" | tr -d '\r' > ~/.ssh/known_hosts | |
| else | |
| ssh-keyscan -p "${SERVER_SSH_PORT:-22}" -H "$SERVER_SSH_HOST" >> ~/.ssh/known_hosts | |
| fi | |
| chmod 600 ~/.ssh/known_hosts | |
| ssh -p "${SERVER_SSH_PORT:-22}" "$SERVER_SSH_USER@$SERVER_SSH_HOST" "mkdir -p '$SERVER_DEPLOY_PATH'" | |
| rsync -az --delete -e "ssh -p ${SERVER_SSH_PORT:-22}" ./site-public/ "$SERVER_SSH_USER@$SERVER_SSH_HOST:$SERVER_DEPLOY_PATH/" |