-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: implement release workflow for wasm application
- Loading branch information
Showing
6 changed files
with
169 additions
and
45 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Build and release | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- ci/app-wasm-release | ||
jobs: | ||
metadata: | ||
name: Build and release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build application | ||
run: | | ||
./logic/build.sh | ||
- name: Get application metadata | ||
id: get_app_metadata | ||
run: | | ||
echo "name=$(cargo read-manifest --manifest-path logic/Cargo.toml | jq -r '.name')" >> $GITHUB_OUTPUT | ||
echo "description=$(cargo read-manifest --manifest-path logic/Cargo.toml | jq -r '.description')" >> $GITHUB_OUTPUT | ||
echo "version=$(cargo read-manifest --manifest-path logic/Cargo.toml | jq -r '.version')" >> $GITHUB_OUTPUT | ||
- name: Install near CLI | ||
run: | | ||
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/download/v0.15.1/near-cli-rs-installer.sh | sh | ||
- name: Release application | ||
env: | ||
NEAR_NETWORK: testnet | ||
NEAR_CREDENTIALS_JSON: ${{ secrets.NEAR_TESTNET_CREDENTIALS_JSON }} | ||
NEAR_CONTRACT_ACCOUNT_ID: "calimero-package-manager.testnet" | ||
run: | | ||
touch "./near-credentials.json" | ||
printf "$NEAR_CREDENTIALS_JSON" >> "./near-credentials.json" | ||
cat "./near-credentials.json" | ||
./logic/release.sh \ | ||
"$(realpath $NEAR_NETWORK)" \ | ||
./near-credentials.json \ | ||
"$NEAR_CONTRACT_ACCOUNT_ID" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,128 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
cd "$(dirname $0)" | ||
|
||
BLOBBY_IPFS="https://blobby-public.euw3.prod.gcp.calimero.network" | ||
|
||
usage() { | ||
echo "Usage: $0 <file_path> <name> <version> <description> <repository> <notes> <near_account_id>" | ||
exit 1 | ||
echo "Usage: $0 <near_network> <near_credentials_file_path> <near_contract_account_id>" | ||
} | ||
|
||
# Validate arguments | ||
if [[ $# -ne 7 ]]; then | ||
if [[ $# -ne 3 ]]; then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
file_path="$1" | ||
name="$2" | ||
version="$3" | ||
description="$4" | ||
repository="$5" | ||
notes="$6" | ||
accountId="$7" | ||
near_network="$1" | ||
near_credentials_file_path="$2" | ||
near_contract_account_id="$3" | ||
near_account_id=$(cat $near_credentials_file_path | jq -r '.account_id') | ||
|
||
if [[ ! -f "$file_path" || "$file_path" != *.wasm ]]; then | ||
echo "Please provide a valid .wasm file." | ||
usage | ||
fi | ||
|
||
# Calculate SHA-256 hash for the file | ||
file_hash=$(sha256sum "$file_path" | awk '{ print $1 }') | ||
echo "File Hash: $file_hash" | ||
echo "-------------------Near network configuration-------------------" | ||
echo "Near network: $near_network" | ||
echo "Near credentials file path: $near_credentials_file_path" | ||
echo "Near signer account ID: $near_account_id" | ||
echo "Near contract account ID: $near_contract_account_id" | ||
echo "-----------------------------------------------------------------" | ||
|
||
# Upload application wasm file to Blobby IPFS | ||
response=$(curl -s -X POST -H "Content-Type: application/wasm" -F "file=@${file_path}" "$BLOBBY_IPFS") | ||
ipfs_path=$(echo "$response" | jq -r '.cid') | ||
ipfs_path="$BLOBBY_IPFS/$ipfs_path" | ||
name=$(cargo read-manifest | jq -r '.name') | ||
version=$(cargo read-manifest | jq -r '.version') | ||
description=$(cargo read-manifest | jq -r '.description') | ||
repository=$(git remote get-url origin) | ||
notes="-" # TODO: Add support for custom notes | ||
sanitized_name=$(echo $name | tr '-' '_') | ||
app_file_path="./res/$sanitized_name.wasm" | ||
|
||
if [[ -z "$ipfs_path" ]]; then | ||
echo "Error occurred while uploading the file." | ||
if [[ ! -f "$app_file_path" ]]; then | ||
echo "Failed to locate .wasm file, expected file path: $app_file_path" | ||
exit 1 | ||
fi | ||
|
||
echo "IPFS Path: $ipfs_path" | ||
echo "-------------------Application metadata-------------------" | ||
echo "Name: $name" | ||
echo "Version: $version" | ||
echo "Description: $description" | ||
echo "Repository: $repository" | ||
echo "Notes: $notes" | ||
echo "Local file path: $app_file_path" | ||
echo "------------------------------------------------------------" | ||
|
||
# Update application metadata on NEAR blockchain | ||
near call "$accountId" add_package "$(jq -n --arg name "$name" --arg description "$description" --arg repository "$repository" '{name: $name, description: $description, repository: $repository}')" --accountId "$accountId" | ||
near call "$accountId" add_release "$(jq -n --arg name "$name" --arg version "$version" --arg notes "$notes" --arg path "$ipfs_path" --arg hash "$file_hash" '{name: $name, version: $version, notes: $notes, path: $path, hash: $hash}')" --accountId "$accountId" | ||
package_metadata=$( | ||
near contract \ | ||
call-function \ | ||
as-read-only \ | ||
$near_contract_account_id \ | ||
get_package_from_owner \ | ||
json-args "$(jq -n --arg name "$name" --arg owner_account "$near_account_id" --arg version "$version" '{name: $name, owner_account: $owner_account, version: $version}')" \ | ||
network-config $near_network \ | ||
now || echo "" | ||
) | ||
if [[ -z "$package_metadata" ]]; then | ||
echo "Package not found, creating a new package." | ||
near contract \ | ||
call-function \ | ||
as-transaction \ | ||
$near_contract_account_id \ | ||
add_package \ | ||
json-args "$(jq -n --arg name "$name" --arg description "$description" --arg repository "$repository" '{name: $name, description: $description, repository: $repository}')" \ | ||
prepaid-gas '100.0 Tgas' \ | ||
attached-deposit '0.0 NEAR' \ | ||
sign-as $near_account_id \ | ||
network-config $near_network \ | ||
sign-with-access-key-file $near_credentials_file_path \ | ||
send | ||
else | ||
echo "Package found, skipping package creation." | ||
echo "Package metadata" | ||
echo $package_metadata | jq -r . | ||
echo "-----------------------------------------------------------------" | ||
fi | ||
|
||
release_metadata=$( | ||
near contract \ | ||
call-function \ | ||
as-read-only \ | ||
$near_contract_account_id \ | ||
get_release_from_owner \ | ||
json-args "$(jq -n --arg name "$name" --arg owner_account "$near_account_id" --arg version "$version" '{name: $name, owner_account: $owner_account, version: $version}')" \ | ||
network-config $near_network \ | ||
now || echo "" | ||
) | ||
if [[ -z "$release_metadata" ]]; then | ||
echo "Release not found, creating a new release." | ||
|
||
file_hash=$(sha256sum "$app_file_path" | awk '{ print $1 }') | ||
echo "File Hash: $file_hash" | ||
|
||
response=$(curl -s -X POST -H "Content-Type: application/wasm" -F "file=@${app_file_path}" "$BLOBBY_IPFS") | ||
ipfs_path=$(echo "$response" | jq -r '.cid') | ||
ipfs_path="$BLOBBY_IPFS/$ipfs_path" | ||
|
||
if [[ -z "$ipfs_path" ]]; then | ||
echo "Error occurred while uploading the file." | ||
exit 1 | ||
fi | ||
|
||
echo "IPFS Path: $ipfs_path" | ||
|
||
near contract \ | ||
call-function \ | ||
as-transaction \ | ||
$near_contract_account_id \ | ||
add_release \ | ||
json-args "$(jq -n --arg name "$name" --arg version "$version" --arg notes "$notes" --arg path "$ipfs_path" --arg hash "$file_hash" '{name: $name, version: $version, notes: $notes, path: $path, hash: $hash}')" \ | ||
prepaid-gas '100.0 Tgas' \ | ||
attached-deposit '0.0 NEAR' \ | ||
sign-as $near_account_id \ | ||
network-config $near_network \ | ||
sign-with-access-key-file $near_credentials_file_path \ | ||
send | ||
else | ||
echo "Release found, skipping release creation." | ||
echo "Release metadata" | ||
echo $release_metadata | jq -r . | ||
echo "-----------------------------------------------------------------" | ||
fi |
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