Skip to content

Commit 39ee6a2

Browse files
committed
Run Windows tests before tagging a release
The GitHub workflows enabled Windows in the testing matrix. We needed to port the pre-build commands that apply the release commits to Windows to make the Windows checks pass.
1 parent 3ca1a18 commit 39ee6a2

File tree

2 files changed

+81
-46
lines changed

2 files changed

+81
-46
lines changed

.github/workflows/create-release-commits.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/publish_release.yml

Lines changed: 81 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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,100 @@ jobs:
6565
fi
6666
echo "Using swift-format version: $SWIFT_FORMAT_VERSION"
6767
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"
6893
test_debug:
6994
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
7297
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)"
74114
# 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
76117
test_release:
77118
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
80121
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)"
82138
# 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
84141
create_tag:
85142
name: Create Tag
86143
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]
88145
permissions:
89146
contents: write
90147
steps:
91148
- name: Checkout repository
92149
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
95158
- name: Tag release
96159
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 }}"
99162
- name: Create release
100163
env:
101164
GH_TOKEN: ${{ github.token }}
@@ -104,6 +167,6 @@ jobs:
104167
# Only create a release automatically for prereleases. For real releases, release notes should be crafted by hand.
105168
exit
106169
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 }}" \
109172
--prerelease

0 commit comments

Comments
 (0)