-
Notifications
You must be signed in to change notification settings - Fork 10
133 lines (119 loc) · 4.8 KB
/
ghcr.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
name: Build and Publish to GHCR Public Repository
on:
workflow_dispatch:
inputs:
commit_sha:
description: 'Commit SHA to build from'
required: true
type: string
publish_to_ghcr:
description: "Publish to GitHub Container Registry"
default: true
type: boolean
ghcr_tag:
description: "Tag for GHCR image"
required: true
type: string
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.commit_sha }}
- name: Setup Earthly
uses: ./.github/earthly-setup
with:
ssh_key: ${{ secrets.SUBSTRATE_REPO_SSH_KEY }}
config_tar: ${{ secrets.EARTHLY_TAR }}
- name: Build and Benchmark
env:
EARTHLY_CI: true
run: |
export EARTHLY_OUTPUT=true
earthly -P +build --PROFILE=production --FEATURES=runtime-benchmarks
- name: Generate and Extract Weights
continue-on-error: true
run: |
repository_name="${GITHUB_REPOSITORY##*/}"
echo "Listing contents on the runner host in /home/runner/work/${repository_name}/${repository_name}:"
ls -la /home/runner/work/${repository_name}/${repository_name}
echo "Pulling Docker image..."
docker pull ubuntu:22.04
mkdir -p weights
echo "Running Docker container..."
docker run -d --name weight_generation \
--memory=4096m \
--cpus=1 \
-v /home/runner/work/${repository_name}/${repository_name}:/workspace \
ubuntu:22.04 \
/bin/bash -c "sleep infinity"
echo "Installing necessary packages inside the container..."
docker exec weight_generation bash -c "\
apt-get update && \
apt-get install -y jq curl build-essential && \
echo 'Checking files in workspace...' && \
ls -la /workspace && \
mkdir -p /workspace/target/production && \
cp /workspace/sidechains-substrate-node /workspace/target/production/sidechains-substrate-node && \
echo 'Verifying the binary is in the expected path...' && \
ls -la /workspace/target/production && \
cd /workspace && \
echo 'Setting the current working directory to /workspace...' && \
chmod +x scripts/run_all_pallet_overhead_and_machine_benchmarks.sh && \
chmod +x scripts/run_storage_benchmarks.sh && \
source .envrc || true && \
./scripts/run_all_pallet_overhead_and_machine_benchmarks.sh -b && \
./scripts/run_storage_benchmarks.sh -b || true"
echo "Finding and copying weight files..."
weight_files=$(docker exec weight_generation find /workspace/runtime/src/weights -name '*.rs')
echo "$weight_files" | while read weight_file; do
weight_file_name=$(basename "$weight_file")
echo "Copying ${weight_file_name}"
docker cp "weight_generation:$weight_file" "weights/${weight_file_name}"
done
docker stop weight_generation
docker rm weight_generation
- name: Overwrite Weights in Runtime Directory
continue-on-error: true
run: |
sudo chmod -R a+rwx ./runtime/src/weights
for weight_file in weights/*.rs
do
cp "$weight_file" "./runtime/src/weights/$(basename "$weight_file")"
done
- name: Main Build
if: ${{ inputs.publish_to_ghcr }}
env:
EARTHLY_CI: true
EARTHLY_PUSH: false
EARTHLY_OUTPUT: true
run: earthly -P +docker --image="ghcr-image" --tags="latest"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: true
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
FORCE_COLOR: 1
- name: Tag and Push Image to GHCR
run: |
repository_name="${GITHUB_REPOSITORY##*/}"
target_image="ghcr.io/${{ github.repository }}/$repository_name-node"
commit_sha="${{ github.event.inputs.commit_sha }}"
custom_tag="${{ inputs.ghcr_tag }}"
docker tag ghcr-image:latest $target_image:latest
docker tag ghcr-image:latest $target_image:$commit_sha
docker tag ghcr-image:latest $target_image:$custom_tag
docker push $target_image:latest
docker push $target_image:$commit_sha
docker push $target_image:$custom_tag