diff --git a/.github/workflows/generate_changelog.yml b/.github/workflows/generate_changelog.yml new file mode 100644 index 0000000000..584f67caf8 --- /dev/null +++ b/.github/workflows/generate_changelog.yml @@ -0,0 +1,85 @@ +name: Generate changelog in PR + +on: + pull_request: + +permissions: + contents: write + +jobs: + verify-version: + name: Verify that version that triggered this workflow is greater than most recent release + runs-on: ubuntu-latest + outputs: + versionIsValid: ${{ steps.validVersion.outputs.versionIsValid }} + version: ${{ steps.validVersion.outputs.version }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v3 + with: + cache: 'npm' + cache-dependency-path: scripts/package-lock.json + - run: npm ci + working-directory: scripts + + - name: Get version from Cargo.toml + id: lookupVersion + uses: mikefarah/yq@a198f72367ce9da70b564a2cc25399de8e27bf37 + with: + cmd: yq -oy '"v" + .workspace.package.version' 'Cargo.toml' + + - name: Get version from the latest releases + id: lookupVersionRelease + uses: pozetroninc/github-action-get-latest-release@master + with: + owner: cptartur + repo: starknet-foundry + excludes: prerelease, draft + + - name: Compare versions + id: validVersion + run: | + RELEASE_VERSION=${{ steps.lookupVersionRelease.outputs.release }} + COMMIT_VERSION=${{ steps.lookupVersion.outputs.result }} + echo "Project version from newest release = $RELEASE_VERSION" + echo "Project version from this commit = $COMMIT_VERSION" + IS_VALID=$(node ./scripts/compareVersions.js $RELEASE_VERSION $COMMIT_VERSION) + echo "versionIsValid=$IS_VALID" >> "$GITHUB_OUTPUT" + echo "version=$COMMIT_VERSION" >> "$GITHUB_OUTPUT" + + - name: Output job skipped + if: ${{ steps.validVersion.outputs.versionIsValid == 'false' }} + run: echo "Version from commit is not greater from newest release, skipping build" + + generate-changelog: + name: Convert unreleased section in CHANGELOG.md to new release + runs-on: ubuntu-latest + needs: verify-version + if: ${{ needs.verify-version.outputs.versionIsValid == 'true' }} + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - run: | + RELEASE_VERSION=${{ needs.verify-version.outputs.version }} + RELEASE_VERSION="${RELEASE_VERSION:1}" + + if ! grep -q $RELEASE_VERSION CHANGELOG.md; then + sed -i "s/## \[Unreleased\]/## \[Unreleased\]\n\n## \[${RELEASE_VERSION}\] - $(TZ=Europe/Krakow date '+%Y-%m-%d')/" CHANGELOG.md + fi + + - name: Commit CHANGELOG.md + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add CHANGELOG.md + git diff --cached --quiet || git commit -m "Update CHANGELOG.md" + + - name: Push changes + uses: ad-m/github-push-action@master + with: + branch: ${{ github.head_ref }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d0e6785384..da9a33a81d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,6 +2,9 @@ name: Release on: push: + branches: + - 'master' + create: tags: - v[0-9]+.* @@ -10,23 +13,73 @@ permissions: jobs: verify-version: + name: Verify that version that triggered this workflow is greater than most recent release runs-on: ubuntu-latest + outputs: + versionIsValid: ${{ steps.validVersion.outputs.versionIsValid }} + version: ${{ steps.validVersion.outputs.version }} steps: - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + cache: 'npm' + cache-dependency-path: scripts/package-lock.json + - run: npm ci + working-directory: scripts + - name: Get version from Cargo.toml id: lookupVersion uses: mikefarah/yq@a198f72367ce9da70b564a2cc25399de8e27bf37 with: cmd: yq -oy '"v" + .workspace.package.version' 'Cargo.toml' - - name: Version check - if: steps.lookupVersion.outputs.result != github.ref_name - run: echo "Project version in Cargo.toml does not match the tag" && exit 1 + - name: Get version from the latest releases + id: lookupVersionRelease + uses: pozetroninc/github-action-get-latest-release@master + with: + owner: foundry-rs + repo: starknet-foundry + excludes: prerelease, draft + + - name: Compare versions + id: validVersion + run: | + RELEASE_VERSION=${{ steps.lookupVersionRelease.outputs.release }} + COMMIT_VERSION=${{ steps.lookupVersion.outputs.result }} + echo "Project version from newest release = $RELEASE_VERSION" + echo "Project version from this commit = $COMMIT_VERSION" + IS_VALID=$(node ./scripts/compareVersions.js $RELEASE_VERSION $COMMIT_VERSION) + echo "versionIsValid=$IS_VALID" >> "$GITHUB_OUTPUT" + echo "version=$COMMIT_VERSION" >> "$GITHUB_OUTPUT" + + - name: Output job skipped + if: ${{ steps.validVersion.outputs.versionIsValid == 'false' }} + run: echo "Version from commit is not greater from newest release, skipping build" + + create-tag: + name: If workflow was triggered by a push to master, create a new tag with release version + runs-on: ubuntu-latest + needs: verify-version + if: ${{ needs.verify-version.outputs.versionIsValid == 'true' }} + + steps: + - name: Create tag action was triggered by a push + if: ${{ github.event_name == 'push' }} + uses: actions/github-script@v6 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'refs/tags/${{ needs.verify-version.outputs.version }}', + sha: context.sha + }) build-binaries: name: Build ${{ matrix.target }} - needs: verify-version + needs: create-tag + # if: ${{ needs.verify-version.outputs.versionIsValid == 'true' }} runs-on: ${{ matrix.os }} continue-on-error: true @@ -94,7 +147,7 @@ jobs: shell: bash run: | set -euxo pipefail - PKG_FULL_NAME="starknet-foundry-${{ github.ref_name }}-${{ matrix.target }}" + PKG_FULL_NAME="starknet-foundry-${{ github.ref_name }}-${{ matrix.target }}" echo "PKG_FULL_NAME=$PKG_FULL_NAME" >> $GITHUB_ENV chmod +x ./scripts/package.sh @@ -109,7 +162,7 @@ jobs: create-release: name: Draft release runs-on: ubuntu-latest - needs: build-binaries + needs: [build-binaries, verify-version] steps: - uses: actions/checkout@v4 with: @@ -130,8 +183,10 @@ jobs: uses: taiki-e/create-gh-release-action@9762dfdfe60a96b3fef6c4a0aaafd9840f1195b7 with: token: ${{ secrets.GITHUB_TOKEN }} + changelog: CHANGELOG.md + allow-missing-changelog: false title: $version - draft: true + ref: refs/tags/${{ needs.verify-version.outputs.version }} - name: Upload artifacts to the release working-directory: artifacts diff --git a/.gitignore b/.gitignore index 3ebf85c66c..2ad2ce1c83 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ pyproject.toml target .vscode/ .env +*/node_modules \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 28c29d4ee8..0fdde596c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1061,7 +1061,7 @@ dependencies = [ [[package]] name = "cast" -version = "0.8.3" +version = "0.8.4" dependencies = [ "anyhow", "camino", @@ -1757,7 +1757,7 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "forge" -version = "0.8.3" +version = "0.8.4" dependencies = [ "anyhow", "ark-ff", diff --git a/Cargo.toml b/Cargo.toml index a9836c23f9..5dfcf06e89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ members = [ ] [workspace.package] -version = "0.8.3" +version = "0.8.4" edition = "2021" repository = "https://github.com/foundry-rs/starknet-foundry" license = "MIT" diff --git a/scripts/compareVersions.js b/scripts/compareVersions.js new file mode 100644 index 0000000000..d81440e0fa --- /dev/null +++ b/scripts/compareVersions.js @@ -0,0 +1,11 @@ +const semver = require('semver') + +if (process.argv.length !== 4) { + console.error('Two arguments requred'); + process.exit(1); +} + +const old_version = process.argv[2]; +const new_version = process.argv[3]; + +console.log((semver.gt(new_version, old_version)).toString()) diff --git a/scripts/package-lock.json b/scripts/package-lock.json new file mode 100644 index 0000000000..b23d9a19df --- /dev/null +++ b/scripts/package-lock.json @@ -0,0 +1,65 @@ +{ + "name": "scripts", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "semver": "^7.5.4" + } + }, + "node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + }, + "dependencies": { + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } +} diff --git a/scripts/package.json b/scripts/package.json new file mode 100644 index 0000000000..f18e7c9d59 --- /dev/null +++ b/scripts/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "semver": "^7.5.4" + } +}