Skip to content

Commit 01a6471

Browse files
committed
Update publish_release action to commit and push PrintVersion.swift changes if needed
1 parent 88a8900 commit 01a6471

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

.github/workflows/publish_release.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ jobs:
6767
echo "swift_format_version=$SWIFT_FORMAT_VERSION" >> "$GITHUB_OUTPUT"
6868
- name: Checkout repository
6969
uses: actions/checkout@v4
70+
71+
- name: Create version commit if version changed
72+
run: |
73+
# Without this, we can't perform git operations in GitHub actions.
74+
git config --global --add safe.directory "$(realpath .)"
75+
git config --local user.name 'swift-ci'
76+
git config --local user.email '[email protected]'
77+
78+
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
79+
BASE_COMMIT=$(git rev-parse HEAD)
80+
81+
sed -E -i "s#print\(\".*\"\)#print\(\"${{ steps.swift_format_version.outputs.swift_format_version }}\"\)#" Sources/swift-format/PrintVersion.swift
82+
83+
if ! git diff --quiet Sources/swift-format/PrintVersion.swift; then
84+
echo "Detected change in PrintVersion.swift — committing and pushing"
85+
git add Sources/swift-format/PrintVersion.swift
86+
git commit -m "Change version to ${{ steps.swift_format_version.outputs.swift_format_version }}"
87+
git push origin HEAD:$BRANCH_NAME
88+
else
89+
echo "No changes in PrintVersion.swift — skipping commit/push"
90+
fi
91+
7092
- name: Create release commits
7193
id: create_release_commits
7294
run: |
@@ -81,10 +103,6 @@ jobs:
81103
git add Package.swift
82104
git commit -m "Change swift-syntax dependency to ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}"
83105
84-
sed -E -i "s#print\(\".*\"\)#print\(\"${{ steps.swift_format_version.outputs.swift_format_version }}\"\)#" Sources/swift-format/PrintVersion.swift
85-
git add Sources/swift-format/PrintVersion.swift
86-
git commit -m "Change version to ${{ steps.swift_format_version.outputs.swift_format_version }}"
87-
88106
{
89107
echo 'release_commit_patch<<EOF'
90108
git format-patch "$BASE_COMMIT"..HEAD --stdout

0 commit comments

Comments
 (0)