-
-
Notifications
You must be signed in to change notification settings - Fork 3
200 lines (168 loc) · 7.3 KB
/
build.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Build and Deploy
on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]
release:
types: [published]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
packages: write
jobs:
# deploy docker to github registry
deployDocker:
if: github.event_name == 'release' && !github.event.release.prerelease
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to GitHub Packages
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deployPackage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build
run: |
bash build.sh
# Deploy to GitHub action artifacts
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: anser-static-snapshot
path: "./dist/"
# Deploy to GitHub Releases
- name: Compress dist
if: github.event_name == 'release'
run: |
cd dist
zip -r ../anser-static-deploy.zip .
cd ..
- name: Deploy to release branch
if: github.event_name == 'release'
run: |
# Commit the changes
git config --global user.name "Github Actions"
git config --global user.email "[email protected]"
git clone --single-branch --branch "releases" https://github.com/${GITHUB_REPOSITORY} releases
version="`if [[ $GITHUB_REF == refs\/tags* ]]; then echo ${GITHUB_REF//refs\/tags\//}; fi`"
cd releases
mkdir -p ${version}
mkdir -p latest
cp -f ../dist/lib/liquidwallet.lib.js ${version}/liquidwallet.lib.js
cp -f ../dist/lib/liquidwallet.lib.js latest/liquidwallet.lib.js
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git add . || true
git commit -m "update ${version}" || true
git push origin releases || true
- name: Deploy to GitHub Releases
if: github.event_name == 'release'
run: |
set -e
echo "${GITHUB_EVENT_PATH}"
cat ${GITHUB_EVENT_PATH}
releaseId=$(jq --raw-output '.release.id' ${GITHUB_EVENT_PATH})
echo "Upload to release $releaseId"
filename="./anser-static-deploy.zip"
url="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/$releaseId/assets?name=$(basename $filename)"
echo "Upload to $url"
curl -L \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/zip" \
--data-binary @"$filename" \
"$url"
filename="./dist/lib/liquidwallet.lib.js"
url="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/$releaseId/assets?name=$(basename $filename)"
echo "Upload to $url"
curl -L \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/javascript" \
--data-binary @"$filename" \
"$url"
deployWWW:
concurrency: ci-${{ github.ref }}
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
if: github.event_name == 'release' && !github.event.release.prerelease
uses: actions/configure-pages@v4
- name: Build
run: |
bash build.sh
- name: Upload artifact
if: github.event_name == 'release' && !github.event.release.prerelease
uses: actions/upload-pages-artifact@v3
with:
path: "./dist/"
- name: Deploy to GitHub Pages
id: deployment
if: github.event_name == 'release' && !github.event.release.prerelease
uses: actions/deploy-pages@v4
- name: Prepare Node 18
uses: actions/setup-node@v2
with:
node-version: 18
- name: Deploy to surge.sh
uses: dswistowski/surge-sh-action@v1
with:
domain: "anser-snapshot.surge.sh"
project: "./dist/"
login: ${{ secrets.SURGE_LOGIN }}
token: ${{ secrets.SURGE_TOKEN }}
- name: Upload to ipfs
if: github.event_name == 'release'
run: |
npm install -g @web3-storage/w3cli
mkdir -p /home/runner/.config/w3access
echo '${{secrets.W3_ACCESS}}' > ~/.config/w3access/w3cli.json
w3 space use anser
w3 up ./dist/ --json > ipfs.json
cid=$(jq -r '.root["/"]' ipfs.json)
echo "$cid" > deploy.log
cat deploy.log
- name: Write ipfs link to release description
if: github.event_name == 'release'
run: |
set -e
echo "${GITHUB_EVENT_PATH}"
cat ${GITHUB_EVENT_PATH}
releaseId=$(jq --raw-output '.release.id' ${GITHUB_EVENT_PATH})
cid=`cat deploy.log`
deployLink="IPfs deployment:\n - ipfs://${cid}\n\nWWW gateway:\n - https://${cid}.ipfs.cf-ipfs.com"
echo $deployLink
# Add to release description
curl -X PATCH \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/$releaseId \
-d "{\"body\": \"${deployLink}\"}"