@@ -34,12 +34,12 @@ jobs:
3434 echo "${{ github.triggering_actor }} is not allowed to create a release"
3535 exit 1
3636 fi
37- define_tags :
38- name : Determine dependent swift-syntax version and prerelease date
37+ create_release_commits :
38+ name : Create release commits
3939 runs-on : ubuntu-latest
4040 outputs :
41- swift_syntax_tag : ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}
4241 swift_format_version : ${{ steps.swift_format_version.outputs.swift_format_version }}
42+ release_commit_patch : ${{ steps.create_release_commits.outputs.release_commit_patch }}
4343 steps :
4444 - name : Determine swift-syntax tag to depend on
4545 id : swift_syntax_tag
@@ -65,37 +65,80 @@ jobs:
6565 fi
6666 echo "Using swift-format version: $SWIFT_FORMAT_VERSION"
6767 echo "swift_format_version=$SWIFT_FORMAT_VERSION" >> "$GITHUB_OUTPUT"
68- test_debug :
69- name : Test in Debug configuration
70- uses : swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
71- needs : define_tags
72- with :
73- pre_build_command : bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
74- # We require that releases of swift-format build without warnings
75- build_command : swift test -Xswiftc -warnings-as-errors
76- test_release :
77- name : Test in Release configuration
68+ - name : Checkout repository
69+ uses : actions/checkout@v4
70+ - name : Create release commits
71+ id : create_release_commits
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 'swift-ci@users.noreply.github.com'
77+
78+ BASE_COMMIT=$(git rev-parse HEAD)
79+
80+ sed -E -i "s#branch: \"(main|release/[0-9]+\.[0-9]+)\"#from: \"${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}\"#" Package.swift
81+ git add Package.swift
82+ git commit -m "Change swift-syntax dependency to ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}"
83+
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+
88+ {
89+ echo 'release_commit_patch<<EOF'
90+ git format-patch "$BASE_COMMIT"..HEAD --stdout
91+ echo EOF
92+ } >> "$GITHUB_OUTPUT"
93+ test :
94+ name : Test in ${{ matrix.release && 'Release' || 'Debug' }} configuration
7895 uses : swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
79- needs : define_tags
96+ needs : create_release_commits
97+ strategy :
98+ fail-fast : false
99+ matrix :
100+ release : [true, false]
80101 with :
81- pre_build_command : bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
102+ linux_pre_build_command : |
103+ git config --global --add safe.directory "$(realpath .)"
104+ git config --local user.name 'swift-ci'
105+ git config --local user.email 'swift-ci@users.noreply.github.com'
106+ git am << EOF
107+ ${{ needs.create_release_commits.outputs.release_commit_patch }}
108+ EOF
109+ windows_pre_build_command : |
110+ git config --local user.name "swift-ci"
111+ git config --local user.email "swift-ci@users.noreply.github.com"
112+ echo @"
113+ ${{ needs.create_release_commits.outputs.release_commit_patch }}
114+ "@ > $env:TEMP\patch.diff
115+ # For some reason `git am` fails in Powershell with the following error. Executing it in cmd works...
116+ # fatal: empty ident name (for <>) not allowed
117+ cmd /c "type $env:TEMP\patch.diff | git am || (exit /b 1)"
82118 # We require that releases of swift-format build without warnings
83- build_command : swift test -c release -Xswiftc -warnings-as-errors
119+ linux_build_command : swift test -Xswiftc -warnings-as-errors ${{ matrix.release && '-c release' }}
120+ windows_build_command : swift test -Xswiftc -warnings-as-errors ${{ matrix.release && '-c release' }}
84121 create_tag :
85122 name : Create Tag
86123 runs-on : ubuntu-latest
87- needs : [check_triggering_actor, test_debug, test_release, define_tags ]
124+ needs : [check_triggering_actor, test, create_release_commits ]
88125 permissions :
89126 contents : write
90127 steps :
91128 - name : Checkout repository
92129 uses : actions/checkout@v4
93- - name : Create release commits
94- run : bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
130+ - name : Apply release commits
131+ run : |
132+ git config --global --add safe.directory "$(realpath .)"
133+ git config --local user.name 'swift-ci'
134+ git config --local user.email 'swift-ci@users.noreply.github.com'
135+ git am << EOF
136+ ${{ needs.create_release_commits.outputs.release_commit_patch }}
137+ EOF
95138 - name : Tag release
96139 run : |
97- git tag "${{ needs.define_tags .outputs.swift_format_version }}"
98- git push origin "${{ needs.define_tags .outputs.swift_format_version }}"
140+ git tag "${{ needs.create_release_commits .outputs.swift_format_version }}"
141+ git push origin "${{ needs.create_release_commits .outputs.swift_format_version }}"
99142 - name : Create release
100143 env :
101144 GH_TOKEN : ${{ github.token }}
@@ -104,6 +147,6 @@ jobs:
104147 # Only create a release automatically for prereleases. For real releases, release notes should be crafted by hand.
105148 exit
106149 fi
107- gh release create "${{ needs.define_tags .outputs.swift_format_version }}" \
108- --title "${{ needs.define_tags .outputs.swift_format_version }}" \
150+ gh release create "${{ needs.create_release_commits .outputs.swift_format_version }}" \
151+ --title "${{ needs.create_release_commits .outputs.swift_format_version }}" \
109152 --prerelease
0 commit comments