Skip to content

Commit d31dbfd

Browse files
committed
chore: improve ci messages
1 parent dbe141c commit d31dbfd

1 file changed

Lines changed: 93 additions & 19 deletions

File tree

.github/workflows/release.yml

Lines changed: 93 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,123 @@
11
name: Build Docker Image and Publish Release
2-
32
on:
43
push:
54
tags:
65
- 'v*.*.*'
7-
86
jobs:
97
build_and_release:
108
runs-on: ubuntu-latest
11-
129
steps:
1310
- name: Checkout code
1411
uses: actions/checkout@v3
15-
12+
with:
13+
fetch-depth: 0 # Fetch all history for proper tag comparison
1614
- name: Set up Docker Buildx
1715
uses: docker/setup-buildx-action@v2
18-
1916
- name: Log in to GitHub Container Registry
2017
uses: docker/login-action@v2
2118
with:
2219
registry: ghcr.io
23-
username: ${{ secrets.GHCR_USERNAME }}
20+
username: ${{ github.actor }}
2421
password: ${{ secrets.GHCR_TOKEN }}
25-
2622
- name: Build Docker image
2723
run: |
28-
docker build -t ghcr.io/team-spiral-racing/docs:${{ github.ref_name }} .
29-
24+
REPO_NAME=${{ github.repository }}
25+
LOWERCASE_REPO_NAME=$(echo "$REPO_NAME" | tr '[:upper:]' '[:lower:]')
26+
docker build -t ghcr.io/${{ github.actor }}/$LOWERCASE_REPO_NAME:${{ github.ref_name }} .
3027
- name: Push Docker image to GitHub Container Registry
3128
run: |
32-
docker push ghcr.io/team-spiral-racing/docs:${{ github.ref_name }}
33-
29+
REPO_NAME=${{ github.repository }}
30+
LOWERCASE_REPO_NAME=$(echo "$REPO_NAME" | tr '[:upper:]' '[:lower:]')
31+
docker push ghcr.io/${{ github.actor }}/$LOWERCASE_REPO_NAME:${{ github.ref_name }}
3432
- name: Generate release notes
3533
id: generate_release_notes
3634
run: |
37-
release_notes=$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"* %s (%an)" | sed 's/\\n/\\n\\n/g')
38-
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
39-
echo "$release_notes" >> $GITHUB_ENV
40-
echo "EOF" >> $GITHUB_ENV
41-
35+
# Get the previous tag (skip the current tag)
36+
PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -v "^${{ github.ref_name }}$" | head -n 1)
37+
38+
if [ -z "$PREVIOUS_TAG" ]; then
39+
# If no previous tag exists, get all commits
40+
COMMIT_RANGE="HEAD"
41+
echo "No previous tag found, getting all commits"
42+
else
43+
# Get commits between previous tag and current tag
44+
COMMIT_RANGE="$PREVIOUS_TAG..${{ github.ref_name }}"
45+
echo "Getting commits from $PREVIOUS_TAG to ${{ github.ref_name }}"
46+
fi
47+
48+
# Get all commit messages with their types
49+
COMMITS=$(git log $COMMIT_RANGE --pretty=format:"%s|||%an" --reverse)
50+
51+
# Initialize release notes
52+
RELEASE_NOTES="## What's Changed"$'\n\n'
53+
54+
# Arrays to store different types of commits
55+
FEATURES=""
56+
FIXES=""
57+
DOCS=""
58+
CHORES=""
59+
OTHERS=""
60+
61+
# Process each commit
62+
while IFS='|||' read -r message author; do
63+
if [[ -n "$message" ]]; then
64+
# Extract commit type and description
65+
if [[ $message =~ ^feat(\(.+\))?!?:(.*)$ ]]; then
66+
FEATURES="${FEATURES}* ${BASH_REMATCH[2]# } (@${author})"$'\n'
67+
elif [[ $message =~ ^fix(\(.+\))?!?:(.*)$ ]]; then
68+
FIXES="${FIXES}* ${BASH_REMATCH[2]# } (@${author})"$'\n'
69+
elif [[ $message =~ ^docs(\(.+\))?!?:(.*)$ ]]; then
70+
DOCS="${DOCS}* ${BASH_REMATCH[2]# } (@${author})"$'\n'
71+
elif [[ $message =~ ^chore(\(.+\))?!?:(.*)$ ]]; then
72+
CHORES="${CHORES}* ${BASH_REMATCH[2]# } (@${author})"$'\n'
73+
elif [[ $message =~ ^(style|refactor|perf|test|build|ci)(\(.+\))?!?:(.*)$ ]]; then
74+
OTHERS="${OTHERS}* ${BASH_REMATCH[3]# } (@${author})"$'\n'
75+
else
76+
# Non-semantic commits go to "Other Changes"
77+
OTHERS="${OTHERS}* ${message} (@${author})"$'\n'
78+
fi
79+
fi
80+
done <<< "$COMMITS"
81+
82+
# Build release notes sections
83+
if [[ -n "$FEATURES" ]]; then
84+
RELEASE_NOTES="${RELEASE_NOTES}### 🚀 Features"$'\n'"${FEATURES}"$'\n'
85+
fi
86+
87+
if [[ -n "$FIXES" ]]; then
88+
RELEASE_NOTES="${RELEASE_NOTES}### 🐛 Bug Fixes"$'\n'"${FIXES}"$'\n'
89+
fi
90+
91+
if [[ -n "$DOCS" ]]; then
92+
RELEASE_NOTES="${RELEASE_NOTES}### 📚 Documentation"$'\n'"${DOCS}"$'\n'
93+
fi
94+
95+
if [[ -n "$CHORES" ]]; then
96+
RELEASE_NOTES="${RELEASE_NOTES}### 🧹 Chores"$'\n'"${CHORES}"$'\n'
97+
fi
98+
99+
if [[ -n "$OTHERS" ]]; then
100+
RELEASE_NOTES="${RELEASE_NOTES}### 🔧 Other Changes"$'\n'"${OTHERS}"$'\n'
101+
fi
102+
103+
# If no commits found, add a default message
104+
if [[ "$RELEASE_NOTES" == "## What's Changed"$'\n\n' ]]; then
105+
RELEASE_NOTES="${RELEASE_NOTES}No changes found in this release."$'\n'
106+
fi
107+
108+
# Set the release notes as an environment variable
109+
{
110+
echo "RELEASE_NOTES<<EOF"
111+
echo "$RELEASE_NOTES"
112+
echo "EOF"
113+
} >> $GITHUB_ENV
114+
115+
# Debug output
116+
echo "Generated release notes:"
117+
echo "$RELEASE_NOTES"
42118
- name: Create .tar.gz archive of repository files
43119
run: |
44120
git archive --format=tar.gz --prefix=TeamSpiralRacing/ -o release-${{ github.ref_name }}.tar.gz HEAD
45-
46121
- name: Upload .tar.gz archive as a GitHub Release asset
47122
id: release
48123
uses: softprops/action-gh-release@v1
@@ -53,7 +128,6 @@ jobs:
53128
files: release-${{ github.ref_name }}.tar.gz
54129
env:
55130
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56-
57131
- name: Output Release URL
58132
run: |
59-
echo "Release URL: ${{ steps.release.outputs.html_url }}"
133+
echo "Release URL: ${{ steps.release.outputs.html_url }}"

0 commit comments

Comments
 (0)