迁移 COS 地域 #378
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: Auto build blog | |
| on: | |
| push: | |
| branches: | |
| - main | |
| repository_dispatch: | |
| workflow_dispatch: | |
| jobs: | |
| build-main: | |
| name: Build Main | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| deployments: write | |
| steps: | |
| - name: Setup Node.js | |
| uses: actions/setup-node@main | |
| with: | |
| node-version: lts/* | |
| - name: Setup Python | |
| uses: actions/setup-python@main | |
| with: | |
| python-version: 3.x | |
| - name: Check out code | |
| uses: actions/checkout@main | |
| - name: Fetch Posts | |
| run: | | |
| git clone https://${{secrets.POST_CHECKOUT_TOKEN}}@github.com/Potat0000/Blog-Posts.git source/_posts | |
| python3 build_script/gen_updatedtime.py | |
| rm -rf source/_posts/.git* | |
| - name: Install packages | |
| run: | | |
| npm install -g hexo-cli | |
| npm install | |
| - name: Get and Patch Lib Files | |
| run: | | |
| mv source/favicon/* source/ | |
| rm -rf source/favicon | |
| curl https://cdn.jsdelivr.net/gh/PrismJS/prism-themes@master/themes/prism-material-light.min.css --create-dirs -o node_modules/prismjs/themes/prism-materiallight.css | |
| curl https://cdn.jsdelivr.net/gh/PrismJS/prism-themes@master/themes/prism-material-oceanic.min.css --create-dirs -o node_modules/prismjs/themes/prism-materialoceanic.css | |
| mv source/beian.ejs node_modules/hexo-theme-fluid/layout/_partials/footer/beian.ejs | |
| - name: Build | |
| run: | | |
| hexo g | |
| sed -i 's,IEJUMPIEJUMPIEJUMP,if(/*@cc_on!@*/false||(!!window.MSInputMethodContext\&\&!!document.documentMode))window.location.href="https://support.dmeng.net/upgrade-your-browser.html?referrer="+encodeURIComponent(window.location.href);,g' $(grep IEJUMPIEJUMPIEJUMP -rl ./public) | |
| - name: Clean up | |
| run: | | |
| cd public | |
| rm -rf xml | |
| rm img/default.png img/fluid.png | |
| - name: Minify | |
| uses: docker://devatherock/minify-js:3.0.0 | |
| with: | |
| directory: public | |
| add_suffix: false | |
| - name: Deploy to TencentCloud COS | |
| env: | |
| SECRET_ID: ${{ secrets.TENCENTCLOUD_SECRET_ID }} | |
| SECRET_KEY: ${{ secrets.TENCENTCLOUD_SECRET_KEY }} | |
| REGION: ap-shanghai | |
| BUCKET: potat0-box-1307988268 | |
| run: | | |
| pip install coscmd | |
| coscmd config -a $SECRET_ID -s $SECRET_KEY -b $BUCKET -r $REGION | |
| cd public | |
| coscmd upload -rfs --delete ./ / | |
| - name: Prepare URL List for Refresh and Prefetch | |
| run: | | |
| echo "https://www.potat0.cc/" > urls.txt | |
| cd public | |
| find . -type f -not -path '*/.*' -not -path './index.html' -not -path './posts/*' | sed "s|^./|https://www.potat0.cc/|" >> ../urls.txt | |
| find . -type f -not -path '*/.*' -a -path './posts/*' -a \( -name '*.html' -o -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.bmp' -o -name '*.gif' -o -name '*.svg' -o -name '*.webp' \) | sed "s|^./|https://www.potat0.cc/|" >> ../urls.txt | |
| cd .. | |
| echo "$(wc -l < urls.txt) URLs in total" | |
| - name: Refresh and Prefetch TencentCloud EdgeOne | |
| env: | |
| TENCENTCLOUD_SECRET_ID: ${{ secrets.TENCENTCLOUD_SECRET_ID }} | |
| TENCENTCLOUD_SECRET_KEY: ${{ secrets.TENCENTCLOUD_SECRET_KEY }} | |
| TENCENTCLOUD_REGION: ap-shanghai | |
| run: | | |
| pip install tccli | |
| tccli teo CreatePurgeTask --cli-unfold-argument --ZoneId zone-3d2iwq53tqx6 --Type purge_host --Targets 'www.potat0.cc' | |
| cat urls.txt | xargs -I {} tccli teo CreatePrefetchTask --cli-unfold-argument --ZoneId zone-3d2iwq53tqx6 --Targets {} | |
| build-cn: | |
| name: Build CN | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| deployments: write | |
| steps: | |
| - name: Setup Node.js | |
| uses: actions/setup-node@main | |
| with: | |
| node-version: lts/* | |
| - name: Setup Python | |
| uses: actions/setup-python@main | |
| with: | |
| python-version: 3.x | |
| - name: Check out code | |
| uses: actions/checkout@main | |
| - name: Fetch Posts | |
| run: | | |
| git clone https://${{secrets.POST_CHECKOUT_TOKEN}}@github.com/Potat0000/Blog-Posts.git source/_posts | |
| python3 build_script/gen_updatedtime.py | |
| rm -rf source/_posts/.git* | |
| - name: Install packages | |
| run: | | |
| npm install -g hexo-cli | |
| npm install | |
| - name: Get and Patch Lib Files | |
| run: | | |
| mv source/favicon/* source/ | |
| rm -rf source/favicon | |
| curl https://cdn.jsdelivr.net/gh/PrismJS/prism-themes@master/themes/prism-material-light.min.css --create-dirs -o node_modules/prismjs/themes/prism-materiallight.css | |
| curl https://cdn.jsdelivr.net/gh/PrismJS/prism-themes@master/themes/prism-material-oceanic.min.css --create-dirs -o node_modules/prismjs/themes/prism-materialoceanic.css | |
| mv source/beian.ejs node_modules/hexo-theme-fluid/layout/_partials/footer/beian.ejs | |
| - name: Patch for CN-Domain website | |
| run: | | |
| sed -i 's/www.potat0.cc/www.土豆.space/g' _config.yml | |
| sed -i 's/www.potat0.cc/www.土豆.space/g' source/manifest.json | |
| sed -i 's/www.potat0.cc/www.土豆.space/g' source/robots.txt | |
| sed -i 's/icp_text: 浙ICP备2021017952号-1/icp_text: 浙ICP备2021017952号-2/g' _config.fluid.yml | |
| sed -i 's/police_text: 浙公网安备33010602011812号/police_text: 浙公网安备33010602013468号/g' _config.fluid.yml | |
| sed -i 's/police_code: 33010602011812/police_code: 33010602013468/g' _config.fluid.yml | |
| sed -i 's/moeicp_code: 20221816/moeicp_code: 20241816/g' _config.fluid.yml | |
| perl -0777 -np -i -e 's,(-{10}\n\n).*xn--udsw05j\.space.*(\n\n-{10}),\1这是本站的一个中文域名的实验性站点,你可以 [点击此处](https://www.potat0.cc/) 访问标准网站。\2,g' source/about/index.md | |
| - name: Build | |
| run: | | |
| hexo g | |
| sed -i 's,IEJUMPIEJUMPIEJUMP,if(/*@cc_on!@*/false||(!!window.MSInputMethodContext\&\&!!document.documentMode))window.location.href="https://support.dmeng.net/upgrade-your-browser.html?referrer="+encodeURIComponent(window.location.href);,g' $(grep IEJUMPIEJUMPIEJUMP -rl ./public) | |
| - name: Clean up | |
| run: | | |
| cd public | |
| rm -rf xml | |
| rm img/default.png img/fluid.png | |
| - name: Minify | |
| uses: docker://devatherock/minify-js:3.0.0 | |
| with: | |
| directory: public | |
| add_suffix: false | |
| - name: Deploy to Aliyun OSS | |
| uses: fangbinwei/aliyun-oss-website-action@v1 | |
| with: | |
| accessKeyId: ${{ secrets.ALIYUN_ACCESSKEY_ID }} | |
| accessKeySecret: ${{ secrets.ALIYUN_ACCESSKEY_SECRET }} | |
| bucket: potat0-box-cn | |
| endpoint: oss-cn-hangzhou.aliyuncs.com | |
| folder: public | |
| incremental: true | |
| skipSetting: true | |
| - name: Prepare URL List for Refresh and Prefetch | |
| run: | | |
| echo "https://www.xn--udsw05j.space/" > urls.txt | |
| echo "https://www.xn--udsw05j.space/" > url-dir.txt | |
| cd public | |
| find . -type f -not -path '*/.*' -not -path './index.html' -not -path './posts/*' | sed "s|^./|https://www.xn--udsw05j.space/|" >> ../urls.txt | |
| find . -type f -not -path '*/.*' -a -path './posts/*' -a \( -name '*.html' -o -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.bmp' -o -name '*.gif' -o -name '*.svg' -o -name '*.webp' \) | sed "s|^./|https://www.xn--udsw05j.space/|" >> ../urls.txt | |
| cd .. | |
| echo "$(wc -l < urls.txt) URLs in total" | |
| - name: Refresh and Prefetch Aliyun CDN | |
| run: | | |
| pip install aliyun-python-sdk-core aliyun-python-sdk-cdn | |
| python3 build_script/aliyun-cdn.py -i ${{secrets.ALIYUN_ACCESSKEY_ID}} -k ${{secrets.ALIYUN_ACCESSKEY_SECRET}} -r ./urls.txt -t clear -o File | |
| python3 build_script/aliyun-cdn.py -i ${{secrets.ALIYUN_ACCESSKEY_ID}} -k ${{secrets.ALIYUN_ACCESSKEY_SECRET}} -r ./url-dir.txt -t clear -o Directory | |
| sleep 3 | |
| python3 build_script/aliyun-cdn.py -i ${{secrets.ALIYUN_ACCESSKEY_ID}} -k ${{secrets.ALIYUN_ACCESSKEY_SECRET}} -r ./urls.txt -t push |