-
Notifications
You must be signed in to change notification settings - Fork 64
78 lines (64 loc) · 2.46 KB
/
release-please.yml
File metadata and controls
78 lines (64 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Release On Version Bump
on:
push:
branches: [main]
permissions:
contents: write
actions: write
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect version bump
id: detect
shell: bash
env:
BEFORE_SHA: ${{ github.event.before }}
run: |
set -euo pipefail
CURRENT_VERSION="$(jq -r '.version' package.json)"
TAG_NAME="v${CURRENT_VERSION}"
echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
# First push to branch or unknown previous commit
if [[ -z "${BEFORE_SHA}" || "${BEFORE_SHA}" =~ ^0+$ ]]; then
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "reason=before_sha_unavailable" >> "$GITHUB_OUTPUT"
exit 0
fi
PREV_VERSION="$(git show "${BEFORE_SHA}:package.json" 2>/dev/null | jq -r '.version' 2>/dev/null || true)"
if [[ -z "${PREV_VERSION}" ]]; then
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "reason=previous_version_unavailable" >> "$GITHUB_OUTPUT"
exit 0
fi
if [[ "$CURRENT_VERSION" == "$PREV_VERSION" ]]; then
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "reason=version_unchanged" >> "$GITHUB_OUTPUT"
exit 0
fi
if git ls-remote --exit-code --tags origin "refs/tags/${TAG_NAME}" >/dev/null 2>&1; then
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "reason=tag_exists" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "previous_version=$PREV_VERSION" >> "$GITHUB_OUTPUT"
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "reason=version_changed" >> "$GITHUB_OUTPUT"
- name: Log decision
shell: bash
run: |
echo "Decision: ${{ steps.detect.outputs.reason }}"
echo "Current version: ${{ steps.detect.outputs.current_version }}"
echo "Tag: ${{ steps.detect.outputs.tag_name }}"
- name: Create GitHub release
if: steps.detect.outputs.should_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.detect.outputs.tag_name }}
target_commitish: ${{ github.sha }}
generate_release_notes: true