|
34 | 34 | } |
35 | 35 |
|
36 | 36 | # 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 |
38 | 41 |
|
39 | 42 | # Inform if build steps are skipped |
40 | 43 | -name:Inform Skipped Build Steps |
@@ -182,40 +185,66 @@ jobs: |
182 | 185 | # Save the current date and time to an environment variable |
183 | 186 | echo "current_datetime=$(date +'%d/%m/%Y %H:%M')" >> $GITHUB_ENV |
184 | 187 |
|
185 | | -#Step to get previous tag and commits |
186 | | - -name:Get commits since lastrelease |
| 188 | +#Get commits since last build |
| 189 | + -name:Get commits since lastnumeric CI tag |
187 | 190 | id:get_commits |
188 | | -if:env.build_trigger == 'true'# Only run if build was triggered |
| 191 | +if:env.build_trigger == 'true' |
189 | 192 | shell:bash |
190 | 193 | 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" |
196 | 215 | 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." |
200 | 225 | 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" |
203 | 232 |
|
204 | | -# Createa release |
| 233 | +# Createthe release with that commit list |
205 | 234 | -name:Create Release |
206 | 235 | id:create_release |
207 | | -if:env.build_trigger == 'true'# Execute only if build was triggered |
| 236 | +if:env.build_trigger == 'true' |
208 | 237 | uses:actions/create-release@latest |
209 | 238 | env: |
210 | 239 | GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }} |
211 | 240 | with: |
212 | | -tag_name:${{github.run_number}} |
| 241 | +tag_name:${{github.run_number}} |
213 | 242 | release_name:${{ env.current_datetime }} (${{ github.run_number }}) |
214 | 243 | body:| |
215 | 244 | 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 }} |
219 | 248 | draft:false |
220 | 249 | prerelease:false |
221 | 250 |
|
|