Skip to content

Commit 29ac238

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

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

.github/workflows/publish_release.yml

+19-4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ jobs:
6767
echo "swift_format_version=$SWIFT_FORMAT_VERSION" >> "$GITHUB_OUTPUT"
6868
- name: Checkout repository
6969
uses: actions/checkout@v4
70+
- name: Create version commit if version changed
71+
run: |
72+
# Without this, we can't perform git operations in GitHub actions.
73+
git config --global --add safe.directory "$(realpath .)"
74+
git config --local user.name 'swift-ci'
75+
git config --local user.email '[email protected]'
76+
77+
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
78+
79+
sed -E -i "s#print\(\".*\"\)#print\(\"${{ steps.swift_format_version.outputs.swift_format_version }}\"\)#" Sources/swift-format/PrintVersion.swift
80+
81+
if ! git diff --quiet Sources/swift-format/PrintVersion.swift; then
82+
echo "Detected change in PrintVersion.swift — committing and pushing"
83+
git add Sources/swift-format/PrintVersion.swift
84+
git commit -m "Change version to ${{ steps.swift_format_version.outputs.swift_format_version }}"
85+
git push origin HEAD:$BRANCH_NAME
86+
else
87+
echo "No changes in PrintVersion.swift — skipping commit/push"
88+
fi
7089
- name: Create release commits
7190
id: create_release_commits
7291
run: |
@@ -81,10 +100,6 @@ jobs:
81100
git add Package.swift
82101
git commit -m "Change swift-syntax dependency to ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}"
83102
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-
88103
{
89104
echo 'release_commit_patch<<EOF'
90105
git format-patch "$BASE_COMMIT"..HEAD --stdout

0 commit comments

Comments
 (0)