Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add presets page update on release workflow #883

Merged
merged 23 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aa248b2
feat: add update class hashes workflow
ericnordelo Jan 31, 2024
ea7f92e
fix: input name
ericnordelo Jan 31, 2024
03e2cee
test
ericnordelo Jan 31, 2024
1b40cb2
test
ericnordelo Jan 31, 2024
a0e89bc
feat: test with main
ericnordelo Jan 31, 2024
744a140
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Jan 31, 2024
a18309a
feat: add update class hashes local action
ericnordelo Jan 31, 2024
8d20bd5
test
ericnordelo Jan 31, 2024
4f74499
feat: finish main logic
ericnordelo Jan 31, 2024
1460f69
test
ericnordelo Jan 31, 2024
61d2b74
fix: version
ericnordelo Jan 31, 2024
f3aa10e
refactor: update wording
ericnordelo Jan 31, 2024
3034b12
Merge branch 'main' into feat/class-hash-action
ericnordelo Feb 8, 2024
3c0f9b3
feat: remove javascript action and update preset page on release
ericnordelo Feb 8, 2024
b9c669d
refactor: scarb version input
ericnordelo Feb 8, 2024
856b512
feat: normalize hashes len
ericnordelo Feb 8, 2024
699ecbd
feat: update workflow name
ericnordelo Feb 8, 2024
9a93e71
feat: apply review updates
ericnordelo Feb 9, 2024
90f0d58
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Feb 9, 2024
d5d8fe5
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Feb 13, 2024
b1b724c
feat: rename file to match action
ericnordelo Feb 16, 2024
f82f18c
feat: get scarb version from Scarb.toml
ericnordelo Feb 21, 2024
17b5f62
Update .github/workflows/prepare-release.yml
ericnordelo Feb 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: Update version on new release branch
name: Update version and presets page on new release branch

on:
create:

env:
SCARB_VERSION: 2.5.3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's our strategy to maintain this up to date?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea is to continue using the same we've been using: update this version at the same time we update the Scarb.toml. We had to do this already for the lint_and_test action.

Copy link
Contributor

@martriay martriay Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see. does it make sense to automate it in some way? is there something preventing us from mistakenly not updating it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm under the impression it might be easy to forget about this bump and mistakenly publish the wrong hashes. what about reading it from Scarb.toml?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

jobs:
update_version:
if: github.ref_type == 'branch' && startsWith(github.ref, 'refs/heads/release-v')
Expand All @@ -26,7 +29,24 @@ jobs:
run: |
echo "Current version: $CURRENT_VERSION"
echo "New version: $NEW_VERSION"
find . -type f -not -path '*/\.*' -not -path './CHANGELOG.md' -not -path './docs/package-lock.json' -not -path './RELEASING.md' -exec sed -i "s/$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/$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${{ env.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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bump scarb to v2.4.4 (#853)
- Bump scarb to v2.5.3 (#898)
- OwnershipTransferred event args are indexed (#809)

### Removed

- Non standard increase_allowance and decrease_allowance functions in ERC20 contract (#881)
Expand All @@ -42,4 +42,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support higher tx versions in Account (#858)
- Bump scarb to v2.4.1 (#858)
- Add security section to Upgrades docs (#861)

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: 0x07c9b5a246fe83b0cd81de65daddb94b3803f94950db99bf2431bbfecf284642
:erc721-class-hash: 0x06b7c9efc5467c621f58d87995302d940a39b7217b5c5a7a55555c97cabf5cd8
:Account-class-hash: 0x01148c31dfa5c4708a4e9cf1eb0fd3d4d8ad9ccf09d0232cd6b56bee64a7de9d
:ERC20-class-hash: 0x07c9b5a246fe83b0cd81de65daddb94b3803f94950db99bf2431bbfecf284642
:ERC721-class-hash: 0x06b7c9efc5467c621f58d87995302d940a39b7217b5c5a7a55555c97cabf5cd8
:EthAccountUpgradeable-class-hash: 0x023e416842ca96b1f7067693892ed00881d97a4b0d9a4c793b75cb887944d98d

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


def main():
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
# 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__':
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
main()
Loading