Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Cross-PR testing #867

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/workflows/create-release-commits.sh

This file was deleted.

91 changes: 67 additions & 24 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
echo "${{ github.triggering_actor }} is not allowed to create a release"
exit 1
fi
define_tags:
name: Determine dependent swift-syntax version and prerelease date
create_release_commits:
name: Create release commits
runs-on: ubuntu-latest
outputs:
swift_syntax_tag: ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}
swift_format_version: ${{ steps.swift_format_version.outputs.swift_format_version }}
release_commit_patch: ${{ steps.create_release_commits.outputs.release_commit_patch }}
steps:
- name: Determine swift-syntax tag to depend on
id: swift_syntax_tag
Expand All @@ -65,37 +65,80 @@ jobs:
fi
echo "Using swift-format version: $SWIFT_FORMAT_VERSION"
echo "swift_format_version=$SWIFT_FORMAT_VERSION" >> "$GITHUB_OUTPUT"
test_debug:
name: Test in Debug configuration
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
needs: define_tags
with:
pre_build_command: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
# We require that releases of swift-format build without warnings
build_command: swift test -Xswiftc -warnings-as-errors
test_release:
name: Test in Release configuration
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
needs: define_tags
- name: Checkout repository
uses: actions/checkout@v4
- name: Create release commits
id: create_release_commits
run: |
# Without this, we can't perform git operations in GitHub actions.
git config --global --add safe.directory "$(realpath .)"
git config --local user.name 'swift-ci'
git config --local user.email 'swift-ci@users.noreply.github.com'

BASE_COMMIT=$(git rev-parse HEAD)

sed -E -i "s#branch: \"(main|release/[0-9]+\.[0-9]+)\"#from: \"${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}\"#" Package.swift
git add Package.swift
git commit -m "Change swift-syntax dependency to ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}"

sed -E -i "s#print\(\".*\"\)#print\(\"${{ steps.swift_format_version.outputs.swift_format_version }}\"\)#" Sources/swift-format/PrintVersion.swift
git add Sources/swift-format/PrintVersion.swift
git commit -m "Change version to ${{ steps.swift_format_version.outputs.swift_format_version }}"

{
echo 'release_commit_patch<<EOF'
git format-patch "$BASE_COMMIT"..HEAD --stdout
echo EOF
} >> "$GITHUB_OUTPUT"
test:
name: Test in ${{ matrix.release && 'Release' || 'Debug' }} configuration
uses: ahoppen/github-workflows/.github/workflows/swift_package_test.yml@windows-5.10
needs: create_release_commits
strategy:
fail-fast: false
matrix:
release: [false]
with:
pre_build_command: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
linux_pre_build_command: |
git config --global --add safe.directory "$(realpath .)"
git config --local user.name 'swift-ci'
git config --local user.email 'swift-ci@users.noreply.github.com'
git am << EOF
${{ needs.create_release_commits.outputs.release_commit_patch }}
EOF
windows_pre_build_command: |
git config --local user.name "swift-ci"
git config --local user.email "swift-ci@users.noreply.github.com"
echo @"
${{ needs.create_release_commits.outputs.release_commit_patch }}
"@ > $env:TEMP\patch.diff
# For some reason `git am` fails in Powershell with the following error. Executing it in cmd works...
# fatal: empty ident name (for <>) not allowed
cmd /c "type $env:TEMP\patch.diff | git am || (exit /b 1)"
# We require that releases of swift-format build without warnings
build_command: swift test -c release -Xswiftc -warnings-as-errors
linux_build_command: swift test -Xswiftc -warnings-as-errors ${{ matrix.release && '-c release' }}
windows_build_command: swift test -Xswiftc -warnings-as-errors ${{ matrix.release && '-c release' }}
create_tag:
name: Create Tag
runs-on: ubuntu-latest
needs: [check_triggering_actor, test_debug, test_release, define_tags]
needs: [check_triggering_actor, test, create_release_commits]
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create release commits
run: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
- name: Apply release commits
run: |
git config --global --add safe.directory "$(realpath .)"
git config --local user.name 'swift-ci'
git config --local user.email 'swift-ci@users.noreply.github.com'
git am << EOF
${{ needs.create_release_commits.outputs.release_commit_patch }}
EOF
- name: Tag release
run: |
git tag "${{ needs.define_tags.outputs.swift_format_version }}"
git push origin "${{ needs.define_tags.outputs.swift_format_version }}"
git tag "${{ needs.create_release_commits.outputs.swift_format_version }}"
git push origin "${{ needs.create_release_commits.outputs.swift_format_version }}"
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
Expand All @@ -104,6 +147,6 @@ jobs:
# Only create a release automatically for prereleases. For real releases, release notes should be crafted by hand.
exit
fi
gh release create "${{ needs.define_tags.outputs.swift_format_version }}" \
--title "${{ needs.define_tags.outputs.swift_format_version }}" \
gh release create "${{ needs.create_release_commits.outputs.swift_format_version }}" \
--title "${{ needs.create_release_commits.outputs.swift_format_version }}" \
--prerelease
14 changes: 8 additions & 6 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ on:
jobs:
tests:
name: Test
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
soundness:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
uses: ahoppen/github-workflows/.github/workflows/swift_package_test.yml@cross-pr-testing
with:
license_header_check_enabled: false
license_header_check_project_name: "Swift.org"
enable_cross_pr_testing: true
# soundness:
# name: Soundness
# uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
# with:
# license_header_check_enabled: false
# license_header_check_project_name: "Swift.org"
37 changes: 23 additions & 14 deletions Sources/SwiftFormat/Rules/UseShorthandTypeNames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,28 @@ public final class UseShorthandTypeNames: SyntaxFormatRule {

switch node.name.text {
case "Array":
guard let typeArgument = genericArgumentList.firstAndOnly else {
guard let argument = genericArgumentList.firstAndOnly,
case .type(let typeArgument) = argument.argument else {
newNode = nil
break
}

newNode = shorthandArrayType(
element: typeArgument.argument,
element: typeArgument,
leadingTrivia: leadingTrivia,
trailingTrivia: trailingTrivia
)

case "Dictionary":
guard let typeArguments = exactlyTwoChildren(of: genericArgumentList) else {
guard let arguments = exactlyTwoChildren(of: genericArgumentList),
case .type(let type0Argument) = arguments.0.argument,
case .type(let type1Argument) = arguments.1.argument else {
newNode = nil
break
}
newNode = shorthandDictionaryType(
key: typeArguments.0.argument,
value: typeArguments.1.argument,
key: type0Argument,
value: type1Argument,
leadingTrivia: leadingTrivia,
trailingTrivia: trailingTrivia
)
Expand All @@ -74,12 +78,13 @@ public final class UseShorthandTypeNames: SyntaxFormatRule {
newNode = nil
break
}
guard let typeArgument = genericArgumentList.firstAndOnly else {
guard let argument = genericArgumentList.firstAndOnly,
case .type(let typeArgument) = argument.argument else {
newNode = nil
break
}
newNode = shorthandOptionalType(
wrapping: typeArgument.argument,
wrapping: typeArgument,
leadingTrivia: leadingTrivia,
trailingTrivia: trailingTrivia
)
Expand Down Expand Up @@ -137,38 +142,42 @@ public final class UseShorthandTypeNames: SyntaxFormatRule {

switch expression.baseName.text {
case "Array":
guard let typeArgument = genericArgumentList.firstAndOnly else {
guard let argument = genericArgumentList.firstAndOnly,
case .type(let typeArgument) = argument.argument else {
newNode = nil
break
}
let arrayTypeExpr = makeArrayTypeExpression(
elementType: typeArgument.argument,
elementType: typeArgument,
leftSquare: TokenSyntax.leftSquareToken(leadingTrivia: leadingTrivia),
rightSquare: TokenSyntax.rightSquareToken(trailingTrivia: trailingTrivia)
)
newNode = ExprSyntax(arrayTypeExpr)

case "Dictionary":
guard let typeArguments = exactlyTwoChildren(of: genericArgumentList) else {
guard let arguments = exactlyTwoChildren(of: genericArgumentList),
case .type(let type0Argument) = arguments.0.argument,
case .type(let type1Argument) = arguments.1.argument else {
newNode = nil
break
}
let dictTypeExpr = makeDictionaryTypeExpression(
keyType: typeArguments.0.argument,
valueType: typeArguments.1.argument,
keyType: type0Argument,
valueType: type1Argument,
leftSquare: TokenSyntax.leftSquareToken(leadingTrivia: leadingTrivia),
colon: TokenSyntax.colonToken(trailingTrivia: .spaces(1)),
rightSquare: TokenSyntax.rightSquareToken(trailingTrivia: trailingTrivia)
)
newNode = ExprSyntax(dictTypeExpr)

case "Optional":
guard let typeArgument = genericArgumentList.firstAndOnly else {
guard let argument = genericArgumentList.firstAndOnly,
case .type(let typeArgument) = argument.argument else {
newNode = nil
break
}
let optionalTypeExpr = makeOptionalTypeExpression(
wrapping: typeArgument.argument,
wrapping: typeArgument,
leadingTrivia: leadingTrivia,
questionMark: TokenSyntax.postfixQuestionMarkToken(trailingTrivia: trailingTrivia)
)
Expand Down
Loading