-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from laxmanpokhrel/dev
major release with depencencies cleanup
- Loading branch information
Showing
7 changed files
with
313 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# Change directory to the root of the project | ||
cd "$(git rev-parse --show-toplevel)" | ||
|
||
echo "==========================================================" | ||
echo "= =" | ||
echo "==========================================================" | ||
|
||
# Declerations | ||
RELEASE_CONFIG_FILE=null | ||
VERSION_UPGRADE_TYPE=null | ||
RELEASE_TYPE='' | ||
TAG=null | ||
|
||
PACKAGEJSON=$(cat package.json) | ||
PACKAGE_NAME="$(echo $PACKAGEJSON | jq -r '.name')" | ||
PACKAGE_VERSION="$(echo $PACKAGEJSON | jq -r '.version')" | ||
PACKAGE_NPM_VERSION=null | ||
FINAL_RELEASE_VERSION=null | ||
|
||
# Check if release config file is available | ||
echo "- reading config.json file" | ||
if [ -f ".release/config.json" ]; then | ||
echo "- '.release/config.json' file found" | ||
RELEASE_CONFIG_FILE=$(cat .release/config.json) | ||
else | ||
echo "- '.release/config.json' file not found" | ||
echo "- abort" | ||
exit 1 | ||
fi | ||
|
||
# Check if release config file has `versionUpgradeType` | ||
echo "- reading 'versionUpgradeType'" | ||
if [ "$(echo "$RELEASE_CONFIG_FILE" | jq -r ".versionUpgradeType")" != "null" ]; then | ||
VERSION_UPGRADE_TYPE=$(echo "$RELEASE_CONFIG_FILE" | jq -r ".versionUpgradeType") | ||
echo "- 'versionUpgradeType': $VERSION_UPGRADE_TYPE" | ||
else | ||
VERSION_UPGRADE_TYPE=null | ||
echo "- no 'versionUpgradeType' provided" | ||
echo "- abort" | ||
exit 1 | ||
fi | ||
|
||
# Check if release config file has `releaseType` | ||
echo "- reading 'releaseType'" | ||
if [ "$(echo "$RELEASE_CONFIG_FILE" | jq -r ".releaseType")" != "null" ]; then | ||
RELEASE_TYPE=$(echo "$RELEASE_CONFIG_FILE" | jq -r ".releaseType") | ||
echo "- 'releaseType': $RELEASE_TYPE" | ||
else | ||
RELEASE_TYPE='' | ||
echo "- no 'releaseType' provided" | ||
# echo "- abort" | ||
# exit 1 | ||
fi | ||
|
||
# Check if npm view command succeeded or failed | ||
echo "- reading package version from npm" | ||
PACKAGE_NPM_VERSION=$(npm view $PACKAGE_NAME version 2>/dev/null) | ||
if [ $? -eq 0 ]; then | ||
echo "- package npm version: $PACKAGE_NPM_VERSION" | ||
# if [ "$PACKAGE_VERSION" == "$PACKAGE_NPM_VERSION" ]; then | ||
# echo "NPM version and package version matched." | ||
# fi | ||
else | ||
echo "- no npm version of the package found" | ||
# FIRST_RELEASE=true | ||
PACKAGE_NPM_VERSION=null | ||
FINAL_RELEASE_VERSION=$PACKAGE_VERSION | ||
fi | ||
|
||
# Function to update version based on VERSION_UPGRADE_TYPE | ||
update_version() { | ||
local current_version=$1 | ||
local release_type=$2 | ||
local major | ||
local minor | ||
local patch | ||
|
||
IFS='.' read -r major minor patch <<<"$current_version" | ||
|
||
case $release_type in | ||
"major") | ||
echo "$(($major + 1)).0.0" | ||
;; | ||
"minor") | ||
echo "$major.$(($minor + 1)).0" | ||
;; | ||
"patch") | ||
echo "$major.$minor.$(($patch + 1))" | ||
;; | ||
*) | ||
echo "- invalid release type: $release_type" | ||
;; | ||
esac | ||
} | ||
|
||
# Logic for FINAL_RELEASE_VERSION | ||
if [ "$PACKAGE_NPM_VERSION" == "null" ]; then | ||
FINAL_RELEASE_VERSION=$PACKAGE_VERSION | ||
else | ||
case $VERSION_UPGRADE_TYPE in | ||
"major" | "minor" | "patch") | ||
echo "- analysing version" | ||
FINAL_RELEASE_VERSION=$(update_version "$PACKAGE_NPM_VERSION" "$VERSION_UPGRADE_TYPE") TAG=$FINAL_RELEASE_VERSION | ||
echo "- analysed deployable version $FINAL_RELEASE_VERSION" | ||
;; | ||
*) | ||
echo "- invalid release type: $VERSION_UPGRADE_TYPE" | ||
;; | ||
esac | ||
fi | ||
|
||
# Logic for TAG | ||
echo "- reading custom tag" | ||
if [ "$(echo "$RELEASE_CONFIG_FILE" | jq -r ".tag")" != "null" ]; then | ||
TAG=$(echo "$RELEASE_CONFIG_FILE" | jq -r ".tag") | ||
echo "- custom tag detected $TAG" | ||
else | ||
echo "- no custom tag found" | ||
TAG="v-$FINAL_RELEASE_VERSION" | ||
fi | ||
|
||
# Check if release notes are available | ||
echo "- reading release notes" | ||
RELEASE_NOTES=$(cat .release/release-notes.txt) | ||
|
||
if [ $? != 0 ]; then | ||
echo "- release notes not provided" | ||
RELEASE_NOTES=null | ||
# exit 1 | ||
fi | ||
|
||
echo "---" | ||
echo "- RELEASE_NOTES: $RELEASE_NOTES" | ||
echo "- PACKAGE_NAME: $PACKAGE_NAME" | ||
echo "- PACKAGE_VERSION: $PACKAGE_VERSION" | ||
echo "- FINAL_RELEASE_VERSION: $FINAL_RELEASE_VERSION" | ||
echo "- VERSION_UPGRADE_TYPE: $VERSION_UPGRADE_TYPE" | ||
echo "- TAG: $TAG" | ||
echo "- RELEASE_TYPE: $RELEASE_TYPE" | ||
|
||
# Set output | ||
echo "tag=$(echo $TAG)" >>$GITHUB_OUTPUT | ||
echo "release-notes=$(echo $RELEASE_NOTES)" >>$GITHUB_OUTPUT | ||
echo "final-release-version=$(echo $FINAL_RELEASE_VERSION)" >>$GITHUB_OUTPUT | ||
echo "release-type=$(echo $VERSION_UPGRADE_TYPE)" >>$GITHUB_OUTPUT | ||
echo "package-version=$(echo $PACKAGE_VERSION)" >>$GITHUB_OUTPUT | ||
echo "release-type=$(echo $RELEASE_TYPE)" >>$GITHUB_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
name: Deploy and Release | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- .release/* | ||
permissions: | ||
contents: write | ||
jobs: | ||
release: | ||
permissions: write-all | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install jq | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install jq | ||
- name: Setup node version | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '*' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Read release props | ||
id: read-release-props | ||
run: bash .github/scripts/release.sh 2>&1 | tee -a get-release-props-logs.log | ||
|
||
- name: Configure git | ||
run: | | ||
USER_NAME='laxmanpokhel_actions' | ||
USER_EMAIL='laxmanpokhrel@users.noreply.github.com' | ||
# Set the git configs | ||
git config --global user.name $USER_NAME | ||
git config --global user.email $USER_EMAIL | ||
- name: Commit logs | ||
continue-on-error: true | ||
run: | | ||
git add . | ||
git commit -m "ci: Release props logs generated." | ||
- name: Upload log file | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: get-release-props-logs | ||
path: get-release-props-logs.log | ||
|
||
- name: Debug variables | ||
run: | | ||
echo "tag=${{steps.read-release-props.outputs.tag}}" | ||
echo "release-notes=${{steps.read-release-props.outputs.release-notes}}" | ||
echo "package-version: ${{steps.read-release-props.outputs.package-version}}" | ||
echo "release-type: ${{steps.read-release-props.outputs.release-type}}" | ||
echo "final-release-version: ${{steps.read-release-props.outputs.final-release-version}}" | ||
echo "release-type: ${{steps.read-release-props.outputs.release-type}}" | ||
echo "isPrerelease: ${{steps.read-release-props.outputs.release-type}} == '--prerelease'" | ||
- name: Checkout to new branch and update package json with new version | ||
id: branch-checkout-details | ||
run: | | ||
# Read current branch | ||
current_branch=$(git rev-parse --abbrev-ref HEAD) | ||
# Create a checkout branch name | ||
checkout_branch_name=release-${{steps.read-release-props.outputs.final-release-version}} | ||
# Checkout to new branch | ||
git checkout -b $checkout_branch_name | ||
# Update the version in package.json, and commit & tag the change: | ||
npm version ${{steps.read-release-props.outputs.final-release-version}} -m "chore(Github Actions-$(date -u +"%Y-%m-%d %H:%M:%S")): Deploy package to NPM" | ||
# Set output | ||
echo "current_branch=$(echo $current_branch)" >>$GITHUB_OUTPUT | ||
echo "checkout_branch_name=$(echo $checkout_branch_name)" >>$GITHUB_OUTPUT | ||
- name: Check branch | ||
run: git branch | ||
|
||
- name: Install package | ||
run: yarn install | ||
|
||
- name: Build package | ||
run: yarn build | ||
|
||
- name: Publish package | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: | | ||
npm pkg fix | ||
npm publish | ||
- name: Create release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
tag="${{ steps.read-release-props.outputs.tag }}" | ||
title="${tag}" | ||
gh release create "$tag" \ | ||
--repo="$GITHUB_REPOSITORY" \ | ||
--title="$title" \ | ||
--notes="${{ steps.read-release-props.outputs.release-notes }}" \ | ||
${{steps.read-release-props.outputs.release-type}} | ||
- name: Push and raise a PR | ||
if: ${{steps.read-release-props.outputs.release-type != '--prerelease'}} | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
# Push the updated version new checkout branch | ||
git push --set-upstream origin ${{steps.branch-checkout-details.outputs.checkout_branch_name}} | ||
# Set the upstream branch for the current branch | ||
git branch --set-upstream-to=origin/${{ steps.branch-checkout-details.outputs.checkout_branch_name }} ${GITHUB_REF#refs/heads/} | ||
# Create PR for the release | ||
gh pr create \ | ||
--base ${{steps.branch-checkout-details.outputs.current_branch}} \ | ||
--title "version ${{steps.read-release-props.outputs.final-release-version}}" \ | ||
--body "* version: ${{steps.read-release-props.outputs.final-release-version}} | $(date -u +"%Y-%m-%d %H:%M:%S")" \ | ||
--no-maintainer-edit |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Ignore source files | ||
src/ | ||
*.js | ||
*.ts | ||
|
||
# Ignore development tools and configuration files | ||
node_modules/ | ||
.git/ | ||
.editorconfig | ||
.eslintrc | ||
tsconfig.json | ||
.github | ||
.husky | ||
.release | ||
scripts | ||
src | ||
|
||
.eslintignore | ||
.eslintrc.cjs | ||
.lintstagedrc | ||
.prettierrc | ||
.releaserc | ||
yarn.lock | ||
package-lock.json | ||
registry/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"versionUpgradeType": "major", | ||
"releaseType": "--latest" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changes | ||
- Semantic release removes | ||
- Cleanup dev dependencies | ||
- npm ignore | ||
- workflow changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters