-
Notifications
You must be signed in to change notification settings - Fork 12
121 lines (107 loc) · 4.09 KB
/
prerelease_on_version_bump.yaml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Prerelease on Version Bump
on:
push:
branches:
- master
jobs:
pre-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Detect single custom component directory
id: detect_integration
run: |
DIR_COUNT=$(find custom_components/* -maxdepth 0 -type d | wc -l)
if [ "$DIR_COUNT" -ne "1" ]; then
echo "Error: There must be exactly one custom component directory." >&2
exit 1
fi
echo "DOMAIN=$(basename $(find custom_components/* -maxdepth 0 -type d))" >> $GITHUB_ENV
- name: Install JQ
run: sudo apt-get install jq
- name: Extract version from current commit
id: current_version
run: echo "CURRENT_VERSION=$(jq -r '.version' custom_components/$DOMAIN/manifest.json)" >> $GITHUB_ENV
- name: Extract version from previous commit
id: previous_version
run: echo "PREVIOUS_VERSION=$(git show HEAD~:custom_components/$DOMAIN/manifest.json | jq -r '.version')" >> $GITHUB_ENV
- name: Collect Changes
if: ${{ env.CURRENT_VERSION != env.PREVIOUS_VERSION }}
id: collect_changes
run: |
PREVIOUS_TAG=$(git rev-list -n 1 v${{ env.PREVIOUS_VERSION }})
CURRENT_SHA=${{ github.sha }}
if [ -z "$PREVIOUS_TAG" ]; then
# Fallback in case there's no previous tag
CHANGELOG=$(git log --pretty=format:"%s%n%b" $(git rev-list --max-parents=0 HEAD)..$CURRENT_SHA)
else
CHANGELOG=$(git log --pretty=format:"%s%n%b" $PREVIOUS_TAG..$CURRENT_SHA)
fi
# Initialize section variables
ALL_FEATURES=""
ALL_FIXES=""
ALL_CHANGES=""
ALL_OTHER=""
# Process each commit message
echo "$CHANGELOG" | while IFS= read -r line; do
if [[ "$line" == "feat"* ]]; then
ALL_FEATURES+="- $line\n"
elif [[ "$line" == "fix"* ]]; then
ALL_FIXES+="- $line\n"
elif [[ "$line" == "refactor"* ]]; then
ALL_CHANGES+="- $line\n"
else
ALL_OTHER+="- $line\n"
fi
done
# Start with an empty formatted changelog
CHANGELOG=""
# Add sections if not empty
if [ ! -z "$ALL_FEATURES" ]; then
CHANGELOG+="## :new: Нововведения\n\n${ALL_FEATURES}\n"
fi
if [ ! -z "$ALL_FIXES" ]; then
CHANGELOG+="## :bug: Исправления\n\n${ALL_FIXES}\n"
fi
if [ ! -z "$ALL_CHANGES" ]; then
CHANGELOG+="## :wrench: Изменения\n\n${ALL_CHANGES}"
fi
if [ ! -z "$ALL_OTHER" ]; then
CHANGELOG+="## :information_source: Примечания\n\n${ALL_OTHER}"
fi
# Save to GITHUB_ENV
{
echo "CHANGELOG<<EOF"
echo -e "$CHANGELOG" | sed '$d'
echo "EOF"
} >> "$GITHUB_ENV"
- name: Create Tag
if: ${{ env.CURRENT_VERSION != env.PREVIOUS_VERSION }}
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.current_version.outputs.version }}';
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/v${version}`,
sha: '${{ github.sha }}'
});
- name: Create Pre-release
if: ${{ env.CURRENT_VERSION != env.PREVIOUS_VERSION }}
uses: actions/github-script@v7
with:
script: |
const {CHANGELOG, CURRENT_VERSION} = process.env;
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${CURRENT_VERSION}`,
name: `v${CURRENT_VERSION}`,
body: `${CHANGELOG}`,
draft: false,
prerelease: true,
});