diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index e6ecd149a..df7444d02 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -37,8 +37,13 @@ jobs: git config --global user.name $user_name git config --global user.email $user_email git remote set-url origin https://${github_token}@github.com/${repository} + ./stamp.sh npm run build npm run -w web deploy + VERSION=$(grep version package.json | awk -F\" '{print $4}') + git tag "$VERSION" main + git push "$REMOTE" "$VERSION" + git push "$REMOTE" main env: user_name: "github-actions[bot]" user_email: "github-actions[bot]@users.noreply.github.com" diff --git a/package.json b/package.json index ec15db6e1..956f50ff6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nand2tetris/web-ide", - "version": "0.0.0", + "version": "2024.49.0", "description": "A Javascript implementation of nand2tetris.org.", "repository": { "type": "git", diff --git a/stamp.sh b/stamp.sh new file mode 100755 index 000000000..70c009416 --- /dev/null +++ b/stamp.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +set -e # Exit on errors +# set -x # Shell debugging + +# CURRENT and NEXT have the format YYYY.WW.REV, where YYYY is the current year, +# WW is the current week, and REV is the number of releases this week. +# The next revision compares the two, in this way +# - If NEXT is later than CURRENT in any fields, accept NEXT. +# - Otherwise, return CURRENT, with one added to REV. +# +# THIS FUNCTION IS NOT TRANSITIVE! It must be called with +# `compare_versions CURRENT NEXT` +compare_versions() { + if [[ "$1" < "$2" ]] ; then + echo "$2" + else + IFS='.' read -r y1 w1 r1 <<< "$1" + r1=$((r1 + 1)) + echo "${y1}.${w1}.${r1}" + fi +} + +# compare_versions 2024.44.4 2024.44.0 # 2024.44.5 +# compare_versions 2024.44.4 2024.45.0 # 2024.45.0 +# compare_versions 2024.44.4 2025.1.0 # 2025.1.0 + +CURRENT=$(grep version package.json | awk -F\" '{print $4}') +NEXT=$(date +%Y.%W.0) +VERSION=$(compare_versions "$CURRENT" "$NEXT") +echo "Releasing $VERSION..." +sed "/version/ s/$CURRENT/$VERSION/" package.json > package.json.out ; mv package.json.out package.json +sed "/version/ s/$CURRENT/$VERSION/" web/public/index.html > web/public/index.html.out ; mv web/public/index.html.out web/public/index.html +git --no-pager diff +git add package.json +git commit --message "Release ${VERSION}" + +if [ "$1" == "--release" ] ; then + git tag "$VERSION" main + git push "$REMOTE" "$VERSION" + git push "$REMOTE" main +fi \ No newline at end of file