-
Notifications
You must be signed in to change notification settings - Fork 0
37 lines (34 loc) · 1.75 KB
/
netlify-clear-cache-deploy.yml
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
name: 'Clear cache and deploy site on Netlify'
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: main branch
# mainブランチで実行されている場合は、NetlifyのキャッシュをクリアしてデプロイするAPIを叩く
if: github.ref_name == 'main'
run: |
echo "Request main branch build and deploy without cache"
curl -X POST https://api.netlify.com/api/v1/sites/${{ secrets.NETLIFY_SITE_ID }}/builds \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.NETLIFY_AUTH_TOKEN }}" \
-d '{"clear_cache": true}'
- name: not in main branch
# mainブランチ以外では、そのブランチでの最新デプロイのIDを取得してから、
# そのデプロイをキャッシュなしでリトライするAPIを叩く
if: github.ref_name != 'main'
run: |
response=$(curl https://api.netlify.com/api/v1/sites/${{ secrets.NETLIFY_SITE_ID }}/deploys?per_page=1\&branch=${{ github.ref_name }} \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.NETLIFY_AUTH_TOKEN }}")
deploy_id=$(echo $response | jq -r '.[0].id')
if [ "$deploy_id" == 'null' ]; then
echo "deploy_id for ${{ github.ref_name }} branch not found";
exit;
fi
echo "Request retrying deploy without cache. branch_name: ${{ github.ref_name }} deploy_id: $deploy_id"
curl -X POST https://api.netlify.com/api/v1/deploys/$deploy_id/retry \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.NETLIFY_AUTH_TOKEN }}" \
-d '{"clear_cache": true}'