Skip to content

Commit 9f6e9b2

Browse files
authored
Merge branch 'main' into include-swift-versions
2 parents e38c3ee + 416e29a commit 9f6e9b2

17 files changed

+507
-48
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Create automerge PR
2+
3+
# Merges `head_branch` into `base_branch` and opens a PR to incorporate that merge commit into `base_branch`.
4+
#
5+
# The typical use case for this is in the first period after Swift has cut release branches.
6+
# Some repositories want to include most changes from `main` also in the release branch. When this job is set up, it can automatically create PRs to merge `main` into the release branch.
7+
# Maintainers of the package can then inspect the changes to ensure that they are not too risky for the release branch.
8+
# We will also run the normal PR testing on these changes, ensuring that these modifications don't break the build.
9+
#
10+
# Example usage in a repository:
11+
#
12+
# name: Create PR to merge main into release branch
13+
#
14+
# # In the first period after branching the release branch, we typically want to include all changes from `main` also in the release branch. This workflow automatically creates a PR every Monday to merge main into the release branch.
15+
# # Later in the release cycle we should stop this practice to avoid landing risky changes by disabling this workflow. To do so, disable the workflow as described in https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/disabling-and-enabling-a-workflow
16+
#
17+
# on:
18+
# schedule:
19+
# - cron: '0 9 * * MON'
20+
# workflow_dispatch:
21+
#
22+
# jobs:
23+
# create_merge_pr:
24+
# name: Create PR to merge main into release branch
25+
# uses: swiftlang/github-workflows/.github/workflows/create_autmerge_pr.yml@main
26+
# if: (github.event_name == 'schedule' && github.repository == 'swiftlang/swift-format') || (github.event_name != 'schedule') # Ensure that we don't run this on a schedule in a fork
27+
# with:
28+
# base_branch: release/6.2
29+
30+
on:
31+
workflow_call:
32+
inputs:
33+
base_branch:
34+
type: string
35+
description: The branch into which head_branch should be merged
36+
required: true
37+
head_branch:
38+
type: string
39+
description: The branch that should be merged into base_branch
40+
default: main
41+
pr_message:
42+
type: string
43+
description: The message that should be included in the PR created by this job
44+
default: This PR was automatically opened by a GitHub action. Review the changes included in this PR and determine if they should be included in the release branch. If yes, merge the PR. Otherwise revert changes that should not be included on this branch.
45+
46+
jobs:
47+
create_merge_pr:
48+
name: Create PR to merge ${{ inputs.head_branch }} into ${{ inputs.base_branch }} branch
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 0
55+
- name: Create merge commit
56+
id: create_merge_commit
57+
run: |
58+
# Without this, we can't perform git operations in GitHub actions.
59+
git config --global --add safe.directory "$(realpath .)"
60+
git config --local user.name 'swift-ci'
61+
git config --local user.email '[email protected]'
62+
63+
git checkout ${{ inputs.base_branch }}
64+
git merge ${{ inputs.head_branch }}
65+
66+
if [[ "$(git rev-parse HEAD)" = "$(git rev-parse ${{ inputs.head_branch }})" ]]; then
67+
echo "has_merged_commits=true" >> "$GITHUB_OUTPUT"
68+
else
69+
echo "has_merged_commits=false" >> "$GITHUB_OUTPUT"
70+
fi
71+
- name: Push branch and create PR
72+
id: push_branch
73+
if: ${{ steps.create_merge_commit.outputs.has_merged_commits == 'true' }}
74+
env:
75+
GH_TOKEN: ${{ github.token }}
76+
run: |
77+
PR_BRANCH="automerge/merge-main-$(date +%Y-%m-%d_%H-%M)"
78+
git checkout -b "$PR_BRANCH"
79+
git push --set-upstream origin "$PR_BRANCH"
80+
81+
gh pr create \
82+
--base "${{ inputs.base_branch }}" \
83+
--head "$PR_BRANCH" \
84+
--title 'Merge `${{ inputs.head_branch }}` into `${{ inputs.base_branch }}`' \
85+
--body '${{ inputs.pr_message }}'

.github/workflows/pull_request.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@ on:
55
types: [opened, reopened, synchronize]
66

