-
Notifications
You must be signed in to change notification settings - Fork 0
234 lines (199 loc) · 10.5 KB
/
publish.yml
File metadata and controls
234 lines (199 loc) · 10.5 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
name: Create and publish a Docker image
# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
push:
branches: ['main']
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Free up additional disk space on GitHub runner (~10-15 GB)
- name: Free runner disk space
run: |
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/share/boost /usr/share/swift /usr/local/lib/android /opt/hostedtoolcache || true
sudo apt-get clean
df -h
# Set up Docker Buildx for efficient layer caching
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=long
# ------------------------------------------------------------
# Build the runtime deterministically with srtool and capture
# its SHA-256 so we can inject it as an OCI label.
# ------------------------------------------------------------
- name: Build runtime with srtool & extract Wasm hash
id: wasm
run: |
set -euo pipefail
echo "🛠️ Running srtool to build compact runtime…"
# Build runtime inside srtool container (outputs verbose log to console)
docker run --rm \
-v "${PWD}":/build \
-e RUNTIME_DIR=runtime/fennel \
-e PACKAGE=fennel-node-runtime \
--workdir /build \
paritytech/srtool:1.84.1 /srtool/build
# After the container exits the compiled Wasm lives in the mounted volume
HASH=$(sha256sum runtime/fennel/target/srtool/release/wbuild/fennel-node-runtime/fennel_node_runtime.compact.wasm | awk '{print "0x"$1}')
echo "WASM_HASH=$HASH" >> $GITHUB_ENV
echo "hash=$HASH" >> $GITHUB_OUTPUT
echo "✅ Deterministic Wasm hash: $HASH"
# ------------------------------------------------------------
# Generate chain specifications using chain-spec-builder
# ------------------------------------------------------------
- name: Install jq for JSON processing
run: |
sudo apt-get update && sudo apt-get install -y jq
echo "✅ Installed jq"
- name: Install chain-spec-builder
run: |
# Create directory for chain-spec-builder
mkdir -p "${HOME}/.cargo/bin"
# Use Parity's prebuilt container that has Rust, protoc, and all dependencies
docker run --rm \
-v "${PWD}":/build \
-v "${HOME}/.cargo/bin":/cargo-bin \
--workdir /build \
paritytech/ci-unified:latest \
bash -c "
cargo install staging-chain-spec-builder --locked --root /tmp/cargo-install && \
cp /tmp/cargo-install/bin/chain-spec-builder /cargo-bin/
"
echo "✅ Installed chain-spec-builder"
# Add cargo bin to PATH for subsequent steps
echo "${HOME}/.cargo/bin" >> $GITHUB_PATH
- name: Create development chain spec
run: |
# Create chainspecs directory if it doesn't exist
mkdir -p chainspecs
# Check if the runtime has a development preset
echo "Checking available presets..."
chain-spec-builder list-presets \
--runtime runtime/fennel/target/srtool/release/wbuild/fennel-node-runtime/fennel_node_runtime.compact.wasm || true
# Use the development preset from the runtime
echo "Creating development chain spec using 'development' preset..."
chain-spec-builder create \
--runtime runtime/fennel/target/srtool/release/wbuild/fennel-node-runtime/fennel_node_runtime.compact.wasm \
named-preset development \
--output chainspecs/development.json
# Convert to raw format
echo "Converting to raw format..."
chain-spec-builder convert-to-raw chainspecs/development.json > chainspecs/development-raw.json
# Verify the specs were created
echo "✅ Generated chain specifications:"
ls -l chainspecs/
# Output the final chain spec structure
echo "Final chain spec structure:"
jq -r '.genesis.runtime | keys[]' chainspecs/development.json || true
- name: Create staging chain specs with bootnodes
run: |
# Create Staging directory for staging chainspecs
mkdir -p Staging
# Generate staging chain spec (plain) with bootnodes
echo "Generating staging chain spec with bootnodes..."
chain-spec-builder create \
--runtime runtime/fennel/target/srtool/release/wbuild/fennel-node-runtime/fennel_node_runtime.compact.wasm \
named-preset staging \
--output Staging/staging-chainspec.json
# Add bootnodes to the staging chain spec
echo "Adding bootnodes to staging chain spec..."
jq '.bootNodes = [
"/dns/fennel-bootnode-1.fennel-staging.svc.cluster.local/tcp/30333/p2p/12D3KooWDCZGrnJhsgWJtDcs6eZc1hUBrVj5QqkEWggAkNVowRAi",
"/dns/fennel-bootnode-2.fennel-staging.svc.cluster.local/tcp/30333/p2p/12D3KooWDbfFv6oepAXmQaiwFaVjD9g7AxowQ8LQdWTcVYpKhnAx"
]' Staging/staging-chainspec.json > Staging/staging-chainspec-temp.json && mv Staging/staging-chainspec-temp.json Staging/staging-chainspec.json
# Generate staging chain spec (raw) with bootnodes
echo "Generating raw staging chain spec..."
chain-spec-builder convert-to-raw Staging/staging-chainspec.json > Staging/staging-raw.json
# Verify the staging specs were created
echo "✅ Generated staging chain specifications:"
ls -la Staging/
# Show bootnode configuration in the generated specs
echo "Bootnode configuration in staging spec:"
jq -r '.bootNodes[]' Staging/staging-chainspec.json
- name: Commit staging chainspecs to repository
run: |
# Configure git
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Add the staging chainspecs
git add Staging/staging-chainspec.json Staging/staging-raw.json
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to staging chainspecs"
else
# Commit the changes
git commit -m "Update staging chainspecs with bootnodes [skip ci]"
# Push the changes back to the repository
git push origin main
echo "✅ Staging chainspecs committed and pushed to repository"
fi
- name: Upload chain specs as artifacts
uses: actions/upload-artifact@v4
with:
name: fennel-chainspecs
path: |
chainspecs/default-genesis.json
chainspecs/development-patch.json
chainspecs/development.json
chainspecs/development-raw.json
Staging/staging-chainspec.json
Staging/staging-raw.json
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
WASM_HASH=${{ env.WASM_HASH }}
cache-from: type=gha
provenance: false
# Create and upload artifact containing image info
- name: Output image info to artifact
run: |
mkdir -p ./artifacts
echo "Image name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" > ./artifacts/image-info.txt
echo "Tags: ${{ steps.meta.outputs.tags }}" >> ./artifacts/image-info.txt
echo "Wasm hash: ${{ env.WASM_HASH }}" >> ./artifacts/image-info.txt
echo "Digest: ${{ steps.build.outputs.digest }}" >> ./artifacts/image-info.txt
echo "Created: $(date -u +\"%Y-%m-%dT%H:%M:%SZ\")" >> ./artifacts/image-info.txt
- name: Upload Docker image info artifact
uses: actions/upload-artifact@v4
with:
name: fennel-node-image-info
path: ./artifacts/image-info.txt