Skip to content

Commit 50380cf

Browse files
committed
new gh action for release
1 parent 0b72745 commit 50380cf

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

.github/workflows/release.yml

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,44 @@ name: Release Obsidian plugin
22

33
on:
44
push:
5-
tags:
6-
- "*"
5+
branches:
6+
- main # or your default branch
77

88
jobs:
9+
check-version:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
version-changed: ${{ steps.version-check.outputs.changed }}
13+
new-version: ${{ steps.version-check.outputs.version }}
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 2 # Need at least 2 commits to compare
18+
19+
- name: Check if version changed
20+
id: version-check
21+
run: |
22+
# Get current version from package.json
23+
current_version=$(node -p "require('./package.json').version")
24+
25+
# Get previous version from package.json in the previous commit
26+
previous_version=$(git show HEAD~1:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8')).version")
27+
28+
echo "Current version: $current_version"
29+
echo "Previous version: $previous_version"
30+
31+
if [ "$current_version" != "$previous_version" ]; then
32+
echo "Version changed from $previous_version to $current_version"
33+
echo "changed=true" >> $GITHUB_OUTPUT
34+
echo "version=v$current_version" >> $GITHUB_OUTPUT
35+
else
36+
echo "Version unchanged"
37+
echo "changed=false" >> $GITHUB_OUTPUT
38+
fi
39+
940
build:
41+
needs: check-version
42+
if: needs.check-version.outputs.version-changed == 'true'
1043
runs-on: ubuntu-latest
1144

1245
steps:
@@ -26,9 +59,15 @@ jobs:
2659
env:
2760
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2861
run: |
29-
tag="${GITHUB_REF#refs/tags/}"
62+
tag="${{ needs.check-version.outputs.new-version }}"
63+
64+
# Create and push the tag
65+
git config user.name github-actions
66+
git config user.email [email protected]
67+
git tag "$tag"
68+
git push origin "$tag"
3069
3170
gh release create "$tag" \
32-
--title="$tag" \
71+
--title="Release $tag" \
3372
--draft \
3473
out/main.js manifest.json styles.css

0 commit comments

Comments
 (0)