Skip to content

Commit 995e5b1

Browse files
andrew-flemingmartriayfrangio
authored
Add script to update version (#405)
* add update_version script * add script to checklist * fix glob * add line * add antora path to script * add version bump job * add version dep * update RELEASING with new CI workflow * add token for checkout * Update .github/workflows/python-app.yml Co-authored-by: Francisco <[email protected]> * change dep tag to commit hash * Update .github/workflows/python-app.yml Co-authored-by: Martín Triay <[email protected]> * Apply suggestions from code review Co-authored-by: Martín Triay <[email protected]> * merge release branch to main in version job * fix git push format * remove blockquote * add branch checkout to checklist * Apply suggestions from code review Co-authored-by: Martín Triay <[email protected]> Co-authored-by: Martín Triay <[email protected]> Co-authored-by: Francisco <[email protected]>
1 parent 6404684 commit 995e5b1

File tree

3 files changed

+65
-26
lines changed

3 files changed

+65
-26
lines changed

.github/workflows/python-app.yml

+27
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,35 @@ on:
1212
types: [published]
1313

1414
jobs:
15+
version:
16+
runs-on: ubuntu-latest
17+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
18+
steps:
19+
- name: Checkout main branch
20+
uses: actions/checkout@v3
21+
with:
22+
ref: 'main'
23+
ssh-key: ${{ secrets.SSH_KEY }}
24+
- name: Set version
25+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
26+
- name: Update version
27+
run: python scripts/update_version.py ${{ env.RELEASE_VERSION }}
28+
- name: Auto-commit changes
29+
uses: stefanzweifel/git-auto-commit-action@49620cd3ed21ee620a48530e81dba0d139c9cb80
30+
with:
31+
commit_message: Bump version to ${{ env.RELEASE_VERSION }}
32+
create_branch: true
33+
branch: release-${{ env.RELEASE_VERSION }}
34+
- name: Merge changes to main
35+
run: |
36+
git checkout "main"
37+
git merge "release-${{ env.RELEASE_VERSION }}" --no-edit
38+
git push
39+
1540
test:
1641
runs-on: ubuntu-latest
42+
if: ${{ always() }}
43+
needs: [version]
1744
steps:
1845
- uses: actions/checkout@v2
1946
- name: Markdown Linter

RELEASING.md

+8-26
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,21 @@ Releasing checklist:
44

55
(1) Write a changelog.
66

7-
(2) Make sure to update SPDX license identifiers. For example:
7+
(2) Checkout the branch to be released. This should be `main` except in the event of a hotfix. For hotfixes, checkout the latest release branch.
88

9-
```cairo
10-
# SPDX-License-Identifier: MIT
11-
# OpenZeppelin Contracts for Cairo v0.1.0 (account/Account.cairo)
12-
```
13-
14-
to
15-
16-
```cairo
17-
# SPDX-License-Identifier: MIT
18-
# OpenZeppelin Contracts for Cairo v0.2.0 (account/Account.cairo)
19-
```
20-
21-
(3) Update documentation version in `docs/antora.yml`
22-
23-
```diff
24-
name: cairo-contracts
25-
title: Contracts for Cairo
26-
-version: 0.1.0
27-
+version: 0.2.0
28-
(...)
29-
```
30-
31-
(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.
9+
(3) Create a tag for the release.
3210

3311
```sh
34-
git checkout -b release-0.2.0
3512
git tag v0.2.0
3613
```
3714

38-
(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).
15+
(4) 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).
3916

4017
```sh
4118
git push origin v0.2.0
4219
```
20+
21+
Note that the CI automatically:
22+
23+
- Updates the SPDX identifiers and antora.yml versions with the pushed tag
24+
- Creates a release branch and adds a tag to it. This can be useful if we need to push a hot fix on top of an existing release in the case of a bug.

scripts/update_version.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import fileinput
2+
import sys
3+
from pathlib import Path
4+
5+
CURRENT_VERSION = "v0.2.1"
6+
ANTORA_PATH = "docs/antora.yml"
7+
8+
9+
def main():
10+
new_version = str(sys.argv[1])
11+
path = Path("src")
12+
for p in path.glob("**/*.cairo"):
13+
_update_version(p, new_version)
14+
_update_version(ANTORA_PATH, new_version)
15+
_update_version("scripts/update_version.py", new_version)
16+
17+
18+
def _update_version(path, version):
19+
with fileinput.input(path, inplace=True) as file:
20+
for line in file:
21+
old, new = CURRENT_VERSION, version
22+
if path == ANTORA_PATH:
23+
old = old.strip("v")
24+
new = new.strip("v")
25+
new_line = line.replace(old, new)
26+
print(new_line, end="")
27+
28+
29+
if __name__ == "__main__":
30+
main()

0 commit comments

Comments
 (0)