@@ -67,24 +67,41 @@ 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 : |
7392 # Without this, we can't perform git operations in GitHub actions.
7493 git config --global --add safe.directory "$(realpath .)"
7594 git config --local user.name 'swift-ci'
7695 git config --local user.email '[email protected] ' 77-
96+
97+ BRANCH_NAME="${GITHUB_REF#refs/heads/}"
98+ git pull origin "$BRANCH_NAME"
7899 BASE_COMMIT=$(git rev-parse HEAD)
79100
80101 sed -E -i "s#branch: \"(main|release/[0-9]+\.[0-9]+)\"#from: \"${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}\"#" Package.swift
81102 git add Package.swift
82103 git commit -m "Change swift-syntax dependency to ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}"
83104
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-
88105 {
89106 echo 'release_commit_patch<<EOF'
90107 git format-patch "$BASE_COMMIT"..HEAD --stdout
0 commit comments