-
Notifications
You must be signed in to change notification settings - Fork 2
162 lines (162 loc) · 7.19 KB
/
deploy-assets.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
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
153
154
155
156
157
158
159
160
161
162
name: deploy
on:
push:
branches:
- prod
- stage
paths:
- './github/workflows/deploy-assets.yml'
- './github/workflows/deploy-resources.yml'
- 'ops/deploy/deploy-resources.js'
- 'ops/deploy/deploy-sections.js'
- 'ops/deploy/deploy-documents.js'
- 'ops/deploy/deploy-categories.js'
- 'ops/deploy/deploy-authors.js'
- 'ops/deploy/deploy-languages.js'
- 'ops/sync/*.js'
- 'src/**/*.png'
- 'src/**/*.jpg'
- 'src/**/*.jpeg'
- 'src/**/*.mp3'
- 'src/**/*.mp4'
- 'src/**/*.md'
- 'src/**/*.yml'
- '!src/**/audio.yml'
- '!src/**/video.yml'
- '!src/**/pdf.yml'
jobs:
transfer-resource-assets:
if: (github.repository == 'Adventech/sabbath-school-resources')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Fetch the repository files
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- uses: actions/setup-node@v3
name: Setup Node
with:
node-version: '16'
- name: Add token for private packages
run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.PACKAGES_SECRET }}" >> .npmrc
- run: npm install --global yarn
name: Install Yarn
- run: yarn install
name: Installing dependencies
- run: gpg --quiet --batch --yes --decrypt --passphrase="$CREDS_PASSPHRASE" --output deploy-creds.tar deploy-creds.tar.gpg
env:
CREDS_PASSPHRASE: ${{ secrets.CREDS_PASSPHRASE }}
working-directory: ops/deploy/creds
- run: tar xvf deploy-creds.tar
working-directory: ops/deploy/creds
- run: aws s3 cp assets s3://sabbath-school-resources-assets.adventech.io/assets --acl "public-read" --region us-east-1 --no-progress --recursive
name: Upload global assets
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- run: find assets -mindepth 1 ! -name ".gitkeep" -exec rm -rf {} +
name: Delete global assets content
- run: aws s3 cp ./src s3://sabbath-school-resources-assets.adventech.io/ --acl "public-read" --region us-east-1 --no-progress --recursive --exclude "*" --include "**/assets/cover.png" --include "**/assets/cover-landscape.png" --include "**/assets/cover-square.png" --include "**/assets/splash.png" --include "**/assets/logo.png" --include "**/assets/fonts/*.ttf"
name: Upload resource assets
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- run: node ops/sync/transfer-resource-assets.js
name: Updating the source files with the remote urls and removing the files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEPLOY_ENV: ${{ steps.extract_branch.outputs.branch }}
- name: Reset .npmrc
run: git restore .npmrc
- name: Commit & Push changes
uses: actions-js/push@master
with:
branch: ${{ steps.extract_branch.outputs.branch }}
github_token: ${{ secrets.GITHUB_TOKEN }}
download-and-transfer-document-assets:
needs: [transfer-resource-assets]
if: (github.repository == 'Adventech/sabbath-school-resources')
runs-on: ubuntu-latest
steps:
- name: Activate Globstar
run: shopt -s globstar
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- uses: actions/checkout@v4
name: Fetch the repository files
with:
ref: ${{ steps.extract_branch.outputs.branch }}
- uses: actions/setup-node@v3
name: Setup Node
with:
node-version: '16'
- name: Add token for private packages
run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.PACKAGES_SECRET }}" >> .npmrc
- run: npm install --global yarn
name: Install Yarn
- run: yarn install
name: Installing dependencies
- run: gpg --quiet --batch --yes --decrypt --passphrase="$CREDS_PASSPHRASE" --output deploy-creds.tar deploy-creds.tar.gpg
env:
CREDS_PASSPHRASE: ${{ secrets.CREDS_PASSPHRASE }}
working-directory: ops/deploy/creds
- run: tar xvf deploy-creds.tar
working-directory: ops/deploy/creds
- run: node ops/sync/set-aspect-ratios.js
name: Set aspect ratios of images
env:
DEPLOY_ENV: ${{ steps.extract_branch.outputs.branch }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: node ops/sync/transfer-document-assets.js
name: Generate transfer commands (seds) to replace locally referenced assets with the remote URLs
env:
DEPLOY_ENV: ${{ steps.extract_branch.outputs.branch }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: test -f transfer_commands.txt && source transfer_commands.txt
name: Run transfer commands if exists
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- run: test -f transfer_commands.txt && rm transfer_commands.txt
name: Clean up
- run: mkdir download
name: Creating download directory
- run: grep -Poir '\!\[(.*?)\]\((http|https)://(?!sabbath-school)[a-zA-Z0-9./?=_%:-]*\)' --include="*.md" ./src > detected_links.txt || true
name: Finding all external links in the markdown files and saving to detected_links.txt
- run: node ops/sync/download-document-assets.js
name: Running script to generate transfer commands
env:
DEPLOY_ENV: ${{ steps.extract_branch.outputs.branch }}
- run: test -f download_commands.txt && bash download_commands.txt
name: Run download commands if exists
- run: aws s3 cp ./download s3://sabbath-school-resources-assets.adventech.io --acl "public-read" --region us-east-1 --no-progress --recursive
name: Upload all downloaded files
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- run: test -f transfer_commands.txt && source transfer_commands.txt
name: Run transfer commands if exists
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- run: test -f detected_links.txt && rm detected_links.txt
- run: test -f download_commands.txt && rm download_commands.txt
- run: test -f transfer_commands.txt && rm transfer_commands.txt
- run: rm -rf download
- name: Reset .npmrc
run: git restore .npmrc
- name: Commit & Push changes
uses: actions-js/push@master
with:
branch: ${{ steps.extract_branch.outputs.branch }}
github_token: ${{ secrets.GITHUB_TOKEN }}
call-deploy-resources:
uses: ./.github/workflows/deploy-resources.yml
needs: [transfer-resource-assets, download-and-transfer-document-assets]
with:
branch: ${{ github.ref_name }}
secrets: inherit