From bacfdc6869e9c9e4d1becd3bbb9aae4a019381ba Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Thu, 13 Jun 2024 09:19:33 +0200 Subject: [PATCH] chore: Add make-release.sh Signed-off-by: Anatolii Bazko --- .../devworkspace-generator-publish-next.yml | 3 +- .../devworkspace-generator-release.yml | 36 +++-- make-release.sh | 145 ++++++++++++++++++ 3 files changed, 169 insertions(+), 15 deletions(-) create mode 100755 make-release.sh diff --git a/.github/workflows/devworkspace-generator-publish-next.yml b/.github/workflows/devworkspace-generator-publish-next.yml index b23b1d4..5bd126d 100644 --- a/.github/workflows/devworkspace-generator-publish-next.yml +++ b/.github/workflows/devworkspace-generator-publish-next.yml @@ -13,6 +13,7 @@ on: push: branches: - main + - 7.**.x jobs: publish: @@ -29,7 +30,7 @@ jobs: id: yarn-cache-dir-path run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT - uses: actions/cache@v4 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} key: yarn-${{ hashFiles('yarn.lock') }} diff --git a/.github/workflows/devworkspace-generator-release.yml b/.github/workflows/devworkspace-generator-release.yml index de75ec6..71bf01e 100644 --- a/.github/workflows/devworkspace-generator-release.yml +++ b/.github/workflows/devworkspace-generator-release.yml @@ -25,20 +25,25 @@ jobs: name: Create Che Devfile Registry Release runs-on: ubuntu-22.04 steps: - - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v4 with: node-version: '16' registry-url: 'https://registry.npmjs.org' scope: '@eclipse-che' - - - name: "Checkout source code" + - name: "Checkout source code" uses: actions/checkout@v4 with: fetch-depth: 0 - - - name: Check existing tags - if: github.event.inputs.performRelease == 'true' + - name: Set up environment + run: | + sudo apt-get update -y || true + sudo apt-get -y -q install hub + hub --version + - name: Install NodeJS + uses: actions/setup-node@v3 + with: + node-version: 18.18.0 + - name: Check existing tags run: | set +e RECREATE_TAGS=${{ github.event.inputs.forceRecreateTags }} @@ -57,18 +62,21 @@ jobs: fi - name: Get yarn cache directory path id: yarn-cache-dir-path - run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT + run: | + echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT - uses: actions/cache@v4 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} key: yarn-${{ hashFiles('yarn.lock') }} restore-keys: yarn- - - name: publish DevWorkspace Generator + - name: Run make-release.sh script env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + GITHUB_TOKEN: ${{secrets.DEVWORKSPACE_GENERATOR_RELEASE_GITHUB_TOKEN}} run: | - sed -i -r -e "s/(\"version\": )(\".*\")/\1\"${{ github.event.inputs.version }}\"/" package.json - yarn - yarn compile - npm publish --tag latest + git config --global user.name "Anatolii Bazko" + git config --global user.email "abazko@redhat.com" + + ./make-release.sh --version {{ github.event.inputs.version }} + diff --git a/make-release.sh b/make-release.sh new file mode 100755 index 0000000..9abc26e --- /dev/null +++ b/make-release.sh @@ -0,0 +1,145 @@ +#!/bin/bash +# +# Copyright (c) 2022-2024 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# Red Hat, Inc. - initial API and implementation +# + +set -e + +usage () +{ echo "Usage: ./make-release.sh -v " + exit +} + +init() { + unset VERSION + + while [[ "$#" -gt 0 ]]; do + case $1 in + '-v'|'--version') VERSION="$2"; shift 1;; + '--help'|'-h') usage;; + esac + shift 1 + done + + [[ -z ${VERSION} ]] && { echo "[ERROR] Release version is not defined"; usage; } + + X_BRANCH=$(echo "${VERSION}" | sed 's/.$/x/') + NEXT_BRANCH="pr-main-to-${VERSION}-next" + NEXT_VERSION="${VERSION}-next" +} + +resetChanges() { + local branch="$1" + + echo "[INFO] Reset changes in ${branch} branch" + + git reset --hard + git checkout "${branch}" + git fetch origin --prune + git pull origin "${branch}" +} + +checkoutToXBranch() { + echo "[INFO] Check out to ${X_BRANCH} branch." + + if [[ $(git ls-remote -q --heads | grep -c "${X_BRANCH}") == 1 ]]; then + echo "[INFO] ${X_BRANCH} exists." + resetChanges "${X_BRANCH}" + else + echo "[INFO] ${X_BRANCH} does not exist. Will be created a new one from main." + resetChanges "main" + git push origin main:"${X_BRANCH}" + fi +} + +checkoutToNextBranch() { + echo "[INFO] Will be created a new ${NEXT_BRANCH} branch from main." + + resetChanges main + git push origin main:"${NEXT_BRANCH}" +} + +publishArtifacts() { + echo "[INFO] Publish DevWorkspace Generator ${VERSION} artifacts" + + yarn + yarn compile + npm publish --tag latest +} + +tagRelease() { + git tag "${VERSION}" + git push origin "${VERSION}" +} + +createPR() { + local base=$1 + local branch=$2 + local message=$3 + + echo "[INFO] Create PR with base = ${base} and head = ${branch}" + hub pull-request --base "${base}" --head "${branch}" -m "${message}" +} + +updatePackageVersionAndCommitChanges() { + local version=$1 + local branch=$2 + local message=$3 + + echo "[INFO] Set ${version} in package.json" + + jq '.version |= "'${version}'"' package.json > package.json.update + mv -f package.json.update package.json + + echo "[INFO] Push changes to ${branch} branch" + + git add package.json + git commit -s -m "${message}" + git push origin "${branch}" +} + +updateXBranch() { + checkoutToXBranch + + COMMIT_MSG="ci: bump ${VERSION} in ${X_BRANCH}" + + updatePackageVersionAndCommitChanges \ + "${VERSION}" \ + "${X_BRANCH}" \ + "${COMMIT_MSG}" + + tagRelease + publishArtifacts +} + +updateMainBrain() { + checkoutToNextBranch + + COMMIT_MSG="ci: bump ${NEXT_VERSION} in main" + + updatePackageVersionAndCommitChanges \ + "${NEXT_VERSION}" \ + "${NEXT_BRANCH}" \ + "${COMMIT_MSG}" + + createPR \ + "main" \ + "${NEXT_BRANCH}" \ + "${COMMIT_MSG}" +} + +run() { + updateXBranch + updateMainBrain +} + +init "$@" +run