Skip to content

generate-only-specified-post #670

generate-only-specified-post

generate-only-specified-post #670

name: generate-only-specified-post
on:
workflow_dispatch:
inputs:
slug:
description: The slug to generate (no `/` as prefix required)
required: true
type: string
kind:
description: "Choose from 3 kinds: `post updated`, `post created`, `comment approved`"
required: true
type: string
category:
description: The category name (slug) includes a specific post
required: false
type: string
jobs:
generate-only-specified-post:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.9.1
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Print job kind
run: echo ${{ github.event.inputs.kind }}
- name: Install dependencies
run: npm ci
- name: Install Python modules
run: pip3 install httpx
- name: Decrypt secrets with gpg
run: |
echo "${{ secrets.GPG_PASSPHRASE }}" \
| sudo gpg --batch --passphrase-fd 0 --output "src/secrets/secret.dev.js" --decrypt "src/secrets/secret.dev.js.gpg"
echo "${{ secrets.GPG_PASSPHRASE }}" \
| sudo gpg --batch --passphrase-fd 0 --output "src/secrets/secret.prd.js" --decrypt "src/secrets/secret.prd.js.gpg"
- name: Set a post to specify
run: |
echo ROUTE_TO_GENERATE=${{ github.event.inputs.slug }} >> $GITHUB_ENV
- name: Replace to ROUTE_TO_GENERATE
run: |
sed -irz "s/\/\/ ### //g" nuxt.config.ts
sed -irz "s/\[###\]/['\/${{ env.ROUTE_TO_GENERATE }}']/g" nuxt.config.ts
- name: Replace to category pages
if: github.event.inputs.kind == 'post created'
# Note that writes to environment variables are not reflected within the same step
run: |
echo CATEGORY=${{ github.event.inputs.category }} >> $GITHUB_ENV
python3 .github/workflows/sed_nuxtconfig_to_category_configs.py --category ${{ github.event.inputs.category }}
- name: Re-generate specified routes
run: |
npm run generate
- name: Generate sitemaps
if: github.event.inputs.kind != 'comment approved'
run: |
python3 .github/workflows/generate_sitemaps.py
- name: Generate feeds
if: github.event.inputs.kind != 'post updated'
run: |
python3 .github/workflows/generate_feeds.py
- name: Sign in
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ap-northeast-1
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Copy specified route files to S3
run: |
aws s3 sync \
--delete \
--region ap-northeast-1 \
--cache-control "no-cache" \
.output/public/${{ env.ROUTE_TO_GENERATE }}/ s3://mirumime-prd-mirumi-me/${{ env.ROUTE_TO_GENERATE }}/
- name: Copy indexes pages and category pages to S3
if: github.event.inputs.kind == 'post created'
run: |
aws s3 sync \
--delete \
--region ap-northeast-1 \
--exclude "*" \
--include "index.html" \
--include "_payload.js" \
--include "entries/*" \
--include "entry-list/*" \
--include "category/${{ env.CATEGORY }}/*" \
--cache-control "no-cache" \
.output/public/ s3://mirumime-prd-mirumi-me/
- name: Copy sitemaps to S3
if: github.event.inputs.kind != 'comment approved'
run: |
aws s3 sync \
--delete \
--region ap-northeast-1 \
--exclude "*" \
--include "sitemap*" \
--cache-control "no-cache" \
.output/public/ s3://mirumime-prd-mirumi-me/
- name: Copy feeds to S3
if: github.event.inputs.kind != 'post updated'
run: |
aws s3 sync \
--delete \
--region ap-northeast-1 \
--exclude "*" \
--include "feed*" \
--cache-control "no-cache" \
.output/public/ s3://mirumime-prd-mirumi-me/
# キャッシュ削除はある程度広くても問題ないのでパターンで細かく区切っていない(あとリクエスト数増やすとエラーの確率が上がってしまう)
- name: Purge CDN caches
run: |
aws cloudfront create-invalidation \
--distribution-id E1UPWIMHFP5TEC \
--paths "/${{ env.ROUTE_TO_GENERATE }}/*" \
"/index.html" \
"/_payload.js" \
"/entries/*" \
"/entry-list/*" \
"/sitemap*" \
"/feed*"
- name: Purge CDN caches for category pages
if: github.event.inputs.kind == 'post created'
run: |
aws cloudfront create-invalidation \
--distribution-id E1UPWIMHFP5TEC \
--paths "/category/${{ env.CATEGORY }}/*"