Skip to content

Commit 7691149

Browse files
fix var
1 parent 90b929c commit 7691149

File tree

1 file changed

+56
-34
lines changed

1 file changed

+56
-34
lines changed

.github/workflows/generate_weights.yml

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
cancel-in-progress: true
1717

1818
env:
19-
HETZNER_TOKEN: ${{ secrets.HETZNER_API_TOKEN }}
19+
HCLOUD_TOKEN: ${{ secrets.HETZNER_API_TOKEN }}
2020

2121
steps:
2222
- uses: actions/checkout@v3
@@ -25,26 +25,39 @@ jobs:
2525
run: |
2626
git config --global url."https://${{ secrets.GH_READ_TOKEN }}:[email protected]/".insteadOf "https://github.com/"
2727
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-
3528
- name: Generate ephemeral SSH key
29+
id: sshkey
3630
run: |
3731
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+
uses: jawher/[email protected]
37+
env:
38+
HCLOUD_TOKEN: ${{ secrets.HETZNER_API_TOKEN }}
39+
with:
40+
args: ssh-key create --name weights-key --public-key "${{ env.PUBLIC_SSH }}"
3941

4042
- name: Create Hetzner Server
41-
id: create_server
43+
uses: jawher/[email protected]
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+
uses: jawher/[email protected]
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
4257
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
4861
4962
- name: Wait for SSH
5063
run: |
@@ -53,40 +66,32 @@ jobs:
5366
sleep 5
5467
done
5568
56-
- name: Run build and benchmark script remotely (inline heredoc)
69+
- name: Run benchmarks remotely
5770
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
5972
set -eux
73+
export GH_TOKEN=${{ secrets.GH_READ_TOKEN }}
74+
export BRANCH=${{ github.event.inputs.branch }}
6075
6176
apt update && apt install -y curl git build-essential jq
6277
63-
# Install Rust
6478
curl https://sh.rustup.rs -sSf | bash -s -- -y
65-
source $HOME/.cargo/env
79+
source \$HOME/.cargo/env
6680
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
7283
cd blockchain-node
73-
74-
# Build release
7584
cargo build --release --features=runtime-benchmarks
7685
77-
# Execute commands from weights.rs files
7886
find pallets -type f -name weights.rs | while read file; do
7987
echo "Processing \$file"
8088
CMD=\$(grep '// Executed command:' "\$file" | sed 's|.*// Executed command: ||')
8189
echo "Running: \$CMD"
8290
(cd "\$(dirname "\$(dirname "\$file")")" && eval "\$CMD")
8391
done
8492
EOF
85-
env:
86-
GH_TOKEN: ${{ secrets.GH_READ_TOKEN }}
87-
BRANCH: ${{ github.event.inputs.branch }}
8893
89-
- name: Download and structure weights.rs files
94+
- name: Download weights.rs files
9095
run: |
9196
mkdir -p weights
9297
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:
95100
scp -i id_rsa -o StrictHostKeyChecking=no root@$SERVER_IP:/root/blockchain-node/pallets/$dir/src/weights.rs weights/$dir/weights.rs
96101
done
97102
98-
- name: Upload weights.rs artifacts
103+
- name: Upload artifact
99104
uses: actions/upload-artifact@v4
100105
with:
101106
name: weights-files
102107
path: weights/
103108

104-
- name: Destroy Hetzner server
109+
- name: Cleanup Hetzner server and SSH key
105110
if: always()
106111
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+
uses: jawher/[email protected]
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+
uses: jawher/[email protected]
125+
if: always()
126+
env:
127+
HCLOUD_TOKEN: ${{ secrets.HETZNER_API_TOKEN }}
128+
with:
129+
args: ssh-key delete weights-key

0 commit comments

Comments
 (0)