generated from mirumirumi/template-nuxt3
-
-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (133 loc) · 5.46 KB
/
generate-only-specified-post.yaml
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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*"