-
Notifications
You must be signed in to change notification settings - Fork 8
110 lines (93 loc) · 3.59 KB
/
sync-build-cache.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
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
name: Sync build cache
permissions:
actions: write
contents: read
on:
schedule:
- cron: '0 22 * * *'
workflow_dispatch:
env:
NODE_OPTIONS: '--max-old-space-size=8192'
concurrency:
group: sync-build-cache
cancel-in-progress: false
jobs:
validate-master-cache:
runs-on: ubuntu-latest
steps:
- name: Checkout to repo
uses: actions/checkout@v3
with:
ref: master
- name: Setup node
uses: actions/setup-node@v2
- name: Get cached dependencies
id: cache-npm
uses: actions/cache/restore@v3
with:
path: node_modules
key: npm-${{ hashFiles('**/package-lock.json') }}
- name: Create npmrc file
shell: bash
run: echo "@deriv-com:registry=https://npm.pkg.github.com" >> .npmrc
- name: Setup install read-only token for deriv-com org
shell: bash
run: echo '//npm.pkg.github.com/:_authToken=${{ secrets.READ_DERIV_COM_ORG_PACKAGES }}' >> .npmrc
- name: Install dependencies
if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
run: npm ci
- name: Save cached dependencies
if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v3
with:
key: ${{ steps.cache-npm.outputs.cache-primary-key }}
path: node_modules
- name: Get master cache
id: restore-master-cache
uses: actions/cache/restore@v3
with:
key: master-cache-public
path: |
.cache
public
- name: Clear master cache
if: ${{ steps.restore-master-cache.outputs.cache-hit == 'true' }}
run: |
owner="binary-com"
repo="deriv-com"
cache_key="${{ steps.restore-master-cache.outputs.cache-matched-key }}"
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/$owner/$repo/actions/caches?key=$cache_key
- name: Rebuild master cache
id: build-cache
run: npm run build
- name: Save master cache
if: ${{ steps.build-cache.outcome == 'success' }}
uses: actions/cache/save@v3
with:
key: master-cache-public
path: |
.cache
public
- name: Clear backup cache
if: ${{ steps.build-cache.outcome == 'success' }}
run: |
owner="binary-com"
repo="deriv-com"
cache_key="master-cache-public-replica"
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/$owner/$repo/actions/caches?key=$cache_key
- name: Sync backup cache with master cache
if: ${{ steps.build-cache.outcome == 'success' }}
uses: actions/cache/save@v3
with:
key: master-cache-public-replica
path: |
.cache
public