Skip to content

Threading improvements #129

Threading improvements

Threading improvements #129

name: Quantus - Release Tag & Publish
on:
pull_request:
types: [closed]
branches:
- main
jobs:
create-tag:
name: Create Tag
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release-proposal')
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.extract_version.outputs.version }}
is_draft: ${{ steps.extract_version.outputs.is_draft }}
is_runtime_upgrade: ${{ steps.detect_upgrade.outputs.is_runtime_upgrade }}
release_branch: ${{ steps.extract_version.outputs.release_branch }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from PR title
id: extract_version
run: |
# Extract version from PR title (format: "ci: Automate version bump to vX.Y.Z")
VERSION=$(echo "${{ github.event.pull_request.title }}" | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+\(-[a-zA-Z0-9]\+\)*')
if [ -z "$VERSION" ]; then
echo "Error: Could not extract version from PR title: ${{ github.event.pull_request.title }}"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Check if this is a draft release
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'draft-release') }}" == "true" ]]; then
echo "is_draft=true" >> $GITHUB_OUTPUT
echo "release_branch=main" >> $GITHUB_OUTPUT
else
echo "is_draft=false" >> $GITHUB_OUTPUT
echo "release_branch=release/$VERSION" >> $GITHUB_OUTPUT
fi
echo "Extracted version: $VERSION"
- name: Detect runtime upgrade
id: detect_upgrade
run: |
# If version contains a dash after the numbers, it's a runtime upgrade
if [[ "${{ steps.extract_version.outputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-[a-zA-Z0-9] ]]; then
echo "is_runtime_upgrade=true" >> $GITHUB_OUTPUT
else
echo "is_runtime_upgrade=false" >> $GITHUB_OUTPUT
fi
- name: Create and push tag
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git tag -a "${{ steps.extract_version.outputs.version }}" -m "Automate release for ${{ steps.extract_version.outputs.version }}"
git push origin "${{ steps.extract_version.outputs.version }}"
build-and-release:
name: Build & Release
needs: create-tag
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-15-intel
- target: x86_64-pc-windows-msvc
os: windows-latest
steps:
- name: Checkout code at tag
uses: actions/checkout@v4
with:
ref: ${{ needs.create-tag.outputs.version }}
- name: Setup Ubuntu
if: runner.os == 'Linux'
uses: ./.github/actions/ubuntu
- name: Setup macOS
if: runner.os == 'macOS'
uses: ./.github/actions/macos
- name: Setup Windows
if: runner.os == 'Windows'
uses: ./.github/actions/windows
- name: Build quantus-node binary
shell: bash
run: |
set -eo pipefail
cargo build --release --package quantus-node --target ${{ matrix.target }}
- name: Prepare Release Assets
id: prepare_assets
env:
NEW_VERSION: ${{ needs.create-tag.outputs.version }}
TARGET_ARCH: ${{ matrix.target }}
shell: bash
run: |
NODE_BASE_NAME="quantus-node"
if [[ "${{ runner.os }}" == "Windows" ]]; then
NODE_EXECUTABLE_NAME="${NODE_BASE_NAME}.exe"
ARCHIVE_EXTENSION="zip"
asset_name="${NODE_BASE_NAME}-${NEW_VERSION}-${TARGET_ARCH}.${ARCHIVE_EXTENSION}"
checksum_file_name="sha256sums-${NEW_VERSION}-${TARGET_ARCH}.txt"
CHSUM_EXEC="powershell -Command \"(Get-FileHash -Algorithm SHA256 '${asset_name}').Hash.ToLower() + ' *${asset_name}' | Set-Content -Encoding ascii '${checksum_file_name}'\""
ARCHIVE_EXEC="powershell -Command \"Compress-Archive -Path staging/${NODE_EXECUTABLE_NAME} -DestinationPath ${asset_name}\""
mkdir -p staging
cp "target/${TARGET_ARCH}/release/${NODE_EXECUTABLE_NAME}" "staging/"
eval "$ARCHIVE_EXEC"
eval "$CHSUM_EXEC"
else
NODE_BINARY_NAME="quantus-node"
asset_name="${NODE_BINARY_NAME}-${NEW_VERSION}-${TARGET_ARCH}.tar.gz"
checksum_file_name="sha256sums-${NEW_VERSION}-${TARGET_ARCH}.txt"
mkdir staging
cp target/${TARGET_ARCH}/release/${NODE_BINARY_NAME} staging/
(cd staging && tar -czvf "../${asset_name}" ${NODE_BINARY_NAME})
if [[ "${{ runner.os }}" == "macOS" ]]; then
shasum -a 256 "${asset_name}" > "${checksum_file_name}"
else
sha256sum "${asset_name}" > "${checksum_file_name}"
fi
fi
echo "Created asset: ${asset_name}"
echo "Created checksum file: ${checksum_file_name}"
asset_paths_json="[\"${asset_name}\", \"${checksum_file_name}\"]"
echo "release_assets_json=${asset_paths_json}" >> $GITHUB_OUTPUT
ls -la
- name: Upload Release Assets as Artifacts
uses: actions/upload-artifact@v4
with:
name: release-assets-${{ matrix.target }}
path: |
quantus-node-${{ needs.create-tag.outputs.version }}-${{ matrix.target }}.${{ runner.os == 'Windows' && 'zip' || 'tar.gz' }}
sha256sums-${{ needs.create-tag.outputs.version }}-${{ matrix.target }}.txt
build-runtime:
name: Build Runtime (srtool)
if: needs.create-tag.outputs.is_runtime_upgrade == 'true'
needs: create-tag
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.create-tag.outputs.version }}
fetch-depth: 0
fetch-tags: true
- name: cache target dir
uses: actions/cache@v4
with:
path: "$GITHUB_WORKSPACE/runtime/target"
key: srtool-target-${{ github.sha }}
restore-keys: |
srtool-target-
- name: build runtime
id: srtool-build
shell: bash
run: |
set -eo pipefail
JSON_OUTPUT=$(docker run --rm \
-e RUSTC_BOOTSTRAP=1 \
-e RUSTC_VERSION="1.86.0" \
-e PACKAGE="quantus-runtime" \
-e RUNTIME_DIR="runtime" \
-e "BUILD_OPTS=--features on-chain-release-build" \
-e PROFILE="release" \
-v "$(pwd):/build" \
-v "/tmp/cargo:/cargo-home" \
paritytech/srtool:1.88.0 \
build --app --json -cM \
| tee /dev/stderr | tail -n 1)
if ! echo "$JSON_OUTPUT" | jq .; then
echo "::error::Failed to parse srtool JSON output. Last line was: $JSON_OUTPUT"
exit 1
fi
echo "$JSON_OUTPUT" | jq > srtool-output.json
WASM_PATH=$(echo "$JSON_OUTPUT" | jq -r '.runtimes.compact.wasm')
WASM_COMPRESSED_PATH=$(echo "$JSON_OUTPUT" | jq -r '.runtimes.compressed.wasm')
runtime_ver=$(echo "$JSON_OUTPUT" | jq -r '.runtimes.compact.subwasm.core_version.specVersion')
cp "$WASM_PATH" quantus-runtime-v${runtime_ver}.compact.wasm
cp "$WASM_COMPRESSED_PATH" quantus-runtime-v${runtime_ver}.compact.compressed.wasm
cp srtool-output.json quantus-runtime-srtool-output-v${runtime_ver}.json
- name: Upload runtime artifacts
uses: actions/upload-artifact@v4
with:
name: runtime
path: |
quantus-runtime-v*.wasm
quantus-runtime-srtool-output-v*.json
create-github-release:
name: 🚀 Create GitHub Release
needs: [create-tag, build-and-release, build-runtime]
if: always() && needs.build-and-release.result == 'success' && (needs.build-runtime.result == 'success' || needs.build-runtime.result == 'skipped')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.create-tag.outputs.version }}
fetch-depth: 0
fetch-tags: true
- name: Download all release assets
uses: actions/download-artifact@v4
with:
path: downloaded-artifacts
- name: Generate asset list file
run: |
echo "--- Directory structure of downloaded-artifacts ---"
ls -R downloaded-artifacts
echo "--- Finding asset files ---"
find downloaded-artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" -o -name "*.txt" \) -print0 > asset_files.txt
cat asset_files.txt | xargs -0 -n1
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_VERSION: ${{ needs.create-tag.outputs.version }}
run: |
release_notes="Automated release for version $NEW_VERSION."
printf "%s" "$release_notes" > release_notes.txt
asset_args=()
while IFS= read -r -d $'\0' file; do
asset_args+=("$file")
done < asset_files.txt
# Add runtime files if this is a runtime upgrade
if [[ "${{ needs.create-tag.outputs.is_runtime_upgrade }}" == "true" ]]; then
compact_wasm_path=$(find . -name "quantus-runtime-v*.compact.wasm" -type f)
compressed_wasm_path=$(find . -name "quantus-runtime-v*.compact.compressed.wasm" -type f)
srtool_json_path=$(find . -name "quantus-runtime-srtool-output-v*.json" -type f)
asset_args+=(
"$compact_wasm_path"
"$compressed_wasm_path"
"$srtool_json_path"
)
fi
# Debug: Print is_draft value
echo "is_draft value: ${{ needs.create-tag.outputs.is_draft }}"
# Add draft flag if this is a draft release
if [[ "${{ needs.create-tag.outputs.is_draft }}" == "true" ]]; then
DRAFT_FLAG="--draft"
else
DRAFT_FLAG=""
fi
echo "Final command will use DRAFT_FLAG: $DRAFT_FLAG"
gh release create "$NEW_VERSION" \
--repo "$GITHUB_REPOSITORY" \
--title "Quantus $NEW_VERSION" \
--notes-file release_notes.txt \
--target ${{ needs.create-tag.outputs.release_branch }} \
$DRAFT_FLAG \
"${asset_args[@]}"
create-runtime-issue:
name: 📝 Create Runtime Upgrade Issue
if: needs.create-tag.outputs.is_runtime_upgrade == 'true'
needs: [create-tag, create-github-release]
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create issue for runtime upgrade
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_VERSION: ${{ needs.create-tag.outputs.version }}
ISSUE_BODY: |
A new runtime upgrade has been released: [${{ needs.create-tag.outputs.version }}](https://github.com/${{ github.repository }}/releases/tag/${{ needs.create-tag.outputs.version }})
## Details
- Release version: [`${{ needs.create-tag.outputs.version }}`](https://github.com/${{ github.repository }}/releases/tag/${{ needs.create-tag.outputs.version }})
- Branch: [`release/${{ needs.create-tag.outputs.version }}`](https://github.com/${{ github.repository }}/tree/release/${{ needs.create-tag.outputs.version }})
## Next Steps
Please review and coordinate the upgrade process.
run: |
issue_title="Runtime upgrade released: $NEW_VERSION"
gh issue create \
--title "$issue_title" \
--body "$ISSUE_BODY" \
--repo "$GITHUB_REPOSITORY" \
--label "runtime-upgrade,automated" \
--assignee "${{ github.actor }}"