@@ -2,6 +2,9 @@ name: Release
22
33on :
44 push :
5+ branches :
6+ - ' master'
7+ create :
58 tags :
69 - v[0-9]+.*
710
@@ -10,23 +13,71 @@ permissions:
1013
1114jobs :
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
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
0 commit comments