Skip to content

Commit

Permalink
Merge pull request #12 from devfile/makerelease
Browse files Browse the repository at this point in the history
chore: Add make-release.sh
  • Loading branch information
tolusha authored Jun 13, 2024
2 parents be69259 + bacfdc6 commit cd6d3b5
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/devworkspace-generator-publish-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
push:
branches:
- main
- 7.**.x

jobs:
publish:
Expand All @@ -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') }}
Expand Down
36 changes: 22 additions & 14 deletions .github/workflows/devworkspace-generator-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 "[email protected]"
./make-release.sh --version {{ github.event.inputs.version }}
145 changes: 145 additions & 0 deletions make-release.sh
Original file line number Diff line number Diff line change
@@ -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 <version>"
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

0 comments on commit cd6d3b5

Please sign in to comment.