Skip to content

Commit

Permalink
Merge pull request #153 from cloud-atlas-ai:chore-improve-release
Browse files Browse the repository at this point in the history
Change release process to not require a direct commit to master branch
  • Loading branch information
muness authored Jan 20, 2025
2 parents 2b5b185 + 08432b6 commit a493bdb
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 76 deletions.
72 changes: 42 additions & 30 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,55 @@
name: Build obsidian plugin

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- '*' # Push events to matching any tag format, i.e. 1.0, 20.15.10

pull_request:
branches:
- master
types:
- closed # Trigger only when a PR is closed (merged)
env:
PLUGIN_NAME: obsidian-ics

jobs:
build:
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x' # You might need to adjust this value to your own version
- name: Build
id: build
run: |
npm install
npm run build --if-present
npm run dev-build --if-present
mkdir ${{ env.PLUGIN_NAME }}
cp manifest.json dist/
cp styles.css dist/
cp dist/main.js dist/manifest.json ${{ env.PLUGIN_NAME }}
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
ls dist/
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tag="${GITHUB_REF#refs/tags/}"
gh release create "$tag" \
--title="$tag" \
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '22.10.2'
- name: Install dependencies
run: npm install
- name: Create and push a tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(jq -r .version package.json)
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$VERSION"
git push origin "$VERSION"
- name: Build
run: |
npm run build --if-present
mkdir ${{ env.PLUGIN_NAME }}
cp manifest.json dist/
cp styles.css dist/
cp dist/main.js dist/manifest.json ${{ env.PLUGIN_NAME }}
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
ls dist/
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(jq -r .version package.json)
gh release create "$VERSION" \
--draft \
dist/main.js dist/styles.css dist/manifest.json dist/main-debug.js ${{ env.PLUGIN_NAME }}.zip
--title="$VERSION" \
--notes "Automated release for version $VERSION" \
dist/main.js dist/styles.css dist/manifest.json ${{ env.PLUGIN_NAME }}.zip
83 changes: 37 additions & 46 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,54 @@
set -euo pipefail

if [ "$#" -ne 2 ]; then
echo "Must provide exactly two arguments."
echo "First one must be the new version number."
echo "Second one must be the minimum obsidian version for this release."
echo ""
echo "Example usage:"
echo "./release.sh 0.3.0 0.11.13"
echo "Exiting."

echo "Usage: $0 <new-version> <minimum-obsidian-version>"
exit 1
fi

if [[ $(git status --porcelain) ]]; then
echo "Changes in the git repo."
echo "Exiting."
NEW_VERSION=$1
MINIMUM_OBSIDIAN_VERSION=$2
BRANCH_NAME="release/${NEW_VERSION}"

# Ensure no uncommitted changes
if [[ $(git status --porcelain) ]]; then
echo "Uncommitted changes detected. Please commit or stash them before running the release script."
exit 1
fi

NEW_VERSION=$1
MINIMUM_OBSIDIAN_VERSION=$2
echo "Preparing release ${NEW_VERSION} with minimum Obsidian version ${MINIMUM_OBSIDIAN_VERSION}"

echo "Updating to version ${NEW_VERSION} with minimum obsidian version ${MINIMUM_OBSIDIAN_VERSION}"
# Create and switch to a new branch
git checkout -b "${BRANCH_NAME}"

read -p "Continue? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Updating package.json"
TEMP_FILE=$(mktemp)
jq ".version |= \"${NEW_VERSION}\"" package.json > "$TEMP_FILE" || exit 1
mv "$TEMP_FILE" package.json
# Update version in package.json
echo "Updating package.json..."
jq ".version = \"${NEW_VERSION}\"" package.json > package.json.tmp && mv package.json.tmp package.json

echo "Updating package-lock.json"
npm install
# Update version in manifest.json
echo "Updating manifest.json..."
jq ".version = \"${NEW_VERSION}\" | .minAppVersion = \"${MINIMUM_OBSIDIAN_VERSION}\"" manifest.json > manifest.json.tmp && mv manifest.json.tmp manifest.json

echo "Updating manifest.json"
TEMP_FILE=$(mktemp)
jq ".version |= \"${NEW_VERSION}\" | .minAppVersion |= \"${MINIMUM_OBSIDIAN_VERSION}\"" manifest.json > "$TEMP_FILE" || exit 1
mv "$TEMP_FILE" manifest.json
# Update versions.json
echo "Updating versions.json..."
jq ". += {\"${NEW_VERSION}\": \"${MINIMUM_OBSIDIAN_VERSION}\"}" versions.json > versions.json.tmp && mv versions.json.tmp versions.json

echo "Updating versions.json"
TEMP_FILE=$(mktemp)
jq ". += {\"${NEW_VERSION}\": \"${MINIMUM_OBSIDIAN_VERSION}\"}" versions.json > "$TEMP_FILE" || exit 1
mv "$TEMP_FILE" versions.json
# Install dependencies to update package-lock.json
echo "Updating package-lock.json..."
npm install

read -p "Create git commit, tag, and push? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
# Commit changes
git add package.json package-lock.json manifest.json versions.json
git commit -m "Release ${NEW_VERSION}"

git add -A .
git commit -m"Update to version ${NEW_VERSION}"
git tag "${NEW_VERSION}"
git push
git push --tags
fi
else
echo "Exiting."
exit 1
fi
# Push branch to remote
git push --set-upstream origin "${BRANCH_NAME}"

# Create a pull request
echo "Creating a pull request..."
gh pr create \
--title "Release ${NEW_VERSION}" \
--body "This pull request updates the version to ${NEW_VERSION} and sets the minimum Obsidian version to ${MINIMUM_OBSIDIAN_VERSION}." \
--base master \
--head "${BRANCH_NAME}"

echo "Pull request created. Please review and merge it to trigger the release workflow."

0 comments on commit a493bdb

Please sign in to comment.