├── .github └── workflows │ ├── configs │ ├── .flake8 │ └── yamllint.yml │ ├── create_automerge_pr.yml │ ├── performance_test.yml │ ├── pull_request.yml │ ├── scripts │ ├── check-broken-symlinks.sh │ ├── check-docs.sh │ ├── check-license-header.sh │ ├── check-swift-format.sh │ ├── check-unacceptable-language.sh │ └── windows │ │ ├── install-vsb.ps1 │ │ └── swift │ │ ├── install-swift-5.10.ps1 │ │ ├── install-swift-5.9.ps1 │ │ ├── install-swift-6.0.ps1 │ │ ├── install-swift-6.1.ps1 │ │ ├── install-swift-nightly-6.1.ps1 │ │ ├── install-swift-nightly.ps1 │ │ └── install-swift.ps1 │ ├── soundness.yml │ └── swift_package_test.yml ├── .gitignore ├── .license_header_template ├── .licenseignore ├── CODEOWNERS ├── LICENSE.txt ├── README.md └── tests ├── test.ps1 └── test.py /.github/workflows/configs/.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | 3 | ignore = 4 | # These are needed to make our license headers pass the linting 5 | E265, 6 | E266, 7 | 8 | # 10% larger than the standard 80 character limit. Conforms to the black 9 | # standard and Bugbear's B950. 10 | max-line-length = 88 11 | -------------------------------------------------------------------------------- /.github/workflows/configs/yamllint.yml: -------------------------------------------------------------------------------- 1 | extends: default 2 | 3 | rules: 4 | line-length: false 5 | document-start: false 6 | truthy: 7 | check-keys: false # Otherwise we get a false positive on GitHub action's `on` key 8 | -------------------------------------------------------------------------------- /.github/workflows/create_automerge_pr.yml: -------------------------------------------------------------------------------- 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 | # ``` 13 | # name: Create PR to merge main into release branch 14 | # 15 | # # 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. 16 | # # 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 17 | # 18 | # on: 19 | # schedule: 20 | # - cron: '0 9 * * MON' 21 | # workflow_dispatch: 22 | # 23 | # jobs: 24 | # create_merge_pr: 25 | # name: Create PR to merge main into release branch 26 | # uses: swiftlang/github-workflows/.github/workflows/create_automerge_pr.yml@main 27 | # 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 28 | # permissions: 29 | # contents: write 30 | # pull-requests: write 31 | # with: 32 | # base_branch: release/6.2 33 | # ``` 34 | # 35 | # PRs created by GitHub Actions don't kick off further actions (https://github.com/peter-evans/create-pull-request/blob/d57e551ebc1a16dee0b8c9ea6d24dba7627a6e35/docs/concepts-guidelines.md#triggering-further-workflow-runs). 36 | # As a workaround, we mark automerge PRs that are created by GitHub actions as draft and trigger the GitHub actions by marking the PR as ready for review. `ready_for_review` must be added to the PR types for this purpose, eg. 37 | # ``` 38 | # on: 39 | # pull_request: 40 | # types: [..., ready_for_review] 41 | # ``` 42 | # Unfortunately this will also re-trigger testing evenon a normal user's PR (which may have already been tested), but skipping them causes the checks to reset so this is the best we can do for now. 43 | on: 44 | workflow_call: 45 | inputs: 46 | base_branch: 47 | type: string 48 | description: The branch into which head_branch should be merged 49 | required: true 50 | head_branch: 51 | type: string 52 | description: The branch that should be merged into base_branch 53 | default: main 54 | pr_message: 55 | type: string 56 | description: The message that should be included in the PR created by this job 57 | 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. 58 | 59 | jobs: 60 | create_merge_pr: 61 | name: Create PR to merge ${{ inputs.head_branch }} into ${{ inputs.base_branch }} branch 62 | runs-on: ubuntu-latest 63 | permissions: 64 | contents: write 65 | pull-requests: write 66 | steps: 67 | - name: Checkout repository 68 | uses: actions/checkout@v4 69 | with: 70 | fetch-depth: 0 71 | - name: Check if there are commits to merge 72 | id: create_merge_commit 73 | run: | 74 | # Without this, we can't perform git operations in GitHub actions. 75 | git config --global --add safe.directory "$(realpath .)" 76 | git config --local user.name 'swift-ci' 77 | git config --local user.email 'swift-ci@users.noreply.github.com' 78 | 79 | if [[ "$(git rev-list --left-only --count origin/${{ inputs.head_branch }}...origin/${{ inputs.base_branch }})" == 0 ]]; then 80 | echo "Nothing to merge" 81 | echo "has_commits_to_merge=false" >> "$GITHUB_OUTPUT" 82 | exit 83 | fi 84 | 85 | echo "has_commits_to_merge=true" >> "$GITHUB_OUTPUT" 86 | - name: Push branch and create PR 87 | id: push_branch 88 | if: ${{ steps.create_merge_commit.outputs.has_commits_to_merge == 'true' }} 89 | env: 90 | GH_TOKEN: ${{ github.token }} 91 | run: | 92 | # Create a branch for the PR instead of opening a PR that merges head_branch directly so that we have a fixed 93 | # target in the PR and don't modify the PR as new commits are put on the head branch. 94 | PR_BRANCH="automerge/merge-main-$(date +%Y-%m-%d_%H-%M)" 95 | git checkout ${{ inputs.head_branch }} 96 | git checkout -b "$PR_BRANCH" 97 | git push --set-upstream origin "$PR_BRANCH" 98 | 99 | gh pr create \ 100 | --base "${{ inputs.base_branch }}" \ 101 | --head "$PR_BRANCH" \ 102 | --title 'Merge `${{ inputs.head_branch }}` into `${{ inputs.base_branch }}`' \ 103 | --body '${{ inputs.pr_message }}' \ 104 | --draft 105 | -------------------------------------------------------------------------------- /.github/workflows/performance_test.yml: -------------------------------------------------------------------------------- 1 | name: Performance test 2 | 3 | on: 4 | workflow_call: 5 | inputs: 6 | container: 7 | type: string 8 | description: "The container that the performance tests should run in" 9 | default: "swift:latest" 10 | package_path: 11 | type: string 12 | description: The directory in the repository that contains a package, which depends on ordo-one/package-benchmark and can run performance measurements. 13 | default: Benchmarks 14 | comment_header: 15 | type: string 16 | description: | 17 | If the performance has changed, this text will be prepended to the comment that contains the performance measurements. 18 | This can be either for performance improvements or regressions. 19 | default: | 20 | This PR has changed performance characteristics. Please review that the measurements reported below are expected. If these are improvements, thanks for improving the performance. 21 | 22 | jobs: 23 | measure_performance: 24 | name: Measure performance 25 | runs-on: ubuntu-latest 26 | container: 27 | image: ${{ inputs.container }} 28 | timeout-minutes: 60 29 | permissions: 30 | pull-requests: write 31 | steps: 32 | - name: Install libjemalloc-dev 33 | run: apt-get update && apt-get install -y libjemalloc-dev 34 | - name: Checkout repository 35 | uses: actions/checkout@v4 36 | with: 37 | fetch-depth: 0 38 | - name: Mark the workspace as safe 39 | # https://github.com/actions/checkout/issues/766 40 | run: git config --global --add safe.directory ${GITHUB_WORKSPACE} 41 | - name: Measure PR performance 42 | run: | 43 | swift package --package-path ${{ inputs.package_path }} --allow-writing-to-directory ${{ inputs.package_path }}/.benchmarkBaselines/ benchmark baseline update "${{ github.head_ref }}" 44 | - name: Measure base branch performance 45 | run: | 46 | git checkout ${{ github.base_ref }} 47 | swift package --package-path ${{ inputs.package_path }} --allow-writing-to-directory ${{ inputs.package_path }}/.benchmarkBaselines/ benchmark baseline update "${{ github.base_ref }}" 48 | - name: Compare performance measurements 49 | id: compare_performance 50 | run: | 51 | if ! swift package --package-path ${{ inputs.package_path }} benchmark baseline check "${{ github.base_ref }}" "${{ github.head_ref }}" --format markdown > /tmp/comparison.md 2>/tmp/comparison-stderr.txt; then 52 | echo "has_significant_changes=true" >> "$GITHUB_OUTPUT" 53 | else 54 | echo "has_significant_changes=false" >> "$GITHUB_OUTPUT" 55 | fi 56 | - name: Install gh 57 | if: ${{ steps.compare_performance.outputs.has_significant_changes == 'true' }} 58 | # Installation instructions from https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt 59 | run: | 60 | (type -p wget >/dev/null || (apt update && apt-get install wget -y)) 61 | mkdir -p -m 755 /etc/apt/keyrings 62 | out=$(mktemp) 63 | wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg 64 | cat $out | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null 65 | chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg 66 | echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null 67 | apt update 68 | apt install gh -y 69 | - name: Post comment 70 | if: ${{ steps.compare_performance.outputs.has_significant_changes == 'true' }} 71 | env: 72 | GH_TOKEN: ${{ github.token }} 73 | run: | 74 | if grep benchmarkThresholdRegression /tmp/comparison-stderr.txt > /dev/null; then 75 | PERFORMANCE_CHANGE_MESSAGE="This PR has regressed performance characteristics. Please review whether the changes reported below are expected or if you can do something to improve them." 76 | elif grep benchmarkThresholdImprovement /tmp/comparison-stderr.txt > /dev/null; then 77 | PERFORMANCE_CHANGE_MESSAGE="This PR has improved performance characteristics. Thank you 🚀" 78 | else 79 | PERFORMANCE_CHANGE_MESSAGE="This PR has changed performance characteristics. Please review that the measurements reported below are expected or if you can do something to improve them." 80 | fi 81 | 82 | cat > /tmp/performance_change_header.md <Performance report 86 | 87 | EOF 88 | 89 | echo "" > /tmp/performance_change_footer.md 90 | 91 | COMMENT="$(cat /tmp/performance_change_header.md /tmp/comparison.md /tmp/performance_change_footer.md)" 92 | gh pr comment ${{ github.event.number }} --body "$COMMENT" 93 | -------------------------------------------------------------------------------- /.github/workflows/pull_request.yml: -------------------------------------------------------------------------------- 1 | name: Pull request 2 | 3 | on: 4 | pull_request: 5 | types: [opened, reopened, synchronize] 6 | 7 | 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 | 40 | tests_macos: 41 | name: Test 42 | uses: ./.github/workflows/swift_package_test.yml 43 | with: 44 | enable_linux_checks: false 45 | enable_windows_checks: false 46 | # macOS 47 | enable_macos_checks: true 48 | macos_build_command: | 49 | mkdir MyPackage 50 | cd MyPackage 51 | xcrun swift package init --type library 52 | xcrun swift build 53 | 54 | soundness: 55 | name: Soundness 56 | uses: ./.github/workflows/soundness.yml 57 | with: 58 | api_breakage_check_enabled: false 59 | license_header_check_project_name: "Swift.org" 60 | format_check_enabled: false 61 | -------------------------------------------------------------------------------- /.github/workflows/scripts/check-broken-symlinks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##===----------------------------------------------------------------------===## 3 | ## 4 | ## This source file is part of the Swift.org open source project 5 | ## 6 | ## Copyright (c) 2024 Apple Inc. and the Swift project authors 7 | ## Licensed under Apache License v2.0 with Runtime Library Exception 8 | ## 9 | ## See https://swift.org/LICENSE.txt for license information 10 | ## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 11 | ## 12 | ##===----------------------------------------------------------------------===## 13 | 14 | set -euo pipefail 15 | 16 | log() { printf -- "** %s\n" "$*" >&2; } 17 | error() { printf -- "** ERROR: %s\n" "$*" >&2; } 18 | fatal() { error "$@"; exit 1; } 19 | 20 | log "Checking for broken symlinks..." 21 | num_broken_symlinks=0 22 | while read -r -d '' file; do 23 | if ! test -e "./${file}"; then 24 | error "Broken symlink: ${file}" 25 | ((num_broken_symlinks++)) 26 | fi 27 | done < <(git ls-files -z) 28 | 29 | if [ "${num_broken_symlinks}" -gt 0 ]; then 30 | fatal "❌ Found ${num_broken_symlinks} symlinks." 31 | fi 32 | 33 | log "✅ Found 0 symlinks." 34 | -------------------------------------------------------------------------------- /.github/workflows/scripts/check-docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##===----------------------------------------------------------------------===## 3 | ## 4 | ## This source file is part of the Swift.org open source project 5 | ## 6 | ## Copyright (c) 2024 Apple Inc. and the Swift project authors 7 | ## Licensed under Apache License v2.0 with Runtime Library Exception 8 | ## 9 | ## See https://swift.org/LICENSE.txt for license information 10 | ## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 11 | ## 12 | ##===----------------------------------------------------------------------===## 13 | 14 | set -euo pipefail 15 | 16 | log() { printf -- "** %s\n" "$*" >&2; } 17 | error() { printf -- "** ERROR: %s\n" "$*" >&2; } 18 | fatal() { error "$@"; exit 1; } 19 | 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 <> "$package_file" 44 | 45 | package.dependencies.append( 46 | .package(url: "https://github.com/swiftlang/swift-docc-plugin", "1.0.0"..<"1.4.0") 47 | ) 48 | EOF 49 | done 50 | fi 51 | 52 | log "Checking documentation targets..." 53 | for target in $(yq -r '.builder.configs[].documentation_targets[]' .spi.yml); do 54 | log "Checking target $target..." 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 $ADDITIONAL_DOCC_ARGUMENTS 57 | done 58 | 59 | log "✅ Found no documentation issues." 60 | -------------------------------------------------------------------------------- /.github/workflows/scripts/check-license-header.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##===----------------------------------------------------------------------===## 3 | ## 4 | ## This source file is part of the Swift.org open source project 5 | ## 6 | ## Copyright (c) 2024 Apple Inc. and the Swift project authors 7 | ## Licensed under Apache License v2.0 with Runtime Library Exception 8 | ## 9 | ## See https://swift.org/LICENSE.txt for license information 10 | ## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 11 | ## 12 | ##===----------------------------------------------------------------------===## 13 | 14 | set -euo pipefail 15 | 16 | log() { printf -- "** %s\n" "$*" >&2; } 17 | error() { printf -- "** ERROR: %s\n" "$*" >&2; } 18 | fatal() { error "$@"; exit 1; } 19 | 20 | if [ -f .license_header_template ]; then 21 | # allow projects to override the license header template 22 | expected_file_header_template=$(cat .license_header_template) 23 | else 24 | test -n "${PROJECT_NAME:-}" || fatal "PROJECT_NAME unset" 25 | expected_file_header_template="@@===----------------------------------------------------------------------===@@ 26 | @@ 27 | @@ This source file is part of the ${PROJECT_NAME} open source project 28 | @@ 29 | @@ Copyright (c) YEARS Apple Inc. and the ${PROJECT_NAME} project authors 30 | @@ Licensed under Apache License v2.0 31 | @@ 32 | @@ See LICENSE.txt for license information 33 | @@ See CONTRIBUTORS.txt for the list of ${PROJECT_NAME} project authors 34 | @@ 35 | @@ SPDX-License-Identifier: Apache-2.0 36 | @@ 37 | @@===----------------------------------------------------------------------===@@" 38 | fi 39 | 40 | paths_with_missing_license=( ) 41 | 42 | if [[ -f .licenseignore ]]; then 43 | static_exclude_list='":(exclude).licenseignore" ":(exclude).license_header_template" ' 44 | dynamic_exclude_list=$(tr '\n' '\0' < .licenseignore | xargs -0 -I% printf '":(exclude)%" ') 45 | exclude_list=$static_exclude_list$dynamic_exclude_list 46 | else 47 | exclude_list=":(exclude).license_header_template" 48 | fi 49 | 50 | file_paths=$(echo "$exclude_list" | xargs git ls-files) 51 | 52 | while IFS= read -r file_path; do 53 | file_basename=$(basename -- "${file_path}") 54 | file_extension="${file_basename##*.}" 55 | if [[ -L "${file_path}" ]]; then 56 | continue # Ignore symbolic links 57 | fi 58 | 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='' 63 | # shellcheck disable=SC2001 # We prefer to use sed here instead of bash search/replace 64 | case "${file_extension}" in 65 | bazel) comment_marker='##' ;; 66 | bazelrc) comment_marker='##' ;; 67 | bzl) comment_marker='##' ;; 68 | c) comment_marker='//' ;; 69 | cpp) comment_marker='//' ;; 70 | cmake) comment_marker='##' ;; 71 | code-workspace) continue ;; # VS Code workspaces are JSON and shouldn't contain comments 72 | CODEOWNERS) continue ;; # Doesn't need a license header 73 | Dockerfile) comment_marker='##' ;; 74 | editorconfig) comment_marker='##' ;; 75 | flake8) continue ;; # Configuration file doesn't need a license header 76 | gitattributes) continue ;; # Configuration files don't need license headers 77 | gitignore) continue ;; # Configuration files don't need license headers 78 | gradle) comment_marker='//' ;; 79 | groovy) comment_marker='//' ;; 80 | gyb) comment_marker='//' ;; 81 | h) comment_marker='//' ;; 82 | in) comment_marker='##' ;; 83 | java) comment_marker='//' ;; 84 | js) comment_marker='//' ;; 85 | json) continue ;; # JSON doesn't support line comments 86 | jsx) comment_marker='//' ;; 87 | kts) comment_marker='//' ;; 88 | md) continue ;; # Text files don't need license headers 89 | mobileconfig) continue ;; # Doesn't support comments 90 | modulemap) continue ;; # Configuration file doesn't need a license header 91 | plist) continue ;; # Plists don't support line comments 92 | proto) comment_marker='//' ;; 93 | ps1) comment_marker='##' ;; 94 | py) comment_marker='##'; header_prefix=$'#!/usr/bin/env python3\n' ;; 95 | rb) comment_marker='##'; header_prefix=$'#!/usr/bin/env ruby\n' ;; 96 | sh) comment_marker='##'; header_prefix=$'#!/bin/bash\n' ;; 97 | strings) comment_marker='//' ;; 98 | swift-format) continue ;; # .swift-format is JSON and doesn't support comments 99 | swift) comment_marker='//' ;; 100 | ts) comment_marker='//' ;; 101 | tsx) comment_marker='//' ;; 102 | txt) continue ;; # Text files don't need license headers 103 | yml) continue ;; # YAML Configuration files don't need license headers 104 | yaml) continue ;; # YAML Configuration files don't need license headers 105 | xcbuildrules) comment_marker='//' ;; 106 | xcspec) comment_marker='//' ;; 107 | *) 108 | error "Unsupported file extension ${file_extension} for file (exclude or update this script): ${file_path}" 109 | paths_with_missing_license+=("${file_path} ") 110 | continue 111 | ;; 112 | esac 113 | expected_file_header=$(echo "${header_prefix}${expected_file_header_template}" | sed -e "s|@@|$comment_marker|g") 114 | expected_file_header_linecount=$(echo "${expected_file_header}" | wc -l) 115 | 116 | file_header=$(head -n "${expected_file_header_linecount}" "${file_path}") 117 | normalized_file_header=$( 118 | echo "${file_header}" \ 119 | | sed -E -e 's/20[12][0123456789] ?- ?20[12][0123456789]/YEARS/' -e 's/20[12][0123456789]/YEARS/' \ 120 | ) 121 | 122 | if ! diff -u \ 123 | --label "Expected header" <(echo "${expected_file_header}") \ 124 | --label "${file_path}" <(echo "${normalized_file_header}") 125 | then 126 | paths_with_missing_license+=("${file_path} ") 127 | fi 128 | done <<< "$file_paths" 129 | 130 | if [ "${#paths_with_missing_license[@]}" -gt 0 ]; then 131 | fatal "❌ Found missing license header in files: ${paths_with_missing_license[*]}." 132 | fi 133 | 134 | log "✅ Found no files with missing license header." 135 | -------------------------------------------------------------------------------- /.github/workflows/scripts/check-swift-format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##===----------------------------------------------------------------------===## 3 | ## 4 | ## This source file is part of the Swift.org open source project 5 | ## 6 | ## Copyright (c) 2024 Apple Inc. and the Swift project authors 7 | ## Licensed under Apache License v2.0 with Runtime Library Exception 8 | ## 9 | ## See https://swift.org/LICENSE.txt for license information 10 | ## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 11 | ## 12 | ##===----------------------------------------------------------------------===## 13 | 14 | set -euo pipefail 15 | 16 | log() { printf -- "** %s\n" "$*" >&2; } 17 | error() { printf -- "** ERROR: %s\n" "$*" >&2; } 18 | fatal() { error "$@"; exit 1; } 19 | 20 | 21 | if [[ -f .swiftformatignore ]]; then 22 | log "Found swiftformatignore file..." 23 | 24 | log "Running swift format format..." 25 | tr '\n' '\0' < .swiftformatignore| xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place 26 | 27 | log "Running swift format lint..." 28 | 29 | tr '\n' '\0' < .swiftformatignore | xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel 30 | else 31 | log "Running swift format format..." 32 | git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place 33 | 34 | log "Running swift format lint..." 35 | 36 | git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel 37 | fi 38 | 39 | 40 | 41 | log "Checking for modified files..." 42 | 43 | GIT_PAGER='' git diff --exit-code '*.swift' 44 | 45 | log "✅ Found no formatting issues." 46 | -------------------------------------------------------------------------------- /.github/workflows/scripts/check-unacceptable-language.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##===----------------------------------------------------------------------===## 3 | ## 4 | ## This source file is part of the Swift.org open source project 5 | ## 6 | ## Copyright (c) 2024 Apple Inc. and the Swift project authors 7 | ## Licensed under Apache License v2.0 with Runtime Library Exception 8 | ## 9 | ## See https://swift.org/LICENSE.txt for license information 10 | ## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 11 | ## 12 | ##===----------------------------------------------------------------------===## 13 | 14 | set -euo pipefail 15 | 16 | log() { printf -- "** %s\n" "$*" >&2; } 17 | error() { printf -- "** ERROR: %s\n" "$*" >&2; } 18 | fatal() { error "$@"; exit 1; } 19 | 20 | test -n "${UNACCEPTABLE_WORD_LIST:-}" || fatal "UNACCEPTABLE_WORD_LIST unset" 21 | 22 | unacceptable_language_lines= 23 | if [[ -f .unacceptablelanguageignore ]]; then 24 | log "Found unacceptable language ignore file..." 25 | 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// /|}" -- ':!*.unacceptablelanguageignore' | grep -v "ignore-unacceptable-language") || true | /usr/bin/paste -s -d " " - 27 | else 28 | log "Checking for unacceptable language..." 29 | 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 " " - 30 | fi 31 | 32 | if [ -n "${unacceptable_language_lines}" ]; then 33 | fatal " ❌ Found unacceptable language: 34 | ${unacceptable_language_lines} 35 | " 36 | fi 37 | 38 | 39 | log "✅ Found no unacceptable language." 40 | -------------------------------------------------------------------------------- /.github/workflows/scripts/windows/install-vsb.ps1: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /.github/workflows/scripts/windows/swift/install-swift-5.10.ps1: -------------------------------------------------------------------------------- 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 18 | -------------------------------------------------------------------------------- /.github/workflows/scripts/windows/swift/install-swift-5.9.ps1: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /.github/workflows/scripts/windows/swift/install-swift-6.0.ps1: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /.github/workflows/scripts/windows/swift/install-swift-6.1.ps1: -------------------------------------------------------------------------------- 1 | ##===----------------------------------------------------------------------===## 2 | ## 3 | ## This source file is part of the Swift.org open source project 4 | ## 5 | ## Copyright (c) 2025 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.1-release/windows10/swift-6.1-RELEASE/swift-6.1-RELEASE-windows10.exe' 15 | $SWIFT_SHA256='8C8AEF8B4A449EBEEFD74482AC767E269F8CBE7E520871C1D103C7079C5F4C6A' 16 | 17 | Install-Swift -Url $SWIFT -Sha256 $SWIFT_SHA256 18 | -------------------------------------------------------------------------------- /.github/workflows/scripts/windows/swift/install-swift-nightly-6.1.ps1: -------------------------------------------------------------------------------- 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_RELEASE_METADATA='http://download.swift.org/swift-6.1-branch/windows10/latest-build.json' 15 | $Release = curl.exe -sL ${SWIFT_RELEASE_METADATA} 16 | $SWIFT_URL = "https://download.swift.org/swift-6.1-branch/windows10/$($($Release | ConvertFrom-JSON).dir)/$($($Release | ConvertFrom-JSON).download)" 17 | 18 | Install-Swift -Url $SWIFT_URL -Sha256 "" -------------------------------------------------------------------------------- /.github/workflows/scripts/windows/swift/install-swift-nightly.ps1: -------------------------------------------------------------------------------- 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_RELEASE_METADATA='http://download.swift.org/development/windows10/latest-build.json' 15 | $Release = curl.exe -sL ${SWIFT_RELEASE_METADATA} 16 | $SWIFT_URL = "https://download.swift.org/development/windows10/$($($Release | ConvertFrom-JSON).dir)/$($($Release | ConvertFrom-JSON).download)" 17 | 18 | Install-Swift -Url $SWIFT_URL -Sha256 "" -------------------------------------------------------------------------------- /.github/workflows/scripts/windows/swift/install-swift.ps1: -------------------------------------------------------------------------------- 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 | function Install-Swift { 13 | param ( 14 | [string]$Url, 15 | [string]$Sha256 16 | ) 17 | Set-Variable ErrorActionPreference Stop 18 | Set-Variable ProgressPreference SilentlyContinue 19 | Write-Host -NoNewLine ('Downloading {0} ... ' -f $url) 20 | Invoke-WebRequest -Uri $url -OutFile installer.exe 21 | Write-Host 'SUCCESS' 22 | Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f $Sha256) 23 | $Hash = Get-FileHash installer.exe -Algorithm sha256 24 | if ($Hash.Hash -eq $Sha256 -or $Sha256 -eq "") { 25 | Write-Host 'SUCCESS' 26 | } else { 27 | Write-Host ('FAILED ({0})' -f $Hash.Hash) 28 | exit 1 29 | } 30 | Write-Host -NoNewLine 'Installing Swift ... ' 31 | $Process = Start-Process installer.exe -Wait -PassThru -NoNewWindow -ArgumentList @( 32 | '/quiet', 33 | '/norestart' 34 | ) 35 | if ($Process.ExitCode -eq 0) { 36 | Write-Host 'SUCCESS' 37 | } else { 38 | Write-Host ('FAILED ({0})' -f $Process.ExitCode) 39 | exit 1 40 | } 41 | Remove-Item -Force installer.exe 42 | } -------------------------------------------------------------------------------- /.github/workflows/soundness.yml: -------------------------------------------------------------------------------- 1 | name: Soundness 2 | 3 | on: 4 | workflow_call: 5 | inputs: 6 | api_breakage_check_enabled: 7 | type: boolean 8 | description: "Boolean to enable the API breakage check job. Defaults to true." 9 | default: true 10 | api_breakage_check_allowlist_path: 11 | type: string 12 | description: "Path to a file that will be passed as --breakage-allowlist-path to swift package diagnose-api-breaking-changes" 13 | default: "" 14 | api_breakage_check_baseline: 15 | type: string 16 | description: "The tag against which API breakages that should be used as the baseline for the API breakage check. By default the PR base is used." 17 | default: "" 18 | api_breakage_check_container_image: 19 | type: string 20 | description: "Container image for the API breakage check job. Defaults to latest Swift Ubuntu image." 21 | default: "swift:6.0-noble" 22 | docs_check_enabled: 23 | type: boolean 24 | description: "Boolean to enable the docs check job. Defaults to true." 25 | default: true 26 | docs_check_container_image: 27 | type: string 28 | description: "Container image for the docs check job. Defaults to latest Swift Ubuntu image." 29 | default: "swift:6.0-noble" 30 | docs_check_additional_arguments: 31 | type: string 32 | description: "Additional arguments that should be passed to docc" 33 | default: "" 34 | unacceptable_language_check_enabled: 35 | type: boolean 36 | description: "Boolean to enable the acceptable language check job. Defaults to true." 37 | default: true 38 | unacceptable_language_check_word_list: 39 | type: string 40 | description: "List of unacceptable words. Defaults to a sensible list of words." 41 | default: "blacklist whitelist slave master sane sanity insane insanity kill killed killing hang hung hanged hanging" # ignore-unacceptable-language 42 | license_header_check_enabled: 43 | type: boolean 44 | description: "Boolean to enable the license header check job. Defaults to true." 45 | default: true 46 | license_header_check_project_name: 47 | type: string 48 | description: "Name of the project called out in the license header. Required unless `license_header_check_enabled` is false or a `.license_header_template` file is present." 49 | default: "" 50 | broken_symlink_check_enabled: 51 | type: boolean 52 | description: "Boolean to enable the broken symlink check job. Defaults to true." 53 | default: true 54 | format_check_enabled: 55 | type: boolean 56 | description: "Boolean to enable the format check job. Defaults to true." 57 | default: true 58 | format_check_container_image: 59 | type: string 60 | description: "Container image for the format check job. Defaults to latest Swift Ubuntu image." 61 | default: "swift:6.0-noble" 62 | shell_check_enabled: 63 | type: boolean 64 | description: "Boolean to enable the shell check job. Defaults to true." 65 | default: true 66 | shell_check_container_image: 67 | type: string 68 | description: "Container image for the shell check job. Defaults to latest Swift Ubuntu image." 69 | default: "swift:6.0-noble" 70 | yamllint_check_enabled: 71 | type: boolean 72 | description: "Boolean to enable the YAML lint check job. Defaults to true." 73 | default: true 74 | python_lint_check_enabled: 75 | type: boolean 76 | description: "Boolean to enable the Python lint check job. Defaults to true." 77 | default: true 78 | linux_pre_build_command: 79 | type: string 80 | description: "Linux command to execute before building the Swift package" 81 | default: "" 82 | 83 | ## We are cancelling previously triggered workflow runs 84 | concurrency: 85 | group: ${{ github.workflow }}-${{ github.ref }}-soundness 86 | cancel-in-progress: true 87 | 88 | jobs: 89 | api-breakage-check: 90 | name: API breakage check 91 | if: ${{ inputs.api_breakage_check_enabled }} 92 | runs-on: ubuntu-latest 93 | container: 94 | image: ${{ inputs.api_breakage_check_container_image }} 95 | timeout-minutes: 20 96 | steps: 97 | - name: Checkout repository 98 | uses: actions/checkout@v4 99 | with: 100 | persist-credentials: false 101 | submodules: true 102 | fetch-tags: true 103 | fetch-depth: 0 # Fetching tags requires fetch-depth: 0 (https://github.com/actions/checkout/issues/1471) 104 | - name: Mark the workspace as safe 105 | # https://github.com/actions/checkout/issues/766 106 | run: git config --global --add safe.directory ${GITHUB_WORKSPACE} 107 | - name: Pre-build 108 | if: ${{ inputs.linux_pre_build_command }} 109 | run: ${{ inputs.linux_pre_build_command }} 110 | - name: Run API breakage check 111 | shell: bash 112 | run: | 113 | if [[ -z '${{ inputs.api_breakage_check_baseline }}' ]]; then 114 | git fetch ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} ${GITHUB_BASE_REF}:pull-base-ref 115 | BASELINE_REF='pull-base-ref' 116 | else 117 | BASELINE_REF='${{ inputs.api_breakage_check_baseline }}' 118 | fi 119 | echo "Using baseline: $BASELINE_REF" 120 | if [[ -z '${{ inputs.api_breakage_check_allowlist_path }}' ]]; then 121 | swift package diagnose-api-breaking-changes "$BASELINE_REF" 122 | else 123 | swift package diagnose-api-breaking-changes "$BASELINE_REF" --breakage-allowlist-path '${{ inputs.api_breakage_check_allowlist_path }}' 124 | fi 125 | 126 | docs-check: 127 | name: Documentation check 128 | if: ${{ inputs.docs_check_enabled }} 129 | runs-on: ubuntu-latest 130 | container: 131 | image: ${{ inputs.docs_check_container_image }} 132 | timeout-minutes: 20 133 | steps: 134 | - name: Checkout repository 135 | uses: actions/checkout@v4 136 | with: 137 | persist-credentials: false 138 | submodules: true 139 | - name: Pre-build 140 | if: ${{ inputs.linux_pre_build_command }} 141 | run: ${{ inputs.linux_pre_build_command }} 142 | - name: Run documentation check 143 | env: 144 | ADDITIONAL_DOCC_ARGUMENTS: ${{ inputs.docs_check_additional_arguments }} 145 | run: | 146 | which curl yq || (apt -q update && apt -yq install curl yq) 147 | curl -s https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/check-docs.sh | bash 148 | 149 | unacceptable-language-check: 150 | name: Unacceptable language check 151 | if: ${{ inputs.unacceptable_language_check_enabled }} 152 | runs-on: ubuntu-latest 153 | timeout-minutes: 1 154 | steps: 155 | - name: Checkout repository 156 | uses: actions/checkout@v4 157 | with: 158 | persist-credentials: false 159 | submodules: true 160 | - name: Run unacceptable language check 161 | env: 162 | UNACCEPTABLE_WORD_LIST: ${{ inputs.unacceptable_language_check_word_list}} 163 | run: curl -s https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/check-unacceptable-language.sh | bash 164 | 165 | license-header-check: 166 | name: License headers check 167 | if: ${{ inputs.license_header_check_enabled }} 168 | runs-on: ubuntu-latest 169 | timeout-minutes: 1 170 | steps: 171 | - name: Checkout repository 172 | uses: actions/checkout@v4 173 | with: 174 | persist-credentials: false 175 | submodules: true 176 | - name: Run license header check 177 | env: 178 | PROJECT_NAME: ${{ inputs.license_header_check_project_name }} 179 | run: curl -s https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/check-license-header.sh | bash 180 | 181 | broken-symlink-check: 182 | name: Broken symlinks check 183 | if: ${{ inputs.broken_symlink_check_enabled }} 184 | runs-on: ubuntu-latest 185 | timeout-minutes: 1 186 | steps: 187 | - name: Checkout repository 188 | uses: actions/checkout@v4 189 | with: 190 | persist-credentials: false 191 | submodules: true 192 | - name: Run broken symlinks check 193 | run: curl -s https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/check-broken-symlinks.sh | bash 194 | 195 | format-check: 196 | name: Format check 197 | if: ${{ inputs.format_check_enabled }} 198 | runs-on: ubuntu-latest 199 | container: 200 | image: ${{ inputs.format_check_container_image }} 201 | timeout-minutes: 20 202 | steps: 203 | - name: Checkout repository 204 | uses: actions/checkout@v4 205 | with: 206 | persist-credentials: false 207 | submodules: true 208 | - name: Mark the workspace as safe 209 | # https://github.com/actions/checkout/issues/766 210 | run: git config --global --add safe.directory ${GITHUB_WORKSPACE} 211 | - name: Run format check 212 | run: | 213 | which curl || (apt -q update && apt -yq install curl) 214 | curl -s https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/check-swift-format.sh | bash 215 | 216 | shell-check: 217 | name: Shell check 218 | if: ${{ inputs.shell_check_enabled }} 219 | runs-on: ubuntu-latest 220 | container: 221 | image: ${{ inputs.shell_check_container_image }} 222 | timeout-minutes: 5 223 | steps: 224 | - name: Checkout repository 225 | uses: actions/checkout@v4 226 | with: 227 | persist-credentials: false 228 | submodules: true 229 | - name: Mark the workspace as safe 230 | # https://github.com/actions/checkout/issues/766 231 | run: git config --global --add safe.directory ${GITHUB_WORKSPACE} 232 | - name: Run shellcheck 233 | run: | 234 | which shellcheck || (apt -q update && apt -yq install shellcheck) 235 | git ls-files -z '*.sh' | xargs -0 --no-run-if-empty shellcheck 236 | 237 | yaml-lint-check: 238 | name: YAML lint check 239 | if: ${{ inputs.yamllint_check_enabled }} 240 | runs-on: ubuntu-latest 241 | timeout-minutes: 5 242 | steps: 243 | - name: Checkout repository 244 | uses: actions/checkout@v4 245 | with: 246 | persist-credentials: false 247 | submodules: true 248 | - name: Run yamllint 249 | run: | 250 | which yamllint || (apt -q update && apt install -yq yamllint) 251 | cd ${GITHUB_WORKSPACE} 252 | if [ ! -f ".yamllint.yml" ]; then 253 | echo "Downloading default yamllint config file" 254 | curl -s https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/configs/yamllint.yml > .yamllint.yml 255 | fi 256 | yamllint --strict --config-file .yamllint.yml . 257 | 258 | python-lint-check: 259 | name: Python lint check 260 | if: ${{ inputs.python_lint_check_enabled }} 261 | runs-on: ubuntu-latest 262 | timeout-minutes: 5 263 | steps: 264 | - name: Checkout repository 265 | uses: actions/checkout@v4 266 | with: 267 | persist-credentials: false 268 | submodules: true 269 | - name: Run flake8 270 | run: | 271 | pip3 install flake8 flake8-import-order 272 | cd ${GITHUB_WORKSPACE} 273 | if [ ! -f ".flake8" ]; then 274 | echo "Downloading default flake8 config file" 275 | curl -s https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/configs/.flake8 > .flake8 276 | fi 277 | flake8 278 | -------------------------------------------------------------------------------- /.github/workflows/swift_package_test.yml: -------------------------------------------------------------------------------- 1 | name: Swift Matrix 2 | 3 | on: 4 | workflow_call: 5 | inputs: 6 | macos_xcode_versions: 7 | type: string 8 | description: "Xcode version list (JSON)" 9 | default: "[\"16.0\", \"16.1\", \"16.2\", \"16.3\"]" 10 | macos_exclude_xcode_versions: 11 | type: string 12 | description: "Exclude Xcode version list (JSON)" 13 | default: "[{\"xcode_version\": \"\"}]" 14 | macos_versions: 15 | type: string 16 | description: "macOS version list (JSON)" 17 | default: "[\"sequoia\"]" 18 | macos_archs: 19 | type: string 20 | description: "macOS arch list (JSON)" 21 | default: "[\"ARM64\"]" 22 | linux_swift_versions: 23 | type: string 24 | description: "Include Linux Swift version list (JSON)" 25 | default: "[ \"5.9\", \"5.10\", \"6.0\", \"6.1\", \"nightly-main\", \"nightly-6.1\", \"nightly-6.2\"]" 26 | linux_exclude_swift_versions: 27 | type: string 28 | description: "Exclude Linux Swift version list (JSON)" 29 | default: "[{\"swift_version\": \"\"}]" 30 | linux_os_versions: 31 | type: string 32 | description: "Linux OS version list (JSON)" 33 | default: "[\"jammy\"]" 34 | windows_swift_versions: 35 | type: string 36 | description: "Include Windows Swift version list (JSON)" 37 | default: "[\"5.9\", \"6.0\", \"6.1\", \"nightly\", \"nightly-6.1\"]" 38 | windows_exclude_swift_versions: 39 | type: string 40 | description: "Exclude Windows Swift version list (JSON)" 41 | default: "[{\"swift_version\": \"\"}]" 42 | swift_flags: 43 | type: string 44 | description: "Swift flags for release version" 45 | default: "" 46 | swift_nightly_flags: 47 | type: string 48 | description: "Swift flags for nightly version" 49 | default: "" 50 | linux_pre_build_command: 51 | type: string 52 | description: "Linux command to execute before building the Swift package" 53 | default: "" 54 | macos_pre_build_command: 55 | type: string 56 | description: "macOS command to execute before building the Swift package" 57 | default: "" 58 | macos_build_command: 59 | type: string 60 | description: "macOS command to build and test the package" 61 | default: "xcrun swift test" 62 | linux_build_command: 63 | type: string 64 | description: "Linux command to build and test the package" 65 | default: "swift test" 66 | windows_pre_build_command: 67 | type: string 68 | description: "Windows Command Prompt command to execute before building the Swift package" 69 | default: "" 70 | windows_build_command: 71 | type: string 72 | description: | 73 | Windows Command Prompt command to build and test the package. 74 | Note that Powershell does not automatically exit if a subcommand fails. The Invoke-Program utility is available to propagate non-zero exit codes. 75 | It is strongly encouraged to run all command using `Invoke-Program` unless you want to continue on error eg. `Invoke-Program git apply patch.diff` instead of `git apply patch.diff`. 76 | default: "swift test" 77 | macos_env_vars: 78 | description: "Newline separated list of environment variables" 79 | type: string 80 | linux_env_vars: 81 | description: "Newline separated list of environment variables" 82 | type: string 83 | windows_env_vars: 84 | description: "Newline separated list of environment variables" 85 | type: string 86 | enable_linux_checks: 87 | type: boolean 88 | description: "Boolean to enable linux testing. Defaults to true" 89 | default: true 90 | enable_macos_checks: 91 | type: boolean 92 | description: "Boolean to enable macOS testing. Defaults to false" 93 | default: false 94 | enable_windows_checks: 95 | type: boolean 96 | description: "Boolean to enable windows testing. Defaults to true" 97 | default: true 98 | enable_windows_docker: 99 | type: boolean 100 | description: "Boolean to enable running build in windows docker container. Defaults to true" 101 | default: true 102 | needs_token: 103 | type: boolean 104 | description: "Boolean to enable providing the GITHUB_TOKEN to downstream job." 105 | default: false 106 | 107 | jobs: 108 | macos-build: 109 | name: macOS (Xcode ${{ matrix.xcode_version }} - ${{ matrix.os_version }} - ${{ matrix.arch }}) 110 | if: ${{ inputs.enable_macos_checks }} 111 | runs-on: [self-hosted, macos, "${{ matrix.os_version }}", "${{ matrix.arch }}"] 112 | strategy: 113 | fail-fast: false 114 | matrix: 115 | xcode_version: ${{ fromJson(inputs.macos_xcode_versions) }} 116 | os_version: ${{ fromJson(inputs.macos_versions) }} 117 | arch: ${{ fromJson(inputs.macos_archs) }} 118 | exclude: 119 | - ${{ fromJson(inputs.macos_exclude_xcode_versions) }} 120 | steps: 121 | - name: Checkout repository 122 | uses: actions/checkout@v4 123 | - name: Provide token 124 | if: ${{ inputs.needs_token }} 125 | run: | 126 | echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV 127 | - name: Set environment variables 128 | if: ${{ inputs.macos_env_vars }} 129 | run: | 130 | for i in "${{ inputs.macos_env_vars }}" 131 | do 132 | printf "%s\n" $i >> $GITHUB_ENV 133 | done 134 | - name: Select Xcode 135 | run: echo "DEVELOPER_DIR=/Applications/Xcode_${{ matrix.xcode_version }}.app" >> $GITHUB_ENV 136 | - name: Swift version 137 | run: xcrun swift --version 138 | - name: Pre-build 139 | run: ${{ inputs.macos_pre_build_command }} 140 | - name: Build / Test 141 | run: ${{ inputs.macos_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }} 142 | timeout-minutes: 60 143 | 144 | linux-build: 145 | name: Linux (${{ matrix.swift_version }} - ${{ matrix.os_version }}) 146 | if: ${{ inputs.enable_linux_checks }} 147 | runs-on: ubuntu-latest 148 | strategy: 149 | fail-fast: false 150 | matrix: 151 | swift_version: ${{ fromJson(inputs.linux_swift_versions) }} 152 | os_version: ${{ fromJson(inputs.linux_os_versions) }} 153 | exclude: 154 | - ${{ fromJson(inputs.linux_exclude_swift_versions) }} 155 | container: 156 | image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }} 157 | steps: 158 | - name: Swift version 159 | run: swift --version 160 | - name: Checkout repository 161 | uses: actions/checkout@v4 162 | - name: Provide token 163 | if: ${{ inputs.needs_token }} 164 | run: | 165 | echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV 166 | - name: Set environment variables 167 | if: ${{ inputs.linux_env_vars }} 168 | run: | 169 | for i in "${{ inputs.linux_env_vars }}" 170 | do 171 | printf "%s\n" $i >> $GITHUB_ENV 172 | done 173 | - name: Pre-build 174 | run: ${{ inputs.linux_pre_build_command }} 175 | - name: Build / Test 176 | run: ${{ inputs.linux_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }} 177 | 178 | windows-build: 179 | name: Windows (${{ matrix.swift_version }} - ${{ inputs.enable_windows_docker && contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }}) 180 | if: ${{ inputs.enable_windows_checks }} 181 | runs-on: ${{ inputs.enable_windows_docker && contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }} 182 | strategy: 183 | fail-fast: false 184 | matrix: 185 | swift_version: ${{ fromJson(inputs.windows_swift_versions) }} 186 | exclude: 187 | - ${{ fromJson(inputs.windows_exclude_swift_versions) }} 188 | steps: 189 | - name: Checkout repository 190 | uses: actions/checkout@v4 191 | - name: Provide token 192 | if: ${{ inputs.needs_token }} 193 | run: | 194 | echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append 195 | - name: Set environment variables 196 | if: ${{ inputs.windows_env_vars }} 197 | run: | 198 | $lines = "${{ inputs.windows_env_vars }}" -split "`r`n" 199 | foreach ($line in $lines) { 200 | echo $line | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append 201 | } 202 | - name: Pull Docker image 203 | id: pull_docker_image 204 | if: ${{ inputs.enable_windows_docker }} 205 | run: | 206 | if ("${{ matrix.swift_version }}".Contains("nightly")) { 207 | $Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809" 208 | } else { 209 | $Image = "swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022" 210 | } 211 | docker pull $Image 212 | echo "image=$Image" >> "$env:GITHUB_OUTPUT" 213 | - name: Install Visual Studio Build Tools 214 | if: ${{ !inputs.enable_windows_docker }} 215 | run: | 216 | Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/install-vsb.ps1 -OutFile $env:TEMP\install-vsb.ps1 217 | . $env:TEMP\install-vsb.ps1 218 | del $env:TEMP\install-vsb.ps1 219 | - name: Install Swift 220 | if: ${{ !inputs.enable_windows_docker }} 221 | run: | 222 | Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/swift/install-swift.ps1 -OutFile $env:TEMP\install-swift.ps1 223 | Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/swift/install-swift-${{ matrix.swift_version }}.ps1 -OutFile $env:TEMP\install-swift-${{ matrix.swift_version }}.ps1 224 | . $env:TEMP\install-swift-${{ matrix.swift_version }}.ps1 225 | del $env:TEMP\install-swift*.ps1 226 | - name: Create test script 227 | run: | 228 | mkdir $env:TEMP\test-script 229 | echo @' 230 | Set-PSDebug -Trace 1 231 | if ("${{ inputs.enable_windows_docker }}" -eq "true") { 232 | $Source = "C:\source" 233 | } else { 234 | $Source = $env:GITHUB_WORKSPACE 235 | } 236 | 237 | # Run the command following `Invoke-Program`. 238 | # If that command returns a non-zero exit code, return the same exit code from this script. 239 | function Invoke-Program($Executable) { 240 | & $Executable @args 241 | if ($LastExitCode -ne 0) { 242 | exit $LastExitCode 243 | } 244 | } 245 | Invoke-Program swift --version 246 | Invoke-Program swift test --version 247 | Invoke-Program cd $Source 248 | ${{ inputs.windows_pre_build_command }} 249 | Invoke-Program ${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }} 250 | '@ >> $env:TEMP\test-script\run.ps1 251 | # Docker build 252 | - name: Docker Build / Test 253 | timeout-minutes: 60 254 | if: ${{ inputs.enable_windows_docker }} 255 | run: | 256 | docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script ${{ steps.pull_docker_image.outputs.image }} powershell.exe -NoLogo -File C:\test-script\run.ps1 257 | # Docker-less build 258 | - name: Build / Test 259 | timeout-minutes: 60 260 | if: ${{ !inputs.enable_windows_docker }} 261 | run: | 262 | Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 263 | RefreshEnv 264 | powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1; exit $LastExitCode 265 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /.license_header_template: -------------------------------------------------------------------------------- 1 | @@===----------------------------------------------------------------------===@@ 2 | @@ 3 | @@ This source file is part of the Swift.org open source project 4 | @@ 5 | @@ Copyright (c) YEARS 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 | -------------------------------------------------------------------------------- /.licenseignore: -------------------------------------------------------------------------------- 1 | .github/workflows/configs/.flake8 2 | **/*.yml 3 | CODEOWNERS 4 | LICENSE.txt 5 | README.md 6 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # 2 | # This source file is part of the Swift.org open source project 3 | # 4 | # Copyright (c) 2024 Apple Inc. and the Swift project authors 5 | # Licensed under Apache License v2.0 with Runtime Library Exception 6 | # 7 | # See https://swift.org/LICENSE.txt for license information 8 | # See https://swift.org/CONTRIBUTORS.txt for Swift project authors 9 | # 10 | 11 | * @swiftlang/github-workflows-contributors 12 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | 204 | 205 | ## Runtime Library Exception to the Apache 2.0 License: ## 206 | 207 | 208 | As an exception, if you use this Software to compile your source code and 209 | portions of this Software are embedded into the binary product as a result, 210 | you may redistribute such product without providing attribution as would 211 | otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. 212 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Actions Workflows 2 | 3 | This repository will contain reusable workflows to minimize redundant workflows 4 | across the organization. This effort will also facilitate the standardization of 5 | testing processes while empowering repository code owners to customize their 6 | testing plans as needed. The repository will contain workflows to support 7 | different types of repositories, such as Swift Package and Swift Compiler. 8 | 9 | For more details on reusable workflows, please refer to the [Reusing 10 | workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows) 11 | section in the GitHub Docs. 12 | 13 | ## Reusable workflow for Swift package repositories 14 | 15 | There are different kinds of workflows that this repository offers: 16 | 17 | ### Soundness 18 | 19 | The soundness workflows provides a multitude of checks to ensure a repository is 20 | following the best practices. By default each check is enabled but can be 21 | disabled by passing the appropriate workflow input. We recommend to adopt all 22 | soundness checks and enforce them on each PR. 23 | 24 | A recommended workflow looks like this: 25 | 26 | ```yaml 27 | name: Pull request 28 | 29 | on: 30 | pull_request: 31 | types: [opened, reopened, synchronize] 32 | 33 | jobs: 34 | soundness: 35 | name: Soundness 36 | uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main 37 | with: 38 | license_header_check_project_name: "Swift.org" 39 | ``` 40 | 41 | ### Testing 42 | 43 | To enable pull request testing for all supported Swift versions (5.9, 5.10, 44 | 6.0, 6.1, nightly, and nightly-6.1) on Linux and Windows, add the following code example in 45 | `.github/workflows/pull_request.yml`: 46 | 47 | ```yaml 48 | name: pull_request 49 | 50 | on: 51 | pull_request: 52 | types: [opened, reopened, synchronize] 53 | 54 | jobs: 55 | tests: 56 | name: tests 57 | uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main 58 | ``` 59 | 60 | If your package only supports newer compiler versions, you can exclude older 61 | versions by using the `*_exclude_swift_versions` workflow input: 62 | 63 | ```yaml 64 | linux_exclude_swift_versions: "[{\"swift_version\": \"5.9\"}]" 65 | windows_exclude_swift_versions: "[{\"swift_version\": \"5.9\"}]" 66 | ``` 67 | 68 | Additionally, if your package requires additional installed packages, you can 69 | use the `pre_build_command`. For example, to install a package called 70 | `example`: 71 | 72 | ```yaml 73 | pre_build_command: "which example || (apt update -q && apt install -yq example" 74 | ``` 75 | 76 | macOS platform support will be available soon. 77 | 78 | ## Running workflows locally 79 | 80 | You can run the Github Actions workflows locally using 81 | [act](https://github.com/nektos/act). To run all the jobs that run on a pull 82 | request, use the following command: 83 | 84 | ```bash 85 | % act pull_request 86 | ``` 87 | 88 | To run just a single job, use `workflow_call -j `, and specify the inputs 89 | the job expects. For example, to run just shellcheck: 90 | 91 | ```bash 92 | % act workflow_call -j soundness --input shell_check_enabled=true 93 | ``` 94 | 95 | To bind-mount the working directory to the container, rather than a copy, use 96 | `--bind`. For example, to run just the formatting, and have the results 97 | reflected in your working directory: 98 | 99 | ```bash 100 | % act --bind workflow_call -j soundness --input format_check_enabled=true 101 | ``` 102 | 103 | If you'd like `act` to always run with certain flags, these can be be placed in 104 | an `.actrc` file either in the current working directory or your home 105 | directory, for example: 106 | 107 | ```bash 108 | --container-architecture=linux/amd64 109 | --remote-name upstream 110 | --action-offline-mode 111 | ``` 112 | -------------------------------------------------------------------------------- /tests/test.ps1: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /tests/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | ##===----------------------------------------------------------------------===## 3 | ## 4 | ## This source file is part of the Swift.org open source project 5 | ## 6 | ## Copyright (c) 2024 Apple Inc. and the Swift project authors 7 | ## Licensed under Apache License v2.0 with Runtime Library Exception 8 | ## 9 | ## See https://swift.org/LICENSE.txt for license information 10 | ## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 11 | ## 12 | ##===----------------------------------------------------------------------===## 13 | --------------------------------------------------------------------------------