Pin SwiftSyntax to a tagged version (#4674)

Specifically this tag:
https://github.com/apple/swift-syntax/releases/tag/0.50800.0-SNAPSHOT-2022-12-29-a

This should make SwiftPM happier about the stability of the pinned
version.

Also switch the CI job to run on macOS to avoid adding Linux-only deps
to the `Package.resolved` file (e.g. CryptoSwift).
This commit is contained in:
JP Simard 2023-01-06 13:10:59 -05:00 committed by GitHub
parent 100b3eec2a
commit e6d4ad653c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 27 deletions

View File

@ -8,28 +8,22 @@ on:
jobs:
update_swift_syntax:
runs-on: ubuntu-latest
runs-on: macos-12
steps:
- name: Checkout source
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Update SwiftSyntax
id: update-swift-syntax
run: ./tools/update-swift-syntax.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check for changes
id: state
run: |
if ! git diff-index --quiet HEAD --; then
echo "dirty=true" >> $GITHUB_OUTPUT
fi
- name: Create PR
if: steps.state.outputs.dirty == 'true'
if: steps.update-swift-syntax.outputs.needs_update == 'true'
uses: peter-evans/create-pull-request@923ad837f191474af6b1721408744feb989a4c27
with:
title: Update SwiftSyntax
body: |
Diff: https://github.com/apple/swift-syntax/compare/${{ steps.update-swift-syntax.outputs.old_commit }}...${{ steps.update-swift-syntax.outputs.new_commit }}
Diff: https://github.com/apple/swift-syntax/compare/${{ steps.update-swift-syntax.outputs.old_tag }}...${{ steps.update-swift-syntax.outputs.new_tag }}
commit-message: Update SwiftSyntax
delete-branch: true
branch: update-swift-syntax

View File

@ -32,7 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "60e2097fa967e3bd0a2c3f08b1c672865c1f1d60"
"revision" : "edd2d0cdb988ac45e2515e0dd0624e4a6de54a94",
"version" : "0.50800.0-SNAPSHOT-2022-12-29-a"
}
},
{

View File

@ -30,7 +30,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "1.2.0")),
.package(url: "https://github.com/apple/swift-syntax.git", revision: "60e2097fa967e3bd0a2c3f08b1c672865c1f1d60"),
.package(url: "https://github.com/apple/swift-syntax.git", exact: "0.50800.0-SNAPSHOT-2022-12-29-a"),
.package(url: "https://github.com/jpsim/SourceKitten.git", .upToNextMinor(from: "0.33.1")),
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.1"),
.package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"),

View File

@ -19,10 +19,10 @@ def swiftlint_repos():
http_archive(
name = "com_github_apple_swift_syntax",
sha256 = "18f910a68c06e7a11f813b781704bff2ef6ebd676ccc7506dc479fc95811a64f", # SwiftSyntax sha256
sha256 = "2024415299a487fcb3b2d7500d2e7c149b4bc4f3b94408edd601457ee27f6b11", # SwiftSyntax sha256
build_file = "@SwiftLint//bazel:SwiftSyntax.BUILD",
strip_prefix = "swift-syntax-60e2097fa967e3bd0a2c3f08b1c672865c1f1d60",
url = "https://github.com/apple/swift-syntax/archive/60e2097fa967e3bd0a2c3f08b1c672865c1f1d60.tar.gz",
strip_prefix = "swift-syntax-0.50800.0-SNAPSHOT-2022-12-29-a",
url = "https://github.com/apple/swift-syntax/archive/refs/tags/0.50800.0-SNAPSHOT-2022-12-29-a.tar.gz",
)
http_archive(

View File

@ -2,22 +2,23 @@
set -euo pipefail
readonly old_commit="$(grep "apple/swift-syntax" Package.swift | sed -nr 's/.*revision: \"([a-f0-9]{40})\"\),$/\1/p')"
readonly old_tag="$(sed -n 's/.* exact: "\(.*\)".*/\1/p' Package.swift)"
if [ $# -eq 0 ]; then
readonly new_commit="$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.VERSION.sha" "https://api.github.com/repos/apple/swift-syntax/commits/main")"
readonly new_tag="$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" "https://api.github.com/repos/apple/swift-syntax/releases?per_page=1" | sed -n 's/.*tag_name":"\([^"]*\)".*/\1/p')"
else
readonly new_commit="$1"
readonly new_tag="$1"
fi
if [[ "$old_commit" == "$new_commit" ]]; then
echo "SwiftSyntax is already up to date"
if [[ "$old_tag" == "$new_tag" ]]; then
echo "SwiftSyntax is already up to date at $new_tag"
exit 0
fi
echo "Updating SwiftSyntax from $old_commit to $new_commit"
echo "Updating SwiftSyntax from $old_tag to $new_tag"
if [[ "${GITHUB_ACTIONS-}" == "true" ]]; then
echo "old_commit=$old_commit" >> $GITHUB_OUTPUT
echo "new_commit=$new_commit" >> $GITHUB_OUTPUT
echo "needs_update=true" >> $GITHUB_OUTPUT
echo "old_tag=$old_tag" >> $GITHUB_OUTPUT
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
fi
# $1 — string to match
@ -31,11 +32,12 @@ function replace() {
fi
}
replace "$old_commit" "$new_commit" Package.swift
replace "$old_commit" "$new_commit" Package.resolved
replace "$old_commit" "$new_commit" bazel/repos.bzl
replace "$old_tag" "$new_tag" Package.swift
swift package update
readonly url="https://github.com/apple/swift-syntax/archive/$new_commit.tar.gz"
replace "$old_tag" "$new_tag" bazel/repos.bzl
readonly url="https://github.com/apple/swift-syntax/archive/refs/tags/$new_tag.tar.gz"
output="$(mktemp -d)/download"
if ! curl -s --location --fail --output "$output" "$url"; then
echo "error: failed to download $url" >&2