This repository has been archived by the owner on Jan 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (75 loc) · 2.47 KB
/
release.yml
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
79
80
81
82
83
84
85
name: Release
on:
push:
branches:
- main
workflow_dispatch:
inputs:
version_bump:
description: 'Trigger release for version bump'
required: false
default: 'false'
jobs:
create:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Git
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Get current version
id: version
run: echo "VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
- name: Check existing release
id: check_release
run: |
if gh release view ${{ env.VERSION }} &>/dev/null; then
echo "EXISTS=true" >> $GITHUB_ENV
else
echo "EXISTS=false" >> $GITHUB_ENV
fi
env:
GH_TOKEN: ${{ github.token }}
- name: Generate changelog
if: env.EXISTS == 'false'
id: changelog
run: |
# Get the latest tag
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$latest_tag" ]; then
# If no tags exist, get all commits
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
git log --pretty=format:"- %s (%h)" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
else
# Get commits since last tag
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
git log ${latest_tag}..HEAD --pretty=format:"- %s (%h)" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi
- name: Create Git Tag
if: env.EXISTS == 'false'
run: |
git tag -a "v${{ env.VERSION }}" -m "Release v${{ env.VERSION }}"
git push origin "v${{ env.VERSION }}"
- name: Create GitHub Release
if: env.EXISTS == 'false'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ env.VERSION }}
name: Release v${{ env.VERSION }}
body: |
## Changes
${{ env.CHANGELOG }}
## Installation
```bash
npm install erfdb@${{ env.VERSION }}
```
prerelease: ${{ contains(env.VERSION, 'alpha') || contains(env.VERSION, 'beta') || contains(env.VERSION, 'rc') }}
draft: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}