Skip to content

Commit

Permalink
Deployment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vrundakansara committed Oct 2, 2024
1 parent d92384f commit ec86f90
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 3 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Create a tag

on:
push:
branches:
- master

# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none
tools: composer, cs2pr

- name: Use desired version of NodeJS
uses: actions/setup-node@v4
with:
node-version: 18.15
cache: 'npm'

- name: Composer Install
uses: ramsey/composer-install@v3

- name: Build the release
run: npm install && npm run release

- name: Maybe create a tag
run: bash bin/release.sh

- name: Release
if: ${{ env.TAG_CREATED == 'true' }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.BRAINSTORM_FORCE_RELEASE }}
body: ''
name: v${{ env.BRAINSTORM_FORCE_RELEASE }}
draft: false
files: force-ui.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
dist/*
.DS_Store
*storybook.log
storybook-static/*
storybook-static/*
*.zip
12 changes: 12 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

echo "💃 Time to build the force-ui plugin ZIP file 🕺"

echo "Creating archive... 🎁"

zip -r force-ui.zip \
dist \
version.json \
changelog.txt

echo "Done. You've built force-ui! 🎉 "
99 changes: 99 additions & 0 deletions bin/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash -e
#
# Deploy your branch.
#

DEPLOY_SUFFIX="${DEPLOY_SUFFIX:--built}"
GIT_USER="${DEPLOY_GIT_USER:-GitHub Actions}"
GIT_EMAIL="${DEPLOY_GIT_EMAIL:-hello@bsf.io}"

BRANCH="${GITHUB_REF:-master}"
SRC_DIR="$PWD"
BUILD_DIR="/tmp/brainstormforce-build"

if [[ -d "$BUILD_DIR" ]]; then
echo "WARNING: ${BUILD_DIR} already exists. You may have accidentally cached this"
echo "directory. This will cause issues with deploying."
exit 1
fi

COMMIT=$(git rev-parse HEAD)
VERSION=$(grep 'Version: ' $PWD/ai-builder.php | grep -oEi '[0-9\.a-z\+-]+$')

# Check if the tag exists in the remote GitHub repository.
TAG_EXISTS=$(git ls-remote --tags origin | grep -c "refs/tags/$VERSION")

# If tag is already found, exit by setting env variables.
# exit 0 to exit with a success.
if [ $TAG_EXISTS != 0 ]; then
echo "BRAINSTORM_FORCE_RELEASE=$VERSION" >>$GITHUB_ENV
echo "TAG_CREATED=false" >>$GITHUB_ENV
exit 0
fi

if [[ $VERSION != "null" ]]; then
DEPLOY_BRANCH="release/${VERSION}"
DEPLOY_AS_RELEASE="${DEPLOY_AS_RELEASE:-yes}"
else
DEPLOY_BRANCH="${BRANCH}${DEPLOY_SUFFIX}"
DEPLOY_AS_RELEASE="${DEPLOY_AS_RELEASE:-no}"
fi

echo "Deploying $BRANCH to $DEPLOY_BRANCH"

# If the deploy branch doesn't already exist, create it from the empty root.
if ! git rev-parse --verify "remotes/origin/$DEPLOY_BRANCH" >/dev/null 2>&1; then
echo -e "\nCreating $DEPLOY_BRANCH..."
git worktree add --detach "$BUILD_DIR"
cd "$BUILD_DIR"
git checkout --orphan "$DEPLOY_BRANCH"
else
echo "Using existing $DEPLOY_BRANCH"
git worktree add --detach "$BUILD_DIR" "remotes/origin/$DEPLOY_BRANCH"
cd "$BUILD_DIR"
git checkout "$DEPLOY_BRANCH"
fi

# Ensure we're in the right dir
cd "$BUILD_DIR"

# Remove existing files
git rm -rfq .

# Sync built files
echo -e "\nSyncing files..."

rsync -av "$SRC_DIR/" "$BUILD_DIR" --exclude-from "$SRC_DIR/.distignore"

# Add changed files
git add .

if [ -z "$(git status --porcelain)" ]; then
echo "No changes to built files."
exit
fi

# Print status!
echo -e "\nSynced files. Changed:"
git status -s

# Double-check our user/email config
if ! git config user.email; then
git config user.name "$GIT_USER"
git config user.email "$GIT_EMAIL"
fi

# Commit it.
MESSAGE=$(printf 'Build changes from %s\n\n%s' "${COMMIT}" "${CIRCLE_BUILD_URL}")
git commit -m "$MESSAGE"

# Push it (real good).
git push origin "$DEPLOY_BRANCH"

# Make a release if one doesn't exist.
if [[ $DEPLOY_AS_RELEASE = "yes" && $(git tag -l "$VERSION") != $VERSION ]]; then
git tag "$VERSION"
git push origin "$VERSION"
echo "BRAINSTORM_FORCE_RELEASE=$VERSION" >>$GITHUB_ENV
echo "TAG_CREATED=true" >>$GITHUB_ENV
fi
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Version 0.0.3 - 2nd October, 2024
- New - Breadcrumb
- New - Grid Container
- New - Dialog Component
- New - Drawer Component
- New - Menu & Menu Item Component
- New - Sidebar
- New - Topbar
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bsf/force-ui",
"version": "0.0.2",
"version": "0.0.3",
"description": "Library of components for the BSF project",
"main": "dist/force-ui.js",
"scripts": {
Expand All @@ -16,7 +16,9 @@
"lint:css-fix": "wp-scripts lint-style ./src/**/*.{scss,css} --fix",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"chromatic": "npx chromatic --project-token CHROMATIC_PROJECT_TOKEN"
"chromatic": "npx chromatic --project-token CHROMATIC_PROJECT_TOKEN",
"package": "sh bin/build.sh",
"release": "npm run build && npm run package "
},
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"force-ui": "0.0.3"
}

0 comments on commit ec86f90

Please sign in to comment.