Skip to content

Commit fc82a67

Browse files
authored
#GITBUILD test
1 parent d032b62 commit fc82a67

File tree

1 file changed

+49
-20
lines changed

1 file changed

+49
-20
lines changed

.github/workflows/main.yml

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ jobs:
3434
}
3535
3636
# Step to ensure the repository is checked out
37-
- uses: actions/checkout@v2
37+
- uses: actions/checkout@v4
38+
with:
39+
fetch-depth: 0
40+
fetch-tags: true
3841

3942
# Inform if build steps are skipped
4043
- name: Inform Skipped Build Steps
@@ -182,40 +185,66 @@ jobs:
182185
# Save the current date and time to an environment variable
183186
echo "current_datetime=$(date +'%d/%m/%Y %H:%M')" >> $GITHUB_ENV
184187
185-
# Step to get previous tag and commits
186-
- name: Get commits since last release
188+
# Get commits since last build
189+
- name: Get commits since last numeric CI tag
187190
id: get_commits
188-
if: env.build_trigger == 'true' # Only run if build was triggered
191+
if: env.build_trigger == 'true'
189192
shell: bash
190193
run: |
191-
# Get the most recent tag
192-
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
193-
if [ "$PREV_TAG" = "none" ]; then
194-
echo "No previous tag found, listing all commits"
195-
COMMITS=$(git log --pretty=format:"* %s" --no-merges)
194+
set -euo pipefail
195+
196+
# Defensive: fetch tags
197+
git fetch --tags --force
198+
199+
# Collect numeric-only tags (e.g., 145, 143...) and sort ascending numerically
200+
mapfile -t NUM_TAGS < <(git tag --list '[0-9]*' | sort -n)
201+
202+
PREV_TAG=""
203+
# Walk from newest to oldest and pick the newest tag that is an ancestor of HEAD
204+
for (( idx=${#NUM_TAGS[@]}-1 ; idx>=0 ; idx-- )); do
205+
t="${NUM_TAGS[$idx]}"
206+
if git merge-base --is-ancestor "$t" HEAD; then
207+
PREV_TAG="$t"
208+
break
209+
fi
210+
done
211+
212+
if [ -z "$PREV_TAG" ]; then
213+
echo "No previous numeric CI tag reachable from HEAD → listing all commits"
214+
RANGE="--all"
196215
else
197-
echo "Previous tag: $PREV_TAG"
198-
# List commits since last tag
199-
COMMITS=$(git log $PREV_TAG..HEAD --pretty=format:"* %s" --no-merges)
216+
echo "Previous CI tag: $PREV_TAG"
217+
RANGE="$PREV_TAG..HEAD"
218+
fi
219+
220+
# Nicely formatted bullets; add --date=short if you want dates
221+
COMMITS=$(git log $RANGE --no-merges --pretty='* %h %s (by %an)')
222+
223+
if [ -z "$COMMITS" ]; then
224+
COMMITS="* No code changes since last CI tag."
200225
fi
201-
# Save commits to the environment
202-
echo "commits=$COMMITS" >> $GITHUB_ENV
226+
227+
{
228+
echo 'commits<<EOF'
229+
printf '%s\n' "$COMMITS"
230+
echo 'EOF'
231+
} >> "$GITHUB_OUTPUT"
203232

204-
# Create a release
233+
# Create the release with that commit list
205234
- name: Create Release
206235
id: create_release
207-
if: env.build_trigger == 'true' # Execute only if build was triggered
236+
if: env.build_trigger == 'true'
208237
uses: actions/create-release@latest
209238
env:
210239
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
211240
with:
212-
tag_name: ${{github.run_number}}
241+
tag_name: ${{ github.run_number }}
213242
release_name: ${{ env.current_datetime }} (${{ github.run_number }})
214243
body: |
215244
Automated Release by GitHub Action CI
216-
217-
### Commits in this release:
218-
${{ env.commits }}
245+
246+
### Commits in this release
247+
${{ steps.get_commits.outputs.commits }}
219248
draft: false
220249
prerelease: false
221250

0 commit comments

Comments
 (0)