@@ -34,12 +34,12 @@ jobs:
34
34
echo "${{ github.triggering_actor }} is not allowed to create a release"
35
35
exit 1
36
36
fi
37
- define_tags :
38
- name : Determine dependent swift-syntax version and prerelease date
37
+ create_release_commits :
38
+ name : Create release commits
39
39
runs-on : ubuntu-latest
40
40
outputs :
41
- swift_syntax_tag : ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}
42
41
swift_format_version : ${{ steps.swift_format_version.outputs.swift_format_version }}
42
+ release_commit_patch : ${{ steps.create_release_commits.outputs.release_commit_patch }}
43
43
steps :
44
44
- name : Determine swift-syntax tag to depend on
45
45
id : swift_syntax_tag
@@ -65,37 +65,100 @@ jobs:
65
65
fi
66
66
echo "Using swift-format version: $SWIFT_FORMAT_VERSION"
67
67
echo "swift_format_version=$SWIFT_FORMAT_VERSION" >> "$GITHUB_OUTPUT"
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 '[email protected] '
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"
68
93
test_debug :
69
94
name : Test in Debug configuration
70
- uses : swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
71
- needs : define_tags
95
+ uses : swiftlang/github-workflows/.github/workflows/swift_package_test.yml@windows-pre-build
96
+ needs : create_release_commits
72
97
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 }}'
98
+ linux_pre_build_command : |
99
+ git config --global --add safe.directory "$(realpath .)"
100
+ git config --local user.name 'swift-ci'
101
+ git config --local user.email '[email protected] '
102
+ git am << EOF
103
+ ${{ needs.create_release_commits.outputs.release_commit_patch }}
104
+ EOF
105
+ windows_pre_build_command : |
106
+ git config --local user.name "swift-ci"
107
+ git config --local user.email "[email protected] "
108
+ echo @"
109
+ ${{ needs.create_release_commits.outputs.release_commit_patch }}
110
+ "@ > $env:TEMP\patch.diff
111
+ # For some reason `git am` fails in Powershell with the following error. Executing it in cmd works...
112
+ # fatal: empty ident name (for <>) not allowed
113
+ cmd /c "type $env:TEMP\patch.diff | git am || (exit /b 1)"
74
114
# We require that releases of swift-format build without warnings
75
- build_command : swift test -Xswiftc -warnings-as-errors
115
+ linux_build_command : swift test -Xswiftc -warnings-as-errors
116
+ windows_build_command : swift test -Xswiftc -warnings-as-errors
76
117
test_release :
77
118
name : Test in Release configuration
78
- uses : swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
79
- needs : define_tags
119
+ uses : swiftlang/github-workflows/.github/workflows/swift_package_test.yml@windows-pre-build
120
+ needs : create_release_commits
80
121
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 }}'
122
+ linux_pre_build_command : |
123
+ git config --global --add safe.directory "$(realpath .)"
124
+ git config --local user.name 'swift-ci'
125
+ git config --local user.email '[email protected] '
126
+ git am << EOF
127
+ ${{ needs.create_release_commits.outputs.release_commit_patch }}
128
+ EOF
129
+ windows_pre_build_command : |
130
+ git config --local user.name "swift-ci"
131
+ git config --local user.email "[email protected] "
132
+ echo @"
133
+ ${{ needs.create_release_commits.outputs.release_commit_patch }}
134
+ "@ > $env:TEMP\patch.diff
135
+ # For some reason `git am` fails in Powershell with the following error. Executing it in cmd works...
136
+ # fatal: empty ident name (for <>) not allowed
137
+ cmd /c "type $env:TEMP\patch.diff | git am || (exit /b 1)"
82
138
# We require that releases of swift-format build without warnings
83
- build_command : swift test -c release -Xswiftc -warnings-as-errors
139
+ linux_build_command : swift test -Xswiftc -warnings-as-errors
140
+ windows_build_command : swift test -Xswiftc -warnings-as-errors
84
141
create_tag :
85
142
name : Create Tag
86
143
runs-on : ubuntu-latest
87
- needs : [check_triggering_actor, test_debug, test_release, define_tags ]
144
+ needs : [check_triggering_actor, test_debug, create_release_commits ]
88
145
permissions :
89
146
contents : write
90
147
steps :
91
148
- name : Checkout repository
92
149
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 }}'
150
+ - name : Apply release commits
151
+ run : |
152
+ git config --global --add safe.directory "$(realpath .)"
153
+ git config --local user.name 'swift-ci'
154
+ git config --local user.email '[email protected] '
155
+ git am << EOF
156
+ ${{ needs.create_release_commits.outputs.release_commit_patch }}
157
+ EOF
95
158
- name : Tag release
96
159
run : |
97
- git tag "${{ needs.define_tags .outputs.swift_format_version }}"
98
- git push origin "${{ needs.define_tags .outputs.swift_format_version }}"
160
+ git tag "${{ needs.create_release_commits .outputs.swift_format_version }}"
161
+ git push origin "${{ needs.create_release_commits .outputs.swift_format_version }}"
99
162
- name : Create release
100
163
env :
101
164
GH_TOKEN : ${{ github.token }}
@@ -104,6 +167,6 @@ jobs:
104
167
# Only create a release automatically for prereleases. For real releases, release notes should be crafted by hand.
105
168
exit
106
169
fi
107
- gh release create "${{ needs.define_tags .outputs.swift_format_version }}" \
108
- --title "${{ needs.define_tags .outputs.swift_format_version }}" \
170
+ gh release create "${{ needs.create_release_commits .outputs.swift_format_version }}" \
171
+ --title "${{ needs.create_release_commits .outputs.swift_format_version }}" \
109
172
--prerelease
0 commit comments