Skip to content

Commit 9498a8a

Browse files
authored
Automate release procedure (#950)
<!-- Reference any GitHub issues resolved by this PR --> Closes #859 ## Introduced changes <!-- A brief description of the changes --> - Added a script for updating `Cargo.toml`, `Cargo.lock` and `CHANGELOG.md` files - Release workflow is now also triggered from the master branch if version in `Cargo.toml` increased ## Breaking changes <!-- List of all breaking changes, if applicable --> ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md`
1 parent da66ee2 commit 9498a8a

File tree

7 files changed

+162
-30
lines changed

7 files changed

+162
-30
lines changed

.github/workflows/release.yml

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Release
22

33
on:
44
push:
5+
branches:
6+
- 'master'
7+
create:
58
tags:
69
- v[0-9]+.*
710

@@ -10,23 +13,71 @@ permissions:
1013

1114
jobs:
1215
verify-version:
16+
name: Verify that version that triggered this workflow is greater than most recent release
1317
runs-on: ubuntu-latest
18+
outputs:
19+
versionIsValid: ${{ steps.validVersion.outputs.versionIsValid }}
20+
version: ${{ steps.validVersion.outputs.version }}
1421
steps:
1522
- uses: actions/checkout@v4
1623

24+
- uses: actions/setup-node@v3
25+
with:
26+
cache: 'npm'
27+
cache-dependency-path: scripts/package-lock.json
28+
- run: npm ci
29+
working-directory: scripts
30+
1731
- name: Get version from Cargo.toml
1832
id: lookupVersion
1933
uses: mikefarah/yq@a198f72367ce9da70b564a2cc25399de8e27bf37
2034
with:
2135
cmd: yq -oy '"v" + .workspace.package.version' 'Cargo.toml'
2236

23-
- name: Version check
24-
if: steps.lookupVersion.outputs.result != github.ref_name
25-
run: echo "Project version in Cargo.toml does not match the tag" && exit 1
37+
- name: Get version from the latest releases
38+
id: lookupVersionRelease
39+
uses: pozetroninc/github-action-get-latest-release@master
40+
with:
41+
owner: foundry-rs
42+
repo: starknet-foundry
43+
excludes: prerelease, draft
44+
45+
- name: Compare versions
46+
id: validVersion
47+
run: |
48+
RELEASE_VERSION=${{ steps.lookupVersionRelease.outputs.release }}
49+
COMMIT_VERSION=${{ steps.lookupVersion.outputs.result }}
50+
echo "Project version from newest release = $RELEASE_VERSION"
51+
echo "Project version from this commit = $COMMIT_VERSION"
52+
IS_VALID=$(node ./scripts/compareVersions.js $RELEASE_VERSION $COMMIT_VERSION)
53+
echo "versionIsValid=$IS_VALID" >> "$GITHUB_OUTPUT"
54+
echo "version=$COMMIT_VERSION" >> "$GITHUB_OUTPUT"
55+
56+
- name: Output job skipped
57+
if: ${{ steps.validVersion.outputs.versionIsValid == 'false' }}
58+
run: echo "Version from commit is not greater from newest release, skipping build"
59+
60+
create-tag:
61+
name: If workflow was triggered by a push to master, create a new tag with release version
62+
runs-on: ubuntu-latest
63+
needs: verify-version
64+
if: ${{ needs.verify-version.outputs.versionIsValid == 'true' }}
65+
steps:
66+
- name: Create tag action was triggered by a push
67+
if: ${{ github.event_name == 'push' }}
68+
uses: actions/github-script@v6
69+
with:
70+
script: |
71+
github.rest.git.createRef({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
ref: 'refs/tags/${{ needs.verify-version.outputs.version }}',
75+
sha: context.sha
76+
})
2677
2778
build-binaries:
2879
name: Build ${{ matrix.target }}
29-
needs: verify-version
80+
needs: create-tag
3081
runs-on: ${{ matrix.os }}
3182
continue-on-error: true
3283

@@ -94,7 +145,7 @@ jobs:
94145
shell: bash
95146
run: |
96147
set -euxo pipefail
97-
PKG_FULL_NAME="starknet-foundry-${{ github.ref_name }}-${{ matrix.target }}"
148+
PKG_FULL_NAME="starknet-foundry-${{ github.ref_name }}-${{ matrix.target }}"
98149
echo "PKG_FULL_NAME=$PKG_FULL_NAME" >> $GITHUB_ENV
99150
100151
chmod +x ./scripts/package.sh
@@ -109,7 +160,7 @@ jobs:
109160
create-release:
110161
name: Draft release
111162
runs-on: ubuntu-latest
112-
needs: build-binaries
163+
needs: [build-binaries, verify-version]
113164
steps:
114165
- uses: actions/checkout@v4
115166
with:
@@ -130,8 +181,10 @@ jobs:
130181
uses: taiki-e/create-gh-release-action@9762dfdfe60a96b3fef6c4a0aaafd9840f1195b7
131182
with:
132183
token: ${{ secrets.GITHUB_TOKEN }}
184+
changelog: CHANGELOG.md
185+
allow-missing-changelog: false
133186
title: $version
134-
draft: true
187+
ref: refs/tags/${{ needs.verify-version.outputs.version }}
135188

136189
- name: Upload artifacts to the release
137190
working-directory: artifacts

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pyproject.toml
55
target
66
.vscode/
77
.env
8+
*/node_modules

RELEASING.md

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
# Instruction For Creating New Starknet Forge Releases
22

3-
1. Bump Starknet Foundry version in the top-level `Cargo.toml` file
4-
2. Regenerate locks using `cargo update -p forge cast`
5-
3. Update `CHANGELOG.md`
6-
1. Convert the `[Unreleased]` section to `[vMAJOR.MINOR.PATCH] - year-month-date`.
7-
2. Create a new `[Unreleased]` section
8-
4. Merge introduced changes
9-
5. Create a new tag in repository with format `vMAJOR.MINOR.PATCH`. This will trigger the release workflow
10-
6. Wait for release workflows to pass. A new draft release will be created on GitHub.
11-
7. Update the release contents using template below and publish it
3+
1. Run `./scripts/release.sh MAJOR.MINOR.PATCH`.
4+
2. Merge introduced changes to master branch.
5+
3. Wait for release workflows to pass. A new release will be created on GitHub.
126

13-
## Release Template
7+
## Manually Creating a Release
148

15-
Optional release description
9+
In case a manual creation of release is necessary, for example when
10+
cherry-picking changes, a release can also be triggered by creating a tag
11+
with the name format `vMAJOR.MINOR.PATCH`.
1612

17-
## What's Changed
18-
19-
- list
20-
- of
21-
- features
22-
23-
## Compatible Scarb Versions
24-
25-
| Tool | Scarb Version |
26-
|-----------|---------------|
27-
| `snforge` | `X.Y.Z` |
28-
| `sncast` | `X.Y.Z` |
13+
Note that in this case `CHANGELOG.md`, `Cargo.toml` and `Cargo.lock` files
14+
have to be updated accordingly.

scripts/compareVersions.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const semver = require('semver')
2+
3+
if (process.argv.length !== 4) {
4+
console.error('Two arguments requred');
5+
process.exit(1);
6+
}
7+
8+
const old_version = process.argv[2];
9+
const new_version = process.argv[3];
10+
11+
console.log((semver.gt(new_version, old_version)).toString())

scripts/package-lock.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"semver": "^7.5.4"
4+
}
5+
}

scripts/release.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
VERSION=$1
4+
5+
sed -i.bak "s/## \[Unreleased\]/## \[Unreleased\]\n\n## \[${VERSION}\] - $(TZ=Europe/Krakow date '+%Y-%m-%d')/" CHANGELOG.md
6+
rm CHANGELOG.md.bak 2> /dev/null
7+
8+
sed -i.bak "/\[workspace.package\]/,/version =/ s/version = \".*/version = \"${VERSION}\"/" Cargo.toml
9+
rm Cargo.toml.bak 2> /dev/null
10+
11+
cargo update forge cast

0 commit comments

Comments
 (0)