Skip to content

Commit

Permalink
Add presets page update on release workflow (#883)
Browse files Browse the repository at this point in the history
* feat: add update class hashes workflow

* fix: input name

* test

* test

* feat: test with main

* feat: add update class hashes local action

* test

* feat: finish main logic

* test

* fix: version

* refactor: update wording

* feat: remove javascript action and update preset page on release

* refactor: scarb version input

* feat: normalize hashes len

* feat: update workflow name

* feat: apply review updates

* feat: rename file to match action

* feat: get scarb version from Scarb.toml

* Update .github/workflows/prepare-release.yml

Co-authored-by: Martín Triay <[email protected]>

---------

Co-authored-by: Martín Triay <[email protected]>
  • Loading branch information
ericnordelo and martriay authored Feb 23, 2024
1 parent 7684fb0 commit e0e888c
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 15 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update version on new release branch
name: Update version and presets page on new release branch

on:
create:
Expand All @@ -12,10 +12,12 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Extract current version
- name: Extract current versions
run: |
CURRENT_VERSION=$(grep '^version = ' Scarb.toml | sed 's/version = "\(.*\)"/\1/')
SCARB_VERSION=$(grep 'cairo-version = ' Scarb.toml | sed 's/cairo-version = "\(.*\)"/\1/')
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
echo "SCARB_VERSION=$SCARB_VERSION" >> $GITHUB_ENV
- name: Extract new version number
run: echo "NEW_VERSION=${GITHUB_REF#refs/heads/release-v}" >> $GITHUB_ENV
Expand All @@ -25,7 +27,24 @@ jobs:
echo "Current version: $CURRENT_VERSION"
echo "New version: $NEW_VERSION"
ESCAPED_CURRENT_VERSION=$(echo $CURRENT_VERSION | sed 's/\./\\./g')
find . -type f -not -path '*/\.*' -not -path './CHANGELOG.md' -not -path './docs/package-lock.json' -not -path './RELEASING.md' -exec sed -i "s/$ESCAPED_CURRENT_VERSION/$NEW_VERSION/g" {} +
find . -type f -not -path '*/\.*' -not -path './CHANGELOG.md' -not -path './docs/package-lock.json' \
-not -path './RELEASING.md' -exec sed -i "s/$ESCAPED_CURRENT_VERSION/$NEW_VERSION/g" {} +
- name: Setup scarb
uses: software-mansion/setup-scarb@v1
id: setup_scarb
with:
scarb-version: ${{ env.SCARB_VERSION }}

- name: Setup class_hash
uses: ericnordelo/setup-class-hash@c14dd33506c3eb8e1acfe2ade9f82585f5acf28c
with:
version: "0.1.0"

- name: Update presets page
run: |
class_hash get --json | sed -e '1,4d' | python3 scripts/get_hashes_page.py v$SCARB_VERSION \
> ./docs/modules/ROOT/pages/utils/_class_hashes.adoc
- name: Auto-commit changes
uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a #v4.16.0
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/api/account.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ include::../utils/_class_hashes.adoc[]
[.contract-index]
.{presets-page}
--
{account-class-hash}
{Account-class-hash}
--

[.contract-index]
Expand Down Expand Up @@ -534,7 +534,7 @@ include::../utils/_class_hashes.adoc[]
[.contract-index]
.{presets-page}
--
{eth-account-upgradeable-class-hash}
{EthAccountUpgradeable-class-hash}
--

[.contract-index]
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/api/erc20.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ include::../utils/_class_hashes.adoc[]
[.contract-index]
.{presets-page}
--
{erc20-class-hash}
{ERC20-class-hash}
--

[.contract-index]
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/api/erc721.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ include::../utils/_class_hashes.adoc[]
[.contract-index]
.{presets-page}
--
{erc721-class-hash}
{ERC721-class-hash}
--

[.contract-index]
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/presets.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ NOTE: Class hashes were computed using {class-hash-cairo-version}.
| Name | Sierra Class Hash

| `{account}`
| `{account-class-hash}`
| `{Account-class-hash}`

| `{eth-account-upgradeable}`
| `{eth-account-upgradeable-class-hash}`
| `{EthAccountUpgradeable-class-hash}`

| `{erc20}`
| `{erc20-class-hash}`
| `{ERC20-class-hash}`

| `{erc721}`
| `{erc721-class-hash}`
| `{ERC721-class-hash}`
|===

TIP: {starkli} class-hash command can be used to compute the class hash from a Sierra artifact.
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/utils/_class_hashes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
:class-hash-cairo-version: https://crates.io/crates/cairo-lang-compiler/2.5.3[cairo 2.5.3]

// Class Hashes
:account-class-hash: 0x01148c31dfa5c4708a4e9cf1eb0fd3d4d8ad9ccf09d0232cd6b56bee64a7de9d
:eth-account-upgradeable-class-hash: 0x023e416842ca96b1f7067693892ed00881d97a4b0d9a4c793b75cb887944d98d
:erc20-class-hash: 0x7d94f28156c0dc3bfd9a07ca79b15b8da2b5b32093db79000fcd0f6f625d213
:erc721-class-hash: 0x06b7c9efc5467c621f58d87995302d940a39b7217b5c5a7a55555c97cabf5cd8
:Account-class-hash: 0x01148c31dfa5c4708a4e9cf1eb0fd3d4d8ad9ccf09d0232cd6b56bee64a7de9d
:ERC20-class-hash: 0x07d94f28156c0dc3bfd9a07ca79b15b8da2b5b32093db79000fcd0f6f625d213
:ERC721-class-hash: 0x06b7c9efc5467c621f58d87995302d940a39b7217b5c5a7a55555c97cabf5cd8
:EthAccountUpgradeable-class-hash: 0x0580fe510cf07255540abda6f9d29aa07cb8944db444bca59e1573904c269844

// Presets page
:presets-page: xref:presets.adoc[Sierra class hash]
36 changes: 36 additions & 0 deletions scripts/get_hashes_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
import json


def main():
# Required compiler version argument
cmp_version = sys.argv[1]

# Read class hashes from stdin
contracts = json.load(sys.stdin)

print(generate_doc_file(cmp_version, contracts))


def generate_doc_file(cmp_version, contracts):
header = f"""// Version
:class-hash-cairo-version: \
https://crates.io/crates/cairo-lang-compiler/{cmp_version}[cairo {cmp_version}]
"""
hashes = "// Class Hashes\n"
for contract in contracts['contracts']:
# The [13:] is to remove the "openzeppelin_" prefix from the contract name
hashes += f":{contract['name'][13:]}-class-hash: {normalize_len(contract['sierra'])}\n"

footer = """// Presets page
:presets-page: xref:presets.adoc[Sierra class hash]"""

return f"{header}\n{hashes}\n{footer}\n"


def normalize_len(sierra_hash):
return "0x" + "0" * (66 - len(sierra_hash)) + sierra_hash[2:]


if __name__ == '__main__':
main()

0 comments on commit e0e888c

Please sign in to comment.