-
Notifications
You must be signed in to change notification settings - Fork 67
171 lines (141 loc) Β· 4.72 KB
/
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
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
163
164
165
166
167
168
169
170
171
name: π₯ Build & Deploy Cookbook
on:
pull_request:
branches:
- main
paths:
- "src/**"
push:
branches:
- main
paths:
- "src/**"
# Perform a release using a workflow dispatch
workflow_dispatch:
defaults:
run:
shell: bash
jobs:
# Run the build as part of PRs to confirm the site properly builds
build:
if: ${{ startsWith(github.ref, 'refs/pull/') }}
runs-on: ubuntu-latest
steps:
- name: β¬οΈ Checkout repo
uses: actions/checkout@v3
- name: β Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn
- name: π₯ Download deps
run: |
yarn
- name: π Build Docs
run: |
yarn build
# Build and deploy the artifacts to Arweave via ArDrive
deploy:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these deployments to complete.
concurrency:
group: deploy
cancel-in-progress: false
steps:
- name: β¬οΈ Checkout repo
uses: actions/checkout@v3
- name: β Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn
- name: π₯ Download deps
run: |
yarn
- name: π Env
run: |
echo "Event name: ${{ github.event_name }}"
echo "Git ref: ${{ github.ref }}"
echo "GH actor: ${{ github.actor }}"
echo "SHA: ${{ github.sha }}"
VER=`node --version`; echo "Node ver: $VER"
VER=`npm --version`; echo "npm ver: $VER"
VER=`deno --version`; echo "deno ver: $VER"
- name: π¬ Decode Wallet JSON File
uses: timheuer/base64-to-file@v1
id: wallet_file
with:
fileName: wallet.json
encodedString: ${{ secrets.CI_WALLET }}
- name: π Build Docs
id: build_artifacts
run: |
yarn build
touch src/.vitepress/dist/.nojekyll
ARTIFACTS_HASH=$(sha256sum src/.vitepress/dist/hashmap.json | awk '{ print $1 }')
echo "artifacts_output_dir=src/.vitepress/dist" >> $GITHUB_OUTPUT
echo "artifacts_hash=${ARTIFACTS_HASH}"
- name: Install ArDrive CLI
run: |
npm i -g ardrive-cli@2
- name: πΎ Publish to Arweave
id: publish_artifacts
#
# Use the ArDrive CLI to:
# - create a new folder in the ao Cookbook Artifacts Drive
# - upload artifacts to that folder
# - create a manifest of the folder
#
run: |
echo "Creating folder for artifacts on ArDrive..."
ARDRIVE_FOLDER_RESULT=$(\
ardrive create-folder \
--turbo \
--parent-folder-id "${ARDRIVE_FOLDER_ID}" \
--folder-name "${ARTIFACTS_HASH}" \
-w "${WALLET}"
)
echo "${ARDRIVE_FOLDER_RESULT}"
FOLDER_ID=$(\
echo "${ARDRIVE_FOLDER_RESULT}" \
| jq -r '.created[0].entityId'
)
until ardrive folder-info \
--folder-id \
"${FOLDER_ID}"; do
echo "ArDrive folder has not yet synced. Sleeping for 2 seconds..."
sleep 2
done
echo "Uploading Artifacts..."
ardrive upload-file \
--turbo \
--parent-folder-id "${FOLDER_ID}" \
--local-paths "${ARTIFACTS_OUTPUT_DIR}"/* \
-w "${WALLET}"
until [[ $(ardrive list-folder \
--parent-folder-id "${FOLDER_ID}" \
| jq 'length') -gt 0 ]]; do
echo "ArDrive folder artifacts have not yet synced. Sleeping for 2 seconds..."
sleep 2
done
echo "Generating Manifest..."
ARDRIVE_MANIFEST_RESULTS=$(\
ardrive create-manifest \
--turbo \
-f "${FOLDER_ID}" \
-w "${WALLET}"
)
echo "${ARDRIVE_MANIFEST_RESULTS}"
MANIFEST_TRANSACTION_ID=$(\
echo "${ARDRIVE_MANIFEST_RESULTS}" \
| jq -r '.created[0].dataTxId'
)
echo "folder_id=${FOLDER_ID}" >> $GITHUB_OUTPUT
echo "tx_id=${MANIFEST_TRANSACTION_ID}" >> $GITHUB_OUTPUT
env:
WALLET: ${{ steps.wallet_file.outputs.filePath }}
ARTIFACTS_HASH: ${{ steps.build_artifacts.outputs.artifacts_hash }}
ARTIFACTS_OUTPUT_DIR: ${{ steps.build_artifacts.outputs.artifacts_output_dir }}
ARDRIVE_FOLDER_ID: ${{ secrets.CLI_ARDRIVE_FOLDER_ID }}