generated from mirumirumi/template-nuxt3
-
-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (128 loc) · 5.04 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
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 }}/*"