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 script to update version #405

Merged
merged 21 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
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
20 changes: 20 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,28 @@ on:
types: [published]

jobs:
version:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
steps:
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: 'main'
ssh-key: ${{ secrets.SSH_KEY }}
- name: Set version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Update version
run: python scripts/update_version.py ${{ env.RELEASE_VERSION }}
- name: Auto-commit changes
uses: stefanzweifel/git-auto-commit-action@49620cd3ed21ee620a48530e81dba0d139c9cb80
Copy link
Contributor

Choose a reason for hiding this comment

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

why the specific hash?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To mitigate risk. I think it's a safer play since we're using a third-party action here

Copy link
Contributor

Choose a reason for hiding this comment

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

do you know if devs can overwrite a version name? in any case the commit hash it's more certain

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed on the certainty^ And yes, I believe devs can replace the tag in git

with:
commit_message: Apply version bump
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved

test:
runs-on: ubuntu-latest
if: ${{ always() }}
needs: [version]
steps:
- uses: actions/checkout@v2
- name: Markdown Linter
Expand Down
30 changes: 4 additions & 26 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,16 @@ Releasing checklist:

(1) Write a changelog.

(2) Make sure to update SPDX license identifiers. For example:

```cairo
# SPDX-License-Identifier: MIT
# OpenZeppelin Contracts for Cairo v0.1.0 (account/Account.cairo)
```

to

```cairo
# SPDX-License-Identifier: MIT
# OpenZeppelin Contracts for Cairo v0.2.0 (account/Account.cairo)
```

(3) Update documentation version in `docs/antora.yml`

```diff
name: cairo-contracts
title: Contracts for Cairo
-version: 0.1.0
+version: 0.2.0
(...)
```

(4) Create a release branch and add a tag to it. This branch can be useful if we need to push a hot fix on top of an existing release in the case of a bug.
(2) Create a release branch and add a tag to it. This branch can be useful if we need to push a hot fix on top of an existing release in the case of a bug.
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved

```sh
git checkout -b release-0.2.0
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved
git tag v0.2.0
```

(5) Push the tag to the main repository, [triggering the CI and release process](https://github.com/OpenZeppelin/cairo-contracts/blob/b27101eb826fae73f49751fa384c2a0ff3377af2/.github/workflows/python-app.yml#L60).
(3) Push the tag to the main repository, [triggering the CI and release process](https://github.com/OpenZeppelin/cairo-contracts/blob/b27101eb826fae73f49751fa384c2a0ff3377af2/.github/workflows/python-app.yml#L60).

> Note that the CI automatically updates the SPDX identifiers with the pushed tag.
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved

```sh
git push origin v0.2.0
Expand Down
30 changes: 30 additions & 0 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fileinput
import sys
from pathlib import Path

CURRENT_VERSION = "v0.2.1"
martriay marked this conversation as resolved.
Show resolved Hide resolved
ANTORA_PATH = "docs/antora.yml"


def main():
new_version = str(sys.argv[1])
path = Path("src")
for p in path.glob("**/*.cairo"):
_update_version(p, new_version)
_update_version(ANTORA_PATH, new_version)
_update_version("scripts/update_version.py", new_version)


def _update_version(path, version):
with fileinput.input(path, inplace=True) as file:
for line in file:
old, new = CURRENT_VERSION, version
if path == ANTORA_PATH:
old = old.strip("v")
new = new.strip("v")
new_line = line.replace(old, new)
print(new_line, end="")


if __name__ == "__main__":
main()