-
-
Notifications
You must be signed in to change notification settings - Fork 126
130 lines (108 loc) · 4.65 KB
/
preview.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Vercel Preview Deployment
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
workflow_dispatch:
push:
branches:
- dev
pull_request: # Trigger the workflow on pull request activities
branches:
- main # Specify the target branch for PRs
jobs:
Deploy-Preview:
runs-on: ubuntu-latest
# if: >
# github.event_name == 'workflow_dispatch' ||
# (github.event_name == 'push' && github.repository == 'EvanNotFound/hexo-theme-redefine') ||
# (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'EvanNotFound/hexo-theme-redefine')
steps:
- id: script
uses: actions/github-script@v6
with:
script: |
const isPr = [ 'pull_request', 'pull_request_target' ].includes(context.eventName)
core.setOutput('ref', isPr ? context.payload.pull_request.head.ref : context.ref)
core.setOutput('repo', isPr ? context.payload.pull_request.head.repo.full_name : context.repo.full_name)
- name: Checkout theme repository
uses: actions/checkout@v3
with:
path: 'theme' # Checkout the theme repository into a directory named 'theme'
ref: ${{ steps.script.outputs.ref }}
repository: ${{ steps.script.outputs.repo }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x' # Specify your required Node.js version
- name: Clone Hexo site repository
run: git clone https://github.com/EvanNotFound/redefine-demo.git hexo-site
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x' # Ensure compatibility with Python 3.x
- name: Install PyYAML
run: pip install pyyaml
- name: Enable Developer Mode in Config
run: |
echo "import yaml
import logging
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
try:
# Load YAML file
with open('hexo-site/_config.redefine.yml', 'r') as file:
config = yaml.safe_load(file)
logging.info('YAML file loaded successfully.')
# Modify the developer mode and CDN settings
config['developer']['enable'] = True
logging.info('Developer mode set to True.')
config['cdn']['enable'] = False
logging.info('CDN set to False.')
# Save the modified YAML file
with open('hexo-site/_config.redefine.yml', 'w') as file:
yaml.safe_dump(config, file, default_flow_style=False, sort_keys=False)
logging.info('YAML file saved with new settings.')
except Exception as e:
logging.error('An error occurred: {}'.format(e))
" > update_yaml.py
python update_yaml.py
- name: Move theme into Hexo site
run: |
mv theme hexo-site/themes/redefine
- name: Install dependencies
run: |
cd hexo-site
npm install
- name: Build Hexo
run: |
cd hexo-site
npm install
npm uninstall hexo-theme-redefine
npm run build
- name: Change directory to hexo-site
run: echo "HEXO_SITE_DIR=${{ github.workspace }}/hexo-site" >> $GITHUB_ENV
- name: Deploy to Vercel Action
uses: EvanNotFound/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
WORKING_DIRECTORY: ${{ env.HEXO_SITE_DIR }}
VERCEL_SCOPE: ${{ secrets.VERCEL_SCOPE }}
PRODUCTION: false
DEPLOY_PR_FROM_FORK: true
ALIAS_DOMAINS: |
redefine-preview.vercel.app
redefine-preview-git-{SHA}.vercel.app
PR_PREVIEW_DOMAIN: "redefine-preview-pr-{PR}.vercel.app"
# - name: Pull Vercel Environment Information
# run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
# working-directory: ${{ env.HEXO_SITE_DIR }}
# - name: Build Project Artifacts
# run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
# working-directory: ${{ env.HEXO_SITE_DIR }}
# - name: Deploy Project Artifacts to Vercel
# run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
# working-directory: ${{ env.HEXO_SITE_DIR }}