-
-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (105 loc) · 4.34 KB
/
Copy pathrelease.yml
File metadata and controls
124 lines (105 loc) · 4.34 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
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
122
123
124
name: "Tag, Release"
on:
push:
branches:
- main
paths:
- "InterventionImage.module.php"
workflow_dispatch:
jobs:
tag_and_release:
runs-on: ubuntu-latest
env:
VERSION_FILE: "InterventionImage.module.php"
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Configure Git User
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Extract module version
id: get_version
run: |
VERSION=$(php -r "\$c = file_get_contents('${{ env.VERSION_FILE }}'); preg_match('/[\'\"].*?version.*?[\'\"]\s*=>\s*[\'\"]?([0-9\.]+)[\'\"]?/', \$c, \$m); \$v = \$m[1] ?? ''; if(is_numeric(\$v) && strpos((string)\$v, '.') === false) { \$v = (int)\$v; \$major = intval(\$v / 100); \$minor = intval(\$v / 10) % 10; \$micro = \$v % 10; \$v = \"\$major.\$minor.\$micro\"; } echo \$v;")
if [ -z "$VERSION" ]; then
echo "::error::Could not find the version number in ${{ env.VERSION_FILE }}"
exit 1
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
run: |
TAG="v${{ steps.get_version.outputs.version }}"
if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag $TAG already exists on remote. Skipping release."
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create Git Tag and GitHub Release
if: steps.check_tag.outputs.exists == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="v${{ steps.get_version.outputs.version }}"
REPO=${{ github.repository }}
echo "Generated Tag: $TAG"
git tag $TAG
git push origin $TAG
# Custom Release Notes Generator
echo "## What's Changed" > release_notes.md
echo "" >> release_notes.md
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
COMMITS=$(git log --format="%H" $PREV_TAG..HEAD)
COMPARE_URL="https://github.com/$REPO/compare/$PREV_TAG...$TAG"
else
COMMITS=$(git log --format="%H" HEAD)
COMPARE_URL="https://github.com/$REPO/commits/$TAG"
fi
SEEN_AUTHORS=()
CONTRIBUTORS_HTML=""
for SHA in $COMMITS; do
TITLE=$(git log --format="%s" -n 1 $SHA)
SHORT_SHA=$(git rev-parse --short $SHA)
LOGIN=$(gh api repos/$REPO/commits/$SHA --jq '.author.login // empty' 2>/dev/null || echo "")
if [ -z "$LOGIN" ]; then
LOGIN=$(git log --format="%an" -n 1 $SHA)
fi
AVATAR=$(gh api repos/$REPO/commits/$SHA --jq '.author.avatar_url // empty' 2>/dev/null || echo "")
if [[ "$LOGIN" == *" "* ]]; then
echo "* $TITLE by **$LOGIN** in $SHORT_SHA" >> release_notes.md
else
echo "* $TITLE by @$LOGIN in $SHORT_SHA" >> release_notes.md
fi
# Check if seen
SEEN=false
for SA in "${SEEN_AUTHORS[@]}"; do
if [ "$SA" == "$LOGIN" ]; then
SEEN=true
break
fi
done
if [ "$SEEN" = false ]; then
SEEN_AUTHORS+=("$LOGIN")
if [ -n "$AVATAR" ]; then
ITEM="<img src=\"$AVATAR\" width=\"24\" height=\"24\" style=\"border-radius: 50%; vertical-align: middle;\" alt=\"\"> $LOGIN"
else
ITEM="$LOGIN"
fi
if [ -z "$CONTRIBUTORS_HTML" ]; then
CONTRIBUTORS_HTML="$ITEM"
else
CONTRIBUTORS_HTML="$CONTRIBUTORS_HTML, $ITEM"
fi
fi
done
echo "" >> release_notes.md
echo "**Full Changelog**: $COMPARE_URL" >> release_notes.md
gh release create $TAG -F release_notes.md --title "$TAG"