Tip
This template is a starting point you can use for every Swift module. We offer:
- A Swift package, tests, and an example app
- Continuous integration with the Swift package workflows
- Automated releases with Release Please and SLSA provenance attestation
- An MIT license and a .gitignore
Run swift TEMPLATE/configure.swift to fill in the project name and the other placeholders. TEMPLATE/Recipe.md walks through the same result starting from Xcode.
What is in-scope for this template?
We the people who publish reusable Swift modules, in order to hand every module a tested package, an example app, and a release, maintain this starting point.
Swift 6 Module Template must remain broad—addressing many kinds of modules. Every module deserves a README, an example, and a clear rule on formatting, this is why we include continuous integration.
We do not specify that GitHub and GitHub Actions are the only way to host projects, others may consider our GitHub-specific notes as a starting point guide for implementing outside of GitHub.
And now below is the template, shown for a specific hypothetical project, enjoy!
White Pawn shows a white chess pawn (♙).
Note
Replace the project name, description, demonstration and badge URLs with your own. Show what your project does before asking people to read further.
White Pawn is a reusable Swift 6 module. It provides:
- A Swift Package Manager library and tests
- An example SwiftUI app in an Xcode project
- Semantic versioning, a CHANGELOG, and an MIT license
- GitHub Actions testing with the workflows published for Swift packages
- EditorConfig, a .gitignore, and enforced formatting
The example app shows a white pawn (♙).
Clone the repo and open Example/Example.xcodeproj. Run the Example scheme on a recent iPhone simulator.
Add this package with Swift Package Manager. In Xcode that is File > Add Package Dependencies...
Format the files the lint workflow checks. These commands use npx at @latest so the local write matches .github/workflows/lint.yml. A pinned package would let the local write and the CI check disagree.
npx prettier@latest --write .
npx markdownlint-cli@latest --fix "**/*.md" --ignore node_modulesAdd the package to an app and call the library. The example app in Example/ shows a white chess pawn (♙).
Note
Explain how to use your project. Or link to the canonical usage instructions.
We are people who publish reusable Swift modules. White Pawn is one module: a Swift package, tests, and an example app.
We specifically will not add a second product, a server, or a package registry release. Swift Package Manager uses the git tag.
Note
Introduce your community, explain what is in scope, and say what is out of scope.
Run the test suite with:
xcrun swift testUse fix:, feat: or BREAKING CHANGE: in your commit messages. This triggers our bot to make a release draft pull request. Merging that pull request triggers a new tag and GitHub Release.
The release workflow uses Release Please with the simple release type. .release-please-manifest.json is the last released version. Release Please writes CHANGELOG.md on the release pull request. Commit messages follow Conventional Commits 1.0.0.
Build and test builds and tests a release-mode Linux library, then attests and uploads it. The release includes that library and release.sigstore.jsonl, containing build provenance and version attestations. The published library is for Linux. Swift Package Manager uses the git tag.
Note
In your GitHub repository settings, under Actions, General, Workflow permissions, select read and write permissions and check "Allow GitHub Actions to create and approve pull requests". Under General, Releases, enable release immutability. Attestations are available for public repositories; private repositories require GitHub Enterprise Cloud.
A repository created from this template should set .release-please-manifest.json to 0.0.0. This repository's manifest is 16.5.0, the same version as tag v16.5.0. Release Please needs a SemVer version to bump.
Run these commands from a clone of the new repository. gh fills in {owner}/{repo} from that clone.
List tags:
gh api repos/{owner}/{repo}/tags --jq '.[].name'Set the starting tag on the current main commit. v0.0.0 is the version Release Please counts forward from. Use another vMAJOR.MINOR.PATCH tag when this repository should start later.
gh api --method POST repos/{owner}/{repo}/git/refs \
-f ref="refs/tags/v0.0.0" \
-f sha="$(gh api repos/{owner}/{repo}/commits/main --jq .sha)"gh release list and gh release create publish the releases this workflow creates after that tag.
Do this every quarter or so and please send a PR here if you see updates available:
- Identify external Actions in .github/workflows scripts and look for available new versions. Review and then update to the new version if it is safe. GitHub-supported Actions (i.e. under the actions/ organization) may require only cursory review.
- Review the Swift versions in .github/workflows/swiftlang-workflows.yml. The package requires the tools version in Package.swift.
- Review the RECIPE and confirm that the current latest pubished version of Xcode equals the version asserted at the top of this file. If not, redo the recipe.
Important
We use an MIT license for this template. You should carefully consider which license to apply to your own project.
If your project materially relied on external sources to make some decisions, cite them here.
- We use title case only for proper nouns, including the name of our project.
- We use an MIT license for this template. You should carefully consider which license to apply to your own project.
- Swift ignore rules are inlined from Swift.gitignore. The macOS and secret rules above them come from project-template.
- This project is built based on best practices documented in Swift 6 Module Template.
- This project is built based on best practices documented in project-template, release v1.3.0.
- Releases follow the project-template release workflow, release v1.3.0. The published file is the Linux static library from
swift build -c release. project-template publishesREADME.mdthere, and rust-template publishes its command-line binary.