Skip to content

Commit 9225a04

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

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

.github/workflows/publish_release.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ 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+
BASE_COMMIT=$(git rev-parse HEAD)
79+
80+
sed -E -i "s#print\(\".*\"\)#print\(\"${{ steps.swift_format_version.outputs.swift_format_version }}\"\)#" Sources/swift-format/PrintVersion.swift
81+
82+
if ! git diff --quiet Sources/swift-format/PrintVersion.swift; then
83+
echo "Detected change in PrintVersion.swift — committing and pushing"
84+
git add Sources/swift-format/PrintVersion.swift
85+
git commit -m "Change version to ${{ steps.swift_format_version.outputs.swift_format_version }}"
86+
git push origin HEAD:$BRANCH_NAME
87+
else
88+
echo "No changes in PrintVersion.swift — skipping commit/push"
89+
fi
7090
- name: Create release commits
7191
id: create_release_commits
7292
run: |
@@ -81,10 +101,6 @@ jobs:
81101
git add Package.swift
82102
git commit -m "Change swift-syntax dependency to ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}"
83103
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-
88104
{
89105
echo 'release_commit_patch<<EOF'
90106
git format-patch "$BASE_COMMIT"..HEAD --stdout

0 commit comments

Comments
 (0)