From 1cc1d0fbc14bb48498ced5d6e9415a2aaf8cf9f0 Mon Sep 17 00:00:00 2001 From: Jacob Herper Date: Wed, 19 Apr 2023 20:34:02 +0100 Subject: [PATCH 1/4] ci: fixes release stage --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b10ca45..7acb0237 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,19 +44,35 @@ jobs: run: | git fetch --unshallow || true git-chglog -o CHANGELOG.md - git add CHANGELOG.md - git commit -m "chore(release): update changelog [skip ci]" - git push + current_version=$(grep -Po '"version": "\K\d+\.\d+\.\d+' package.json) + + if grep -qE "^\s*feat" CHANGELOG.md; then + new_version=$(semver --increment minor $current_version) + elif grep -qE "^\s*fix" CHANGELOG.md; then + new_version=$(semver --increment patch $current_version) + else + new_version=$current_version + fi + + sed -i -E "s/\"version\": \"[0-9]+\.[0-9]+\.[0-9]+\"/\"version\": \"$new_version\"/" package.json + + git add CHANGELOG.md package.json + git commit -m "chore(release): $new_version [skip ci]" + git push origin HEAD:main + - name: Get current version number + run: | + version=$(grep '"version":' package.json | awk -F'"' '{print $4}') + echo "::set-output name=version::$version" - name: Create a new release if: github.ref == 'refs/heads/main' && github.event_name == 'push' uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} + tag_name: v${{ steps.get_version.outputs.version }} # Construct the tag name based on the version number + release_name: Release ${{ steps.get_version.outputs.version }} body: | - Release ${{ github.ref }} + Release v${{ steps.get_version.outputs.version }} $(cat CHANGELOG.md) draft: false prerelease: false From 40337a1bb43c6ad3cb17c2bd299f7d01916c339f Mon Sep 17 00:00:00 2001 From: Jacob Herper Date: Wed, 19 Apr 2023 21:09:04 +0100 Subject: [PATCH 2/4] chore: updates release step --- .github/workflows/ci.yml | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7acb0237..458b01d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,21 +59,33 @@ jobs: git add CHANGELOG.md package.json git commit -m "chore(release): $new_version [skip ci]" git push origin HEAD:main - - name: Get current version number + - name: Get current version + id: get_version + run: echo "::set-env name=PACKAGE_VERSION::$(node -p -e "require('./package.json').version")" + shell: bash + - name: Set previous version + id: set_previous_version + run: echo "::set-env name=PREVIOUS_VERSION::$(git describe --tags --abbrev=0)" + shell: bash + - name: Bump version + id: bump_version run: | - version=$(grep '"version":' package.json | awk -F'"' '{print $4}') - echo "::set-output name=version::$version" + npx semver --increment ${{ env.BUMP_TYPE }} ${{ env.PACKAGE_VERSION }} --preid=beta.${{ github.run_number }} -i -f -p 'beta' > version.txt + echo "::set-env name=NEW_VERSION::$(cat version.txt)" + shell: bash + - name: Update package.json + run: | + npm version --no-git-tag-version $(cat version.txt) + shell: bash - name: Create a new release - if: github.ref == 'refs/heads/main' && github.event_name == 'push' uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} with: - tag_name: v${{ steps.get_version.outputs.version }} # Construct the tag name based on the version number - release_name: Release ${{ steps.get_version.outputs.version }} + tag_name: ${{ env.NEW_VERSION }} + release_name: Release ${{ env.NEW_VERSION }} body: | - Release v${{ steps.get_version.outputs.version }} - $(cat CHANGELOG.md) + ${{ steps.generate_release_notes.outputs.release_notes }} draft: false prerelease: false From 8d77db28ea1bedcce328c87ada0604fedfe6dc5e Mon Sep 17 00:00:00 2001 From: Jacob Herper Date: Wed, 19 Apr 2023 21:30:46 +0100 Subject: [PATCH 3/4] chore: refactors setting of env vars --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 458b01d2..0a5d61bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,17 +61,17 @@ jobs: git push origin HEAD:main - name: Get current version id: get_version - run: echo "::set-env name=PACKAGE_VERSION::$(node -p -e "require('./package.json').version")" + run: echo "PACKAGE_VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV shell: bash - name: Set previous version id: set_previous_version - run: echo "::set-env name=PREVIOUS_VERSION::$(git describe --tags --abbrev=0)" + run: echo "PREVIOUS_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV shell: bash - name: Bump version id: bump_version run: | npx semver --increment ${{ env.BUMP_TYPE }} ${{ env.PACKAGE_VERSION }} --preid=beta.${{ github.run_number }} -i -f -p 'beta' > version.txt - echo "::set-env name=NEW_VERSION::$(cat version.txt)" + echo "NEW_VERSION=$(cat version.txt)" >> $GITHUB_ENV shell: bash - name: Update package.json run: | From c0f49860efd4383b10835b6ff3cdd93b392cf91b Mon Sep 17 00:00:00 2001 From: Jacob Herper Date: Wed, 19 Apr 2023 21:39:36 +0100 Subject: [PATCH 4/4] chore: adds semver install step --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a5d61bd..d862427d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,10 +67,12 @@ jobs: id: set_previous_version run: echo "PREVIOUS_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV shell: bash + - name: Install SemVer + run: npm i -g semver - name: Bump version id: bump_version run: | - npx semver --increment ${{ env.BUMP_TYPE }} ${{ env.PACKAGE_VERSION }} --preid=beta.${{ github.run_number }} -i -f -p 'beta' > version.txt + semver --increment ${{ env.BUMP_TYPE }} ${{ env.PACKAGE_VERSION }} --preid=beta.${{ github.run_number }} -i -f -p 'beta' > version.txt echo "NEW_VERSION=$(cat version.txt)" >> $GITHUB_ENV shell: bash - name: Update package.json