Skip to content

Commit b75aef4

Browse files
authored
refactor: extract repeated git identity configuration into reusable composite action (#203)
- [x] Add `develop/**` to `branches` filter in `.github/workflows/pull-request.yml`
1 parent 1840e67 commit b75aef4

7 files changed

Lines changed: 26 additions & 11 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: 'Configure git identity'
2+
author: 'Pete Sramek'
3+
description: 'Configures git user name and email from the last commit.'
4+
5+
runs:
6+
using: composite
7+
steps:
8+
- name: 'Configure git identity'
9+
shell: bash
10+
run: |
11+
git config user.name "$(git log -n 1 --pretty=format:%an)"
12+
git config user.email "$(git log -n 1 --pretty=format:%ae)"

.github/actions/git/push-changes/action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ runs:
8787
set -e
8888
working-directory: ${{ inputs.working-directory }}
8989

90+
- name: Configure git identity
91+
if: ${{ fromJSON(steps.validate.outputs.has-changes) == '1' }}
92+
uses: './.github/actions/git/configure-identity'
93+
9094
- name: Push changes to ${{ github.head_ref || github.ref }}
9195
if: ${{ fromJSON(steps.validate.outputs.has-changes) == '1' }}
9296
shell: bash
9397
run: |
94-
git config user.name "$(git log -n 1 --pretty=format:%an)"
95-
git config user.email "$(git log -n 1 --pretty=format:%ae)"
9698
git commit -m '${{ inputs.commit-message }}'
9799
git pull --rebase origin ${{ github.head_ref || github.ref }}
98100
git push

.github/actions/github/create-release/action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ runs:
2525
echo "notes-start-tag=${{ inputs.notes-start-tag }}"
2626
echo "notes-start-tag-argument=${{ inputs.notes-start-tag != '' && format('--notes-start-tag {0}', inputs.notes-start-tag) || '' }}"
2727
shell: bash
28+
- name: 'Configure git identity'
29+
uses: './.github/actions/git/configure-identity'
2830
- name: 'Create git tag ${{ inputs.release-version }}'
2931
shell: bash
3032
run: |

.github/workflows/backtrack.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ jobs:
3030
token: ${{ secrets.GH_ADMIN_TOKEN }}
3131

3232
- name: 'Configure git'
33-
run: |
34-
git config user.name "$(git log -n 1 --pretty=format:%an)"
35-
git config user.email "$(git log -n 1 --pretty=format:%ae)"
33+
uses: './.github/actions/git/configure-identity'
3634

3735
- name: 'Resolve backtrack targets'
3836
id: targets

.github/workflows/bump-version.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ jobs:
113113
dotnet-version: ${{ env.dotnet-sdk-version }}
114114

115115
- name: 'Configure git'
116-
run: |
117-
git config user.name "$(git log -n 1 --pretty=format:%an)"
118-
git config user.email "$(git log -n 1 --pretty=format:%ae)"
116+
uses: './.github/actions/git/configure-identity'
119117

120118
- name: 'Create develop branch from main'
121119
run: |

.github/workflows/pull-request.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ on:
88
- synchronize
99
- reopened
1010
branches:
11+
- 'develop/**'
1112
- 'preview/**'
12-
- 'release/**'
13+
- 'release/**'
1314

1415
permissions:
1516
actions: read

.github/workflows/release.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,13 @@ jobs:
358358
echo "support-branch-exists=false" >> $GITHUB_OUTPUT
359359
fi
360360
361+
- name: 'Configure git identity'
362+
if: ${{ steps.check-support-branch.outputs.support-branch-exists == 'false' }}
363+
uses: './.github/actions/git/configure-identity'
364+
361365
- name: 'Create support branch'
362366
if: ${{ steps.check-support-branch.outputs.support-branch-exists == 'false' }}
363367
run: |
364-
git config user.name "$(git log -n 1 --pretty=format:%an)"
365-
git config user.email "$(git log -n 1 --pretty=format:%ae)"
366368
git checkout -b "${{ steps.resolve-support-branch.outputs.support-branch }}"
367369
git push --set-upstream origin "${{ steps.resolve-support-branch.outputs.support-branch }}"
368370

0 commit comments

Comments
 (0)