77
jobs:
8+
tests_with_docker:
9+
name: Test with Docker
10+
uses: ./.github/workflows/swift_package_test.yml
11+
with:
12+
# Linux
13+
linux_build_command: |
14+
mkdir MyPackage
15+
cd MyPackage
16+
swift package init --type library
17+
swift build
18+
# Windows
19+
windows_build_command: |
20+
mkdir MyPackage
21+
cd MyPackage
22+
swift package init --type library
23+
swift build
24+
enable_windows_docker: true
25+
26+
tests_without_docker:
27+
name: Test without Docker
28+
uses: ./.github/workflows/swift_package_test.yml
29+
with:
30+
# Skip Linux which doesn't currently support docker-less workflow
31+
enable_linux_checks: false
32+
# Windows
33+
windows_build_command: |
34+
mkdir MyPackage
35+
cd MyPackage
36+
swift package init --type library
37+
swift build
38+
enable_windows_docker: false
39+
840
soundness:
941
name: Soundness
1042
uses: ./.github/workflows/soundness.yml

.github/workflows/scripts/check-docs.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,43 @@ log() { printf -- "** %s\n" "$*" >&2; }
1717
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
1818
fatal() { error "$@"; exit 1; }
1919

20-
log "Editing Package.swift..."
21-
cat <<EOF >> "Package.swift"
20+
if [ ! -f .spi.yml ]; then
21+
log "No '.spi.yml' found, no documentation targets to check."
22+
exit 0
23+
fi
24+
25+
if ! command -v yq &> /dev/null; then
26+
fatal "yq could not be found. Please install yq to proceed."
27+
fi
28+
29+
package_files=$(find . -maxdepth 1 -name 'Package*.swift')
30+
if [ -z "$package_files" ]; then
31+
fatal "Package.swift not found. Please ensure you are running this script from the root of a Swift package."
32+
fi
33+
34+
# yq 3.1.0-3 doesn't have filter, otherwise we could replace the grep call with "filter(.identity == "swift-docc-plugin") | keys | .[]"
35+
hasDoccPlugin=$(swift package dump-package | yq -r '.dependencies[].sourceControl' | grep -e "\"identity\": \"swift-docc-plugin\"" || true)
36+
if [[ -n $hasDoccPlugin ]]
37+
then
38+
log "swift-docc-plugin already exists"
39+
else
40+
log "Appending swift-docc-plugin"
41+
for package_file in $package_files; do
42+
log "Editing $package_file..."
43+
cat <<EOF >> "$package_file"
44+
2245
package.dependencies.append(
2346
.package(url: "https://github.com/swiftlang/swift-docc-plugin", "1.0.0"..<"1.4.0")
2447
)
2548
EOF
49+
done
50+
fi
2651

2752
log "Checking documentation targets..."
2853
for target in $(yq -r '.builder.configs[].documentation_targets[]' .spi.yml); do
2954
log "Checking target $target..."
30-
swift package plugin generate-documentation --target "$target" --warnings-as-errors --analyze --level detailed
55+
# shellcheck disable=SC2086 # We explicitly want to explode "$ADDITIONAL_DOCC_ARGUMENTS" into multiple arguments.
56+
swift package plugin generate-documentation --target "$target" --warnings-as-errors --analyze --level detailed $ADDITIONAL_DOCC_ARGUMENTS
3157
done
3258

3359
log "✅ Found no documentation issues."

.github/workflows/scripts/check-license-header.sh

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ log() { printf -- "** %s\n" "$*" >&2; }
1717
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
1818
fatal() { error "$@"; exit 1; }
1919

20-
test -n "${PROJECT_NAME:-}" || fatal "PROJECT_NAME unset"
21-
2220
if [ -f .license_header_template ]; then
2321
# allow projects to override the license header template
2422
expected_file_header_template=$(cat .license_header_template)
2523
else
24+
test -n "${PROJECT_NAME:-}" || fatal "PROJECT_NAME unset"
2625
expected_file_header_template="@@===----------------------------------------------------------------------===@@
2726
@@
2827
@@ This source file is part of the ${PROJECT_NAME} open source project
@@ -53,40 +52,67 @@ file_paths=$(echo "$exclude_list" | xargs git ls-files)
5352
while IFS= read -r file_path; do
5453
file_basename=$(basename -- "${file_path}")
5554
file_extension="${file_basename##*.}"
55+
if [[ -L "${file_path}" ]]; then
56+
continue # Ignore symbolic links
57+
fi
5658

