deploy-to-production #565
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
name: deploy-to-production | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_run: | |
workflows: ["create-post"] | |
types: [completed] | |
branches: [main] | |
workflow_dispatch: | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: "production" | |
cancel-in-progress: false | |
# Default to bash | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/[email protected] | |
# see: https://github.com/actions/checkout | |
with: | |
submodules: recursive | |
fetch-depth: 1 | |
- name: Cache Hugo resources | |
uses: actions/[email protected] | |
env: | |
cache-name: cache-hugo-resources | |
with: | |
path: resources | |
key: ${{ env.cache-name }} | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v2 | |
with: | |
hugo-version: "latest" | |
extended: true | |
- name: Setup Pages | |
id: pages | |
uses: actions/[email protected] | |
- name: Build Github Pages | |
env: | |
# For maximum backward compatibility with Hugo modules | |
HUGO_ENVIRONMENT: production | |
HUGO_ENV: production | |
run: hugo --minify --gc | |
- name: Upload Github Pages Artifact | |
uses: actions/[email protected] | |
with: | |
path: ./public | |
# # Deployment to github pages | |
# deploy-to-github-pages: | |
# runs-on: ubuntu-latest | |
# needs: build | |
# permissions: | |
# pages: write | |
# id-token: write | |
# actions: read | |
# environment: | |
# name: github-pages | |
# url: ${{ steps.deployment.outputs.page_url }} | |
# steps: | |
# - name: Deploy to GitHub Pages | |
# id: deployment | |
# # see: https://github.com/actions/deploy-pages/ | |
# uses: actions/[email protected] | |
# with: | |
# artifact_name: github-pages | |
# Deploy to production | |
deploy-to-production: | |
runs-on: ubuntu-latest | |
needs: build | |
environment: | |
name: production | |
url: https://osguider.com/blog/ | |
steps: | |
- name: Download Artifact | |
# see: https://github.com/actions/download-artifact | |
uses: actions/[email protected] | |
with: | |
name: github-pages | |
path: ./public | |
- name: unArchive Artifact | |
run: | | |
ls -la --recursive | |
- name: Deploy to Production | |
id: production | |
# @see: https://github.com/easingthemes/ssh-deploy | |
uses: easingthemes/[email protected] | |
with: | |
ARGS: "-rlgoDzvc -i --delete" | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
SOURCE: "./public/*" | |
REMOTE_HOST: ${{ secrets.SSH_REMOTE_HOST }} | |
REMOTE_PORT: ${{ secrets.SSH_REMOTE_PORT }} | |
REMOTE_USER: ${{ secrets.SSH_REMOTE_USER }} | |
TARGET: ${{ secrets.SSH_REMOTE_TARGET }} | |
SCRIPT_AFTER: | | |
cd "${{ secrets.SSH_REMOTE_TARGET }}" \ | |
&& mkdir blog_new \ | |
&& tar xf artifact.tar -C blog_new/ \ | |
&& rm -rf blog \ | |
&& mv blog_new blog \ | |
&& rm -rf artifact.tar | |
# && curl -s https://osguider.com/blog/sitemap.xml | grep -oP '<loc>\K[^<]+' | head -5 | curl -H 'Content-Type:text/plain' --data-binary @- "${{ secrets.BAIDU_SITMAP_UPLOAD_URL }}" | |
push-urls-to-search-engines: | |
concurrency: | |
group: "search-engines" | |
cancel-in-progress: true | |
runs-on: ubuntu-latest | |
needs: deploy-to-production | |
steps: | |
- name: Push Urls To Search Engines | |
# see: https://github.com/actions/download-artifact | |
uses: 3Alan/[email protected] | |
with: | |
site: osguider.com | |
sitemap: https://osguider.com/blog/sitemap.xml | |
count: 10 | |
bing-token: ${{ secrets.WEBMASTER_BING_TOKEN }} | |
baidu-token: ${{ secrets.WEBMASTER_BAIDU_TOKEN }} | |
google-client-email: ${{ secrets.WEBMASTER_GOOGLE_CLIENT_EMAIL }} | |
google-private-key: ${{ secrets.WEBMASTER_GOOGLE_PRIVATE_KEY }} |