generate-only-specified-post #731
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: 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: 20.12.2 | |
- 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 != 'comment approved' | |
# Note that writes to environment variables are not reflected within the another 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 build files that include specified route files to S3 | |
# Since the Nuxt spec has changed and even if you just generate one route, the file name in _nuxt/* | |
# will change, and the static file name that other fixed pages refer to will also change, so you | |
# need to upload everything except the dynamically generated parts | |
# Note that `"*"` in exclude and include have different meanings | |
run: | | |
aws s3 sync \ | |
--delete \ | |
--region ap-northeast-1 \ | |
--exclude "*" \ | |
--include "_payload.json" \ | |
--include "200.html" \ | |
--include "404.html" \ | |
--include "index.html" \ | |
--include "${{ env.ROUTE_TO_GENERATE }}/*" \ | |
--include "about/*" \ | |
--include "category/${{ env.CATEGORY }}/**" \ | |
--include "contact/*" \ | |
--include "entries/**" \ | |
--include "entry-list/*" \ | |
--include "nice-to-meet-you-10/*" \ | |
--include "privacy-policy/*" \ | |
--include "profile/*" \ | |
--include "s/*" \ | |
--include "what-is-this-blog/*" \ | |
--cache-control "no-cache" \ | |
.output/public/ s3://mirumime-prd-mirumi-me/ | |
aws s3 sync \ | |
--region ap-northeast-1 \ | |
--cache-control "max-age=31536000" \ | |
.output/public/_nuxt/ s3://mirumime-prd-mirumi-me/_nuxt/ | |
- 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/ | |
# いま CloudFront のキャッシュパスパターンがわざわざ /_nuxt/* 用にわかれているが、もともと全部キャッシュしたいので | |
# デフォルト (*) に適用されている分だけで問題なかった、という状態になっている | |
- name: Purge CDN caches | |
run: | | |
aws cloudfront create-invalidation \ | |
--distribution-id E1UPWIMHFP5TEC \ | |
--paths "/*" \ | |
"/${{ env.ROUTE_TO_GENERATE }}/*" \ | |
"/entries/*" \ | |
"/entry-list/*" \ | |
"/category/${{ env.CATEGORY }}/*" \ | |
"/sitemap*" \ | |
"/feed*" |