Skip to content

Commit a493bdb

Browse files
authored
Merge pull request #153 from cloud-atlas-ai:chore-improve-release
Change release process to not require a direct commit to master branch
2 parents 2b5b185 + 08432b6 commit a493bdb

File tree

2 files changed

+79
-76
lines changed

2 files changed

+79
-76
lines changed

.github/workflows/release.yml

+42-30
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
11
name: Build obsidian plugin
22

33
on:
4-
push:
5-
# Sequence of patterns matched against refs/tags
6-
tags:
7-
- '*' # Push events to matching any tag format, i.e. 1.0, 20.15.10
8-
4+
pull_request:
5+
branches:
6+
- master
7+
types:
8+
- closed # Trigger only when a PR is closed (merged)
99
env:
1010
PLUGIN_NAME: obsidian-ics
1111

1212
jobs:
1313
build:
14+
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
1415
permissions:
1516
contents: write
1617
runs-on: ubuntu-latest
1718
steps:
18-
- uses: actions/checkout@v3
19-
- name: Use Node.js
20-
uses: actions/setup-node@v3
21-
with:
22-
node-version: '20.x' # You might need to adjust this value to your own version
23-
- name: Build
24-
id: build
25-
run: |
26-
npm install
27-
npm run build --if-present
28-
npm run dev-build --if-present
29-
mkdir ${{ env.PLUGIN_NAME }}
30-
cp manifest.json dist/
31-
cp styles.css dist/
32-
cp dist/main.js dist/manifest.json ${{ env.PLUGIN_NAME }}
33-
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
34-
ls dist/
35-
- name: Create release
36-
env:
37-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38-
run: |
39-
tag="${GITHUB_REF#refs/tags/}"
40-
gh release create "$tag" \
41-
--title="$tag" \
19+
- uses: actions/checkout@v3
20+
- name: Use Node.js
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: '22.10.2'
24+
- name: Install dependencies
25+
run: npm install
26+
- name: Create and push a tag
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: |
30+
VERSION=$(jq -r .version package.json)
31+
git config user.name "github-actions[bot]"
32+
git config user.email "github-actions[bot]@users.noreply.github.com"
33+
git tag "$VERSION"
34+
git push origin "$VERSION"
35+
36+
- name: Build
37+
run: |
38+
npm run build --if-present
39+
mkdir ${{ env.PLUGIN_NAME }}
40+
cp manifest.json dist/
41+
cp styles.css dist/
42+
cp dist/main.js dist/manifest.json ${{ env.PLUGIN_NAME }}
43+
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
44+
ls dist/
45+
46+
- name: Create release
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
run: |
50+
VERSION=$(jq -r .version package.json)
51+
gh release create "$VERSION" \
4252
--draft \
43-
dist/main.js dist/styles.css dist/manifest.json dist/main-debug.js ${{ env.PLUGIN_NAME }}.zip
53+
--title="$VERSION" \
54+
--notes "Automated release for version $VERSION" \
55+
dist/main.js dist/styles.css dist/manifest.json ${{ env.PLUGIN_NAME }}.zip

release.sh

+37-46
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,54 @@
33
set -euo pipefail
44

55
if [ "$#" -ne 2 ]; then
6-
echo "Must provide exactly two arguments."
7-
echo "First one must be the new version number."
8-
echo "Second one must be the minimum obsidian version for this release."
9-
echo ""
10-
echo "Example usage:"
11-
echo "./release.sh 0.3.0 0.11.13"
12-
echo "Exiting."
13-
6+
echo "Usage: $0 <new-version> <minimum-obsidian-version>"
147
exit 1
158
fi
169

17-
if [[ $(git status --porcelain) ]]; then
18-
echo "Changes in the git repo."
19-
echo "Exiting."
10+
NEW_VERSION=$1
11+
MINIMUM_OBSIDIAN_VERSION=$2
12+
BRANCH_NAME="release/${NEW_VERSION}"
2013

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

24-
NEW_VERSION=$1
25-
MINIMUM_OBSIDIAN_VERSION=$2
20+
echo "Preparing release ${NEW_VERSION} with minimum Obsidian version ${MINIMUM_OBSIDIAN_VERSION}"
2621

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

29-
read -p "Continue? [y/N] " -n 1 -r
30-
echo
31-
if [[ $REPLY =~ ^[Yy]$ ]]
32-
then
33-
echo "Updating package.json"
34-
TEMP_FILE=$(mktemp)
35-
jq ".version |= \"${NEW_VERSION}\"" package.json > "$TEMP_FILE" || exit 1
36-
mv "$TEMP_FILE" package.json
25+
# Update version in package.json
26+
echo "Updating package.json..."
27+
jq ".version = \"${NEW_VERSION}\"" package.json > package.json.tmp && mv package.json.tmp package.json
3728

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

41-
echo "Updating manifest.json"
42-
TEMP_FILE=$(mktemp)
43-
jq ".version |= \"${NEW_VERSION}\" | .minAppVersion |= \"${MINIMUM_OBSIDIAN_VERSION}\"" manifest.json > "$TEMP_FILE" || exit 1
44-
mv "$TEMP_FILE" manifest.json
33+
# Update versions.json
34+
echo "Updating versions.json..."
35+
jq ". += {\"${NEW_VERSION}\": \"${MINIMUM_OBSIDIAN_VERSION}\"}" versions.json > versions.json.tmp && mv versions.json.tmp versions.json
4536

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

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

56-
git add -A .
57-
git commit -m"Update to version ${NEW_VERSION}"
58-
git tag "${NEW_VERSION}"
59-
git push
60-
git push --tags
61-
fi
62-
else
63-
echo "Exiting."
64-
exit 1
65-
fi
45+
# Push branch to remote
46+
git push --set-upstream origin "${BRANCH_NAME}"
47+
48+
# Create a pull request
49+
echo "Creating a pull request..."
50+
gh pr create \
51+
--title "Release ${NEW_VERSION}" \
52+
--body "This pull request updates the version to ${NEW_VERSION} and sets the minimum Obsidian version to ${MINIMUM_OBSIDIAN_VERSION}." \
53+
--base master \
54+
--head "${BRANCH_NAME}"
55+
56+
echo "Pull request created. Please review and merge it to trigger the release workflow."

0 commit comments

Comments
 (0)