Skip to content

Commit 5e16653

Browse files
committed
feat: add GHA workflow for mainnet builds
1 parent 435c6bc commit 5e16653

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Build Mainnet
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build-and-deploy:
10+
name: Build and deploy
11+
runs-on: ubuntu-latest
12+
env:
13+
SSH_PORT: ${{ secrets.FILESERVER_SSH_PORT != '' && secrets.FILESERVER_SSH_PORT || '22' }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 18
22+
cache: npm
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Build TypeScript
28+
run: npm run mainnet:build:src
29+
30+
- name: Build binaries
31+
run: |
32+
targets="node18-linux-x64,node18-linux-arm64,node18-macos-x64,node18-macos-arm64,node18-win-x64,node18-win-arm64"
33+
npx pkg out/src/main-mainnet.js -t $targets --output bin/edge
34+
35+
- name: Get version
36+
id: version
37+
run: echo "version=$(node -p 'require("./package.json").version')" >> "$GITHUB_OUTPUT"
38+
39+
- name: Prepare artifacts
40+
env:
41+
VERSION: ${{ steps.version.outputs.version }}
42+
run: |
43+
declare -A binaries=(
44+
["linux/x64"]="edge-linux-x64"
45+
["linux/arm64"]="edge-linux-arm64"
46+
["macos/x64"]="edge-macos-x64"
47+
["macos/arm64"]="edge-macos-arm64"
48+
["win/x64"]="edge-win-x64.exe"
49+
["win/arm64"]="edge-win-arm64.exe"
50+
)
51+
52+
for combo in "${!binaries[@]}"; do
53+
platform="${combo%%/*}"
54+
arch="${combo##*/}"
55+
binary="${binaries[$combo]}"
56+
bin_name="edge"
57+
if [[ "$platform" == "win" ]]; then
58+
bin_name="edge.exe"
59+
fi
60+
61+
dir="dist/${platform}/${arch}/${VERSION}"
62+
mkdir -p "$dir"
63+
64+
cp "bin/${binary}" "${dir}/${bin_name}"
65+
sha256sum "${dir}/${bin_name}" | awk '{print $1}' > "${dir}/checksum"
66+
echo "$VERSION" > "${dir}/version"
67+
done
68+
69+
- name: Deploy to fileserver
70+
env:
71+
SSH_KEY: ${{ secrets.FILESERVER_SSH_KEY }}
72+
SSH_HOST: ${{ secrets.FILESERVER_HOST }}
73+
SSH_USER: ${{ secrets.FILESERVER_SSH_USER }}
74+
BASE_PATH: ${{ secrets.FILESERVER_PATH }}
75+
VERSION: ${{ steps.version.outputs.version }}
76+
run: |
77+
mkdir -p ~/.ssh
78+
echo "$SSH_KEY" > ~/.ssh/deploy_key
79+
chmod 600 ~/.ssh/deploy_key
80+
ssh-keyscan -p "$SSH_PORT" "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null
81+
82+
for platform in linux macos win; do
83+
for arch in x64 arm64; do
84+
remote_dir="${BASE_PATH}/cli/mainnet/${platform}/${arch}"
85+
86+
ssh -i ~/.ssh/deploy_key -p "$SSH_PORT" -o StrictHostKeyChecking=accept-new \
87+
"${SSH_USER}@${SSH_HOST}" "mkdir -p ${remote_dir}/${VERSION}"
88+
89+
scp -i ~/.ssh/deploy_key -P "$SSH_PORT" -o StrictHostKeyChecking=accept-new \
90+
dist/${platform}/${arch}/${VERSION}/* \
91+
"${SSH_USER}@${SSH_HOST}:${remote_dir}/${VERSION}/"
92+
93+
ssh -i ~/.ssh/deploy_key -p "$SSH_PORT" -o StrictHostKeyChecking=accept-new \
94+
"${SSH_USER}@${SSH_HOST}" "cd ${remote_dir} && rm -rf latest && cp -r ${VERSION} latest"
95+
done
96+
done
97+
98+
rm -f ~/.ssh/deploy_key

0 commit comments

Comments
 (0)