16
16
cancel-in-progress : true
17
17
18
18
env :
19
- HETZNER_TOKEN : ${{ secrets.HETZNER_API_TOKEN }}
19
+ HCLOUD_TOKEN : ${{ secrets.HETZNER_API_TOKEN }}
20
20
21
21
steps :
22
22
- uses : actions/checkout@v3
@@ -25,26 +25,39 @@ jobs:
25
25
run : |
26
26
git config --global url."https://${{ secrets.GH_READ_TOKEN }}:[email protected] /".insteadOf "https://github.com/"
27
27
28
- - name : Install Hetzner CLI & jq
29
- run : |
30
- curl -LO https://github.com/hetznercloud/cli/releases/download/v1.36.0/hcloud-linux-amd64.tar.gz
31
- tar -xzf hcloud-linux-amd64.tar.gz
32
- sudo mv hcloud /usr/local/bin
33
- sudo apt-get install -y jq
34
-
35
28
- name : Generate ephemeral SSH key
29
+ id : sshkey
36
30
run : |
37
31
ssh-keygen -t ed25519 -N "" -f id_rsa
38
- cat id_rsa.pub
32
+ echo "PRIVATE_SSH=$(base64 -w 0 id_rsa)" >> $GITHUB_ENV
33
+ echo "PUBLIC_SSH=$(cat id_rsa.pub)" >> $GITHUB_ENV
34
+
35
+ - name : Upload SSH key to Hetzner
36
+
37
+ env :
38
+ HCLOUD_TOKEN : ${{ secrets.HETZNER_API_TOKEN }}
39
+ with :
40
+ args : ssh-key create --name weights-key --public-key "${{ env.PUBLIC_SSH }}"
39
41
40
42
- name : Create Hetzner Server
41
- id : create_server
43
+
44
+ env :
45
+ HCLOUD_TOKEN : ${{ secrets.HETZNER_API_TOKEN }}
46
+ with :
47
+ args : server create --name weights-${{ github.run_id }} --type=cpx31 --image=ubuntu-22.04 --ssh-key=weights-key --location=fsn1
48
+
49
+ - name : Fetch server IP
50
+
51
+ env :
52
+ HCLOUD_TOKEN : ${{ secrets.HETZNER_API_TOKEN }}
53
+ with :
54
+ args : server describe weights-${{ github.run_id }} -o json
55
+
56
+ - name : Extract IP and prepare SSH
42
57
run : |
43
- SERVER_NAME="weights-$(date +%s)"
44
- hcloud context create default <<< "$HETZNER_TOKEN"
45
- hcloud server create --name "$SERVER_NAME" --type cx31 --image ubuntu-22.04 --ssh-key "$(cat id_rsa.pub)" --wait --format json > server.json
46
- echo "SERVER_IP=$(jq -r '.[0].public_net.ipv4.ip' server.json)" >> $GITHUB_ENV
47
- echo "SERVER_ID=$(jq -r '.[0].id' server.json)" >> $GITHUB_ENV
58
+ echo "SERVER_IP=$(cat ${GITHUB_WORKSPACE}/hcloud.output | jq -r '.public_net.ipv4.ip')" >> $GITHUB_ENV
59
+ echo "$PRIVATE_SSH" | base64 -d > id_rsa
60
+ chmod 600 id_rsa
48
61
49
62
- name : Wait for SSH
50
63
run : |
@@ -53,40 +66,32 @@ jobs:
53
66
sleep 5
54
67
done
55
68
56
- - name : Run build and benchmark script remotely (inline heredoc)
69
+ - name : Run benchmarks remotely
57
70
run : |
58
- ssh -i id_rsa -o StrictHostKeyChecking=no root@$SERVER_IP ' bash -s' <<' EOF'
71
+ ssh -i id_rsa -o StrictHostKeyChecking=no root@$SERVER_IP " bash -s" <<EOF
59
72
set -eux
73
+ export GH_TOKEN=${{ secrets.GH_READ_TOKEN }}
74
+ export BRANCH=${{ github.event.inputs.branch }}
60
75
61
76
apt update && apt install -y curl git build-essential jq
62
77
63
- # Install Rust
64
78
curl https://sh.rustup.rs -sSf | bash -s -- -y
65
- source $HOME/.cargo/env
79
+ source \ $HOME/.cargo/env
66
80
67
- # Configure GitHub token for private deps
68
- git config --global url."https://${GH_TOKEN}:[email protected] /".insteadOf "https://github.com/"
69
-
70
- # Clone the repo
71
- git clone --branch "$BRANCH" --single-branch https://github.com/Cerebellum-Network/blockchain-node.git
81
+ git config --global url."https://\${GH_TOKEN}:[email protected] /".insteadOf "https://github.com/"
82
+ git clone --branch "\$BRANCH" --single-branch https://github.com/Cerebellum-Network/blockchain-node.git
72
83
cd blockchain-node
73
-
74
- # Build release
75
84
cargo build --release --features=runtime-benchmarks
76
85
77
- # Execute commands from weights.rs files
78
86
find pallets -type f -name weights.rs | while read file; do
79
87
echo "Processing \$file"
80
88
CMD=\$(grep '// Executed command:' "\$file" | sed 's|.*// Executed command: ||')
81
89
echo "Running: \$CMD"
82
90
(cd "\$(dirname "\$(dirname "\$file")")" && eval "\$CMD")
83
91
done
84
92
EOF
85
- env :
86
- GH_TOKEN : ${{ secrets.GH_READ_TOKEN }}
87
- BRANCH : ${{ github.event.inputs.branch }}
88
93
89
- - name : Download and structure weights.rs files
94
+ - name : Download weights.rs files
90
95
run : |
91
96
mkdir -p weights
92
97
PALLET_DIRS=$(ssh -i id_rsa -o StrictHostKeyChecking=no root@$SERVER_IP "find /root/blockchain-node/pallets -type f -name weights.rs | sed 's|/root/blockchain-node/pallets/||' | sed 's|/src/weights.rs||'")
@@ -95,13 +100,30 @@ jobs:
95
100
scp -i id_rsa -o StrictHostKeyChecking=no root@$SERVER_IP:/root/blockchain-node/pallets/$dir/src/weights.rs weights/$dir/weights.rs
96
101
done
97
102
98
- - name : Upload weights.rs artifacts
103
+ - name : Upload artifact
99
104
uses : actions/upload-artifact@v4
100
105
with :
101
106
name : weights-files
102
107
path : weights/
103
108
104
- - name : Destroy Hetzner server
109
+ - name : Cleanup Hetzner server and SSH key
105
110
if : always()
106
111
run : |
107
- hcloud server delete --yes $SERVER_ID
112
+ echo "Destroying server weights-${{ github.run_id }}"
113
+ shell : bash
114
+
115
+ - name : Delete Hetzner server
116
+
117
+ if : always()
118
+ env :
119
+ HCLOUD_TOKEN : ${{ secrets.HETZNER_API_TOKEN }}
120
+ with :
121
+ args : server delete weights-${{ github.run_id }}
122
+
123
+ - name : Delete Hetzner SSH key
124
+
125
+ if : always()
126
+ env :
127
+ HCLOUD_TOKEN : ${{ secrets.HETZNER_API_TOKEN }}
128
+ with :
129
+ args : ssh-key delete weights-key
0 commit comments