59+
# The characters that are used to start a line comment and that replace '@@' in the license header template
60+
comment_marker=''
61+
# A line that we expect before the license header. This should end with a newline if it is not empty
62+
header_prefix=''
5763
# shellcheck disable=SC2001 # We prefer to use sed here instead of bash search/replace
5864
case "${file_extension}" in
59-
c) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
60-
cmake) expected_file_header=$(sed -e 's|@@|##|g' <<<"${expected_file_header_template}") ;;
61-
gradle) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
62-
groovy) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
63-
h) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
64-
in) expected_file_header=$(sed -e 's|@@|##|g' <<<"${expected_file_header_template}") ;;
65-
java) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
66-
js) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
67-
json) continue ;; # JSON doesn't support comments
68-
jsx) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
69-
kts) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
70-
proto) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
71-
ps1) expected_file_header=$(sed -e 's|@@|##|g' <<<"${expected_file_header_template}") ;;
72-
py) expected_file_header=$(cat <(echo '#!/usr/bin/env python3') <(sed -e 's|@@|##|g' <<<"${expected_file_header_template}")) ;;
73-
rb) expected_file_header=$(cat <(echo '#!/usr/bin/env ruby') <(sed -e 's|@@|##|g' <<<"${expected_file_header_template}")) ;;
74-
sh) expected_file_header=$(cat <(echo '#!/bin/bash') <(sed -e 's|@@|##|g' <<<"${expected_file_header_template}")) ;;
75-
swift) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
65+
bazel) comment_marker='##' ;;
66+
bazelrc) comment_marker='##' ;;
67+
bzl) comment_marker='##' ;;
68+
c) comment_marker='//' ;;
69+
cmake) comment_marker='##' ;;
70+
code-workspace) continue ;; # VS Code workspaces are JSON and shouldn't contain comments
71+
CODEOWNERS) continue ;; # Doesn't need a license header
72+
Dockerfile) comment_marker='##' ;;
73+
editorconfig) comment_marker='##' ;;
74+
flake8) continue ;; # Configuration file doesn't need a license header
75+
gitattributes) continue ;; # Configuration files don't need license headers
76+
gitignore) continue ;; # Configuration files don't need license headers
77+
gradle) comment_marker='//' ;;
78+
groovy) comment_marker='//' ;;
79+
gyb) comment_marker='//' ;;
80+
h) comment_marker='//' ;;
81+
in) comment_marker='##' ;;
82+
java) comment_marker='//' ;;
83+
js) comment_marker='//' ;;
84+
json) continue ;; # JSON doesn't support line comments
85+
jsx) comment_marker='//' ;;
86+
kts) comment_marker='//' ;;
87+
md) continue ;; # Text files don't need license headers
88+
mobileconfig) continue ;; # Doesn't support comments
89+
modulemap) continue ;; # Configuration file doesn't need a license header
90+
plist) continue ;; # Plists don't support line comments
91+
proto) comment_marker='//' ;;
92+
ps1) comment_marker='##' ;;
93+
py) comment_marker='##'; header_prefix=$'#!/usr/bin/env python3\n' ;;
94+
rb) comment_marker='##'; header_prefix=$'#!/usr/bin/env ruby\n' ;;
95+
sh) comment_marker='##'; header_prefix=$'#!/bin/bash\n' ;;
7696
swift-format) continue ;; # .swift-format is JSON and doesn't support comments
77-
ts) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
78-
tsx) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
97+
swift) comment_marker='//' ;;
98+
ts) comment_marker='//' ;;
99+
tsx) comment_marker='//' ;;
100+
txt) continue ;; # Text files don't need license headers
101+
yml) continue ;; # YAML Configuration files don't need license headers
102+
yaml) continue ;; # YAML Configuration files don't need license headers
79103
*)
80104
error "Unsupported file extension ${file_extension} for file (exclude or update this script): ${file_path}"
81105
paths_with_missing_license+=("${file_path} ")
106+
continue
82107
;;
83108
esac
84-
expected_file_header_linecount=$(wc -l <<<"${expected_file_header}")
109+
expected_file_header=$(echo "${header_prefix}${expected_file_header_template}" | sed -e "s|@@|$comment_marker|g")
110+
expected_file_header_linecount=$(echo "${expected_file_header}" | wc -l)
85111

86112
file_header=$(head -n "${expected_file_header_linecount}" "${file_path}")
87113
normalized_file_header=$(
88114
echo "${file_header}" \
89-
| sed -e 's/20[12][0123456789]-20[12][0123456789]/YEARS/' -e 's/20[12][0123456789]/YEARS/' \
115+
| sed -E -e 's/20[12][0123456789] ?- ?20[12][0123456789]/YEARS/' -e 's/20[12][0123456789]/YEARS/' \
90116
)
91117

92118
if ! diff -u \

.github/workflows/scripts/check-unacceptable-language.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ test -n "${UNACCEPTABLE_WORD_LIST:-}" || fatal "UNACCEPTABLE_WORD_LIST unset"
2121

