Build and Publish to GHCR Public Repository #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |