Skip to content

Commit

Permalink
add release.yml for automated version bumping (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMinkov authored Nov 30, 2023
1 parent 2d625a5 commit 06cfdb5
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 14 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Purpose:
# Automatically bumps the project's patch version bi-weekly on Tuesdays.
#
# Details:
# - Triggered at 00:00 UTC every Tuesday; runs on even weeks of the year.
# - Sets up the environment by checking out the repo and setting up Node.js.
# - Bumps patch version using `npm version patch`, then creates a new branch 'release/x.x.x'.
# - Pushes changes and creates a PR to `main` using GitHub CLI.
# - Can also be triggered manually via `workflow_dispatch`.
name: Version Bump

on:
workflow_dispatch: # Allow to manually trigger the workflow
schedule:
- cron: '0 0 * * 2' # At 00:00 UTC every Tuesday

jobs:
version-bump:
runs-on: ubuntu-latest

steps:
# Since cronjob syntax doesn't support bi-weekly schedule, we need to check if it's an even week or not
- name: Check if it's an even week
run: |
WEEK_NUM=$(date +'%V')
if [ $((WEEK_NUM % 2)) -eq 0 ]; then
echo "RUN_JOB=true" >> $GITHUB_ENV
else
echo "RUN_JOB=false" >> $GITHUB_ENV
fi
- name: Check out the repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Configure Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
- name: Bump patch version
if: ${{ env.RUN_JOB }} == 'true'
run: |
git fetch --prune --unshallow
NEW_VERSION=$(npm version patch)
echo "New version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Install npm dependencies
run: npm install

- name: Update CHANGELOG.md
run: |
npm run update-changelog
git add CHANGELOG.md
git commit -m "Update CHANGELOG for new version $NEW_VERSION"
- name: Create new release branch
run: |
NEW_BRANCH="release/${NEW_VERSION}"
git checkout -b $NEW_BRANCH
git push -u origin $NEW_BRANCH
git push --tags
gh pr create --base main --head $NEW_BRANCH --title "Release $NEW_VERSION" --body "This is an automated PR to update to version $NEW_VERSION"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN}}
28 changes: 15 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# Changelog

All notable changes to this project will be documented in this file.
All notable changes to this project are documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!--
Possible subsections:
_Added_ for new features.
_Changed_ for changes in existing functionality.
_Deprecated_ for soon-to-be removed features.
_Removed_ for now removed features.
_Fixed_ for any bug fixes.
_Security_ in case of vulnerabilities.
-->

## Unreleased

## [0.15.1] - 2023-11-29

Expand Down Expand Up @@ -354,13 +366,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed bug with CI not cleaning up node_modules after testing. [#219](https://github.com/o1-labs/zkapp-cli/pull/219)

## [0.3.7] - 2021-06-03

<!--
Possible subsections:
Added for new features.
Changed for changes in existing functionality.
Deprecated for soon-to-be removed features.
Removed for now removed features.
Fixed for any bug fixes.
Security in case of vulnerabilities.
-->
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"prettier": "prettier --no-editorconfig --write \"**/*.{js,ts}\"",
"e2e:install": "npx playwright-core install --with-deps",
"e2e:test": "npm run clean && npx playwright test --workers=1",
"e2e:test:smoke": "npm run e2e:test -- --grep '@on-chain @interaction'"
"e2e:test:smoke": "npm run e2e:test -- --grep '@on-chain @interaction'",
"update-changelog": "./update-changelog.sh"
},
"lint-staged": {
"**/*": [
Expand Down
21 changes: 21 additions & 0 deletions update-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Step 1: Capture the latest version
latest_version=$(grep -oP '\[\K[0-9]+\.[0-9]+\.[0-9]+(?=\])' CHANGELOG.md | head -1)
echo "Latest version: $latest_version"

# Step 2: Bump the patch version
IFS='.' read -r -a version_parts <<< "$latest_version"
let version_parts[2]+=1
new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}"
echo "New version: $new_version"

# Step 3: Capture the current date
current_date=$(date +%Y-%m-%d)
echo "Current date: $current_date"

# Step 4: Update the CHANGELOG
# Insert a new version section with an additional newline for spacing
sed -i "/## Unreleased/a \\\n## [$new_version] - $current_date" CHANGELOG.md

echo "CHANGELOG updated with version $new_version"

0 comments on commit 06cfdb5

Please sign in to comment.