2222
unacceptable_language_lines=
2323
if [[ -f .unacceptablelanguageignore ]]; then
24-
log "Found for unacceptable file..."
24+
log "Found unacceptable language ignore file..."
2525
log "Checking for unacceptable language..."
26-
unacceptable_language_lines=$(tr '\n' '\0' < .unacceptablelanguageignore | xargs -0 -I% printf '":(exclude)%" '| xargs git grep -i -I -w -H -n --column -E "${UNACCEPTABLE_WORD_LIST// /|}" | grep -v "ignore-unacceptable-language") || true | /usr/bin/paste -s -d " " -
26+
unacceptable_language_lines=$(tr '\n' '\0' < .unacceptablelanguageignore | xargs -0 -I% printf '":(exclude)%" '| xargs git grep -i -I -w -H -n --column -E "${UNACCEPTABLE_WORD_LIST// /|}" -- ':!*.unacceptablelanguageignore' | grep -v "ignore-unacceptable-language") || true | /usr/bin/paste -s -d " " -
2727
else
2828
log "Checking for unacceptable language..."
2929
unacceptable_language_lines=$(git grep -i -I -w -H -n --column -E "${UNACCEPTABLE_WORD_LIST// /|}" | grep -v "ignore-unacceptable-language") || true | /usr/bin/paste -s -d " " -
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
$VSB='https://download.visualstudio.microsoft.com/download/pr/5536698c-711c-4834-876f-2817d31a2ef2/c792bdb0fd46155de19955269cac85d52c4c63c23db2cf43d96b9390146f9390/vs_BuildTools.exe'
13+
$VSB_SHA256='C792BDB0FD46155DE19955269CAC85D52C4C63C23DB2CF43D96B9390146F9390'
14+
Set-Variable ErrorActionPreference Stop
15+
Set-Variable ProgressPreference SilentlyContinue
16+
Write-Host -NoNewLine ('Downloading {0} ... ' -f ${VSB})
17+
Invoke-WebRequest -Uri $VSB -OutFile $env:TEMP\vs_buildtools.exe
18+
Write-Host 'SUCCESS'
19+
Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f $VSB_SHA256)
20+
$Hash = Get-FileHash $env:TEMP\vs_buildtools.exe -Algorithm sha256
21+
if ($Hash.Hash -eq $VSB_SHA256) {
22+
Write-Host 'SUCCESS'
23+
} else {
24+
Write-Host ('FAILED ({0})' -f $Hash.Hash)
25+
exit 1
26+
}
27+
Write-Host -NoNewLine 'Installing Visual Studio Build Tools ... '
28+
$Process =
29+
Start-Process $env:TEMP\vs_buildtools.exe -Wait -PassThru -NoNewWindow -ArgumentList @(
30+
'--quiet',
31+
'--wait',
32+
'--norestart',
33+
'--nocache',
34+
'--add', 'Microsoft.VisualStudio.Component.Windows11SDK.22000',
35+
'--add', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
36+
)
37+
if ($Process.ExitCode -eq 0 -or $Process.ExitCode -eq 3010) {
38+
Write-Host 'SUCCESS'
39+
} else {
40+
Write-Host ('FAILED ({0})' -f $Process.ExitCode)
41+
exit 1
42+
}
43+
Remove-Item -Force $env:TEMP\vs_buildtools.exe
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
. $PSScriptRoot\install-swift.ps1
13+
14+
$SWIFT='https://download.swift.org/swift-5.10.1-release/windows10/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-windows10.exe'
15+
$SWIFT_SHA256='3027762138ACFA1BBE3050FF6613BBE754332E84C9EFA5C23984646009297286'
16+
17+
Install-Swift -Url $SWIFT -Sha256 $SWIFT_SHA256
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
. $PSScriptRoot\install-swift.ps1
13+
14+
$SWIFT='https://download.swift.org/swift-5.9.2-release/windows10/swift-5.9.2-RELEASE/swift-5.9.2-RELEASE-windows10.exe'
15+
$SWIFT_SHA256='D78A717551C78E824C9B74B0CFB1AD86060FC286EA071FDDB26DF18F56DC7212'
16+
17+
Install-Swift -Url $SWIFT -Sha256 $SWIFT_SHA256
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
. $PSScriptRoot\install-swift.ps1
13+
14+
$SWIFT='https://download.swift.org/swift-6.0.3-release/windows10/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-windows10.exe'
15+
$SWIFT_SHA256='AB205D83A38047882DB80E6A88C7D33B651F3BAC96D4515D7CBA5335F37999D3'
16+
17+
Install-Swift -Url $SWIFT -Sha256 $SWIFT_SHA256

0 commit comments

Comments
 (0)