Swift Dependency Updater 是一个自动更新 Swift Package Manager 项目依赖的工具。与 swift package update
不同,它还会检查是否有更新需要调整 Package.swift
文件中指定的版本。
mint install Nef10/swift-dependency-updater
git clone https://github.com/Nef10/swift-dependency-updater.git
cd swift-dependency-updater
swift run swift-dependency-updater
swift-dependency-updater [update] [<folder>] [--keep-requirements]
swift-dependency-updater list [<folder>] [--exclude-indirect] [--updates-only]
运行 swift-dependency-updater --help
可以查看完整的支持命令列表,运行 swift-dependency-updater help <subcommand>
可以查看特定命令的详细帮助。
得益于 swift-argument-parser,你可以通过 swift-dependency-updater --generate-completion-script {zsh|bash|fish}
生成自动补全脚本。你的 shell 对应的确切命令可能不同,但例如对于 zsh,如果你的 fpath 中有 ~/.zfunctions,你可以使用
swift-dependency-updater --generate-completion-script zsh > ~/.zfunctions/_swift-dependency-updater
swift-dependency-updater 可以通过运行 swift-dependency-updater github [<folder>] [--keep-requirements]
在 GitHub 上为每个过期的依赖自动创建 Pull Request。这需要将有效的 GitHub Token 放在 TOKEN
环境变量中,并且 git 在检出的文件夹中通过身份验证(意味着 git push
将成功运行)。
虽然可以在本地运行此命令,但它主要用于通过 GitHub Actions 运行。唯一的问题是,由 action 创建的 push 或 pull request 本身不会触发 action 运行,这意味着默认情况下,您的 CI 不会在由此命令创建的 PR 上运行。有一些 可用的解决方法。 我建议创建 GitHub App 以创建 tokens,因为它提供了最好的安全性。
完成此操作后,您可以使用以下 actions 文件创建 action,并将其放置在您存储库中的 .github/workflows/swift-dependency-updater.yml
下,例如
name: Swift Dependency Updater
on:
schedule:
- cron: '17 10 * * 5' # Run every Friday at 10:17 UTC
workflow_dispatch: # Allows to manually trigger the script
permissions: # The workflow does not need specific permissions as we use a different token
contents: read
jobs:
test:
name: Update Swift Dependencies
runs-on: ubuntu-latest # The action supports macOS-latest as well
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1.3.0
with:
app_id: ${{ secrets.APP_ID }} # These two secrets need to be added
private_key: ${{ secrets.APP_PRIVATE_KEY }} # to your repository settings
- name: Checkout code
uses: actions/checkout@v2
with:
path: repo
fetch-depth: 0 # Fetching the whole repo is required to check if branches already exist
token: ${{ steps.generate_token.outputs.token }} # Checkout repo pre-configured with right token
- name: Install Swift
uses: swift-actions/setup-swift@v1
- name: Checkout swift-dependency-updater
uses: actions/checkout@v2
with:
repository: Nef10/swift-dependency-updater
path: swift-dependency-updater
ref: main # specify a version tag or use main to always use the latest code
- name: Run swift-dependency-updater
run: cd swift-dependency-updater && swift run swift-dependency-updater github ../repo
env:
TOKEN: ${{ steps.generate_token.outputs.token }} # Required to open the Pull Requests
目前不支持使用 .branch(_ name:)
或 .revision(_ ref:)
指定的依赖项。
该工具的灵感来自 vintage,spm-dependencies-checker 和 swift-package-dependencies-check。