Skip to content

Commit 6e4c968

Browse files
authored
Merge pull request #891 from ahoppen/6.1/publish-release
[6.1] Fix the `Publish Release` workflow
2 parents fed90eb + 8b79703 commit 6e4c968

File tree

2 files changed

+67
-51
lines changed

2 files changed

+67
-51
lines changed

.github/workflows/create-release-commits.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/publish_release.yml

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ jobs:
3434
echo "${{ github.triggering_actor }} is not allowed to create a release"
3535
exit 1
3636
fi
37-
define_tags:
38-
name: Determine dependent swift-syntax version and prerelease date
37+
create_release_commits:
38+
name: Create release commits
3939
runs-on: ubuntu-latest
4040
outputs:
41-
swift_syntax_tag: ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}
4241
swift_format_version: ${{ steps.swift_format_version.outputs.swift_format_version }}
42+
release_commit_patch: ${{ steps.create_release_commits.outputs.release_commit_patch }}
4343
steps:
4444
- name: Determine swift-syntax tag to depend on
4545
id: swift_syntax_tag
@@ -65,37 +65,81 @@ jobs:
6565
fi
6666
echo "Using swift-format version: $SWIFT_FORMAT_VERSION"
6767
echo "swift_format_version=$SWIFT_FORMAT_VERSION" >> "$GITHUB_OUTPUT"
68-
test_debug:
69-
name: Test in Debug configuration
70-
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
71-
needs: define_tags
72-
with:
73-
pre_build_command: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
74-
# We require that releases of swift-format build without warnings
75-
build_command: swift test -Xswiftc -warnings-as-errors
76-
test_release:
77-
name: Test in Release configuration
68+
- name: Checkout repository
69+
uses: actions/checkout@v4
70+
- name: Create release commits
71+
id: create_release_commits
72+
run: |
73+
# Without this, we can't perform git operations in GitHub actions.
74+
git config --global --add safe.directory "$(realpath .)"
75+
git config --local user.name 'swift-ci'
76+
git config --local user.email '[email protected]'
77+
78+
BASE_COMMIT=$(git rev-parse HEAD)
79+
80+
sed -E -i "s#branch: \"(main|release/[0-9]+\.[0-9]+)\"#from: \"${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}\"#" Package.swift
81+
git add Package.swift
82+
git commit -m "Change swift-syntax dependency to ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}"
83+
84+
sed -E -i "s#print\(\".*\"\)#print\(\"${{ steps.swift_format_version.outputs.swift_format_version }}\"\)#" Sources/swift-format/PrintVersion.swift
85+
git add Sources/swift-format/PrintVersion.swift
86+
git commit -m "Change version to ${{ steps.swift_format_version.outputs.swift_format_version }}"
87+
88+
{
89+
echo 'release_commit_patch<<EOF'
90+
git format-patch "$BASE_COMMIT"..HEAD --stdout
91+
echo EOF
92+
} >> "$GITHUB_OUTPUT"
93+
test:
94+
name: Test in ${{ matrix.release && 'Release' || 'Debug' }} configuration
7895
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
79-
needs: define_tags
96+
needs: create_release_commits
97+
strategy:
98+
fail-fast: false
99+
matrix:
100+
release: [true, false]
80101
with:
81-
pre_build_command: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
102+
enable_windows_docker: false # Dockerless Windows is 5-10 minutes faster than Docker on Windows
103+
linux_pre_build_command: |
104+
git config --global --add safe.directory "$(realpath .)"
105+
git config --local user.name 'swift-ci'
106+
git config --local user.email '[email protected]'
107+
git am << EOF
108+
${{ needs.create_release_commits.outputs.release_commit_patch }}
109+
EOF
110+
windows_pre_build_command: |
111+
git config --local user.name "swift-ci"
112+
git config --local user.email "[email protected]"
113+
echo @"
114+
${{ needs.create_release_commits.outputs.release_commit_patch }}
115+
"@ > $env:TEMP\patch.diff
116+
# For some reason `git am` fails in Powershell with the following error. Executing it in cmd works...
117+
# fatal: empty ident name (for <>) not allowed
118+
cmd /c "type $env:TEMP\patch.diff | git am || (exit /b 1)"
82119
# We require that releases of swift-format build without warnings
83-
build_command: swift test -c release -Xswiftc -warnings-as-errors
120+
linux_build_command: swift test -Xswiftc -warnings-as-errors ${{ matrix.release && '-c release' || '' }}
121+
windows_build_command: swift test -Xswiftc -warnings-as-errors ${{ matrix.release && '-c release' || '' }}
84122
create_tag:
85123
name: Create Tag
86124
runs-on: ubuntu-latest
87-
needs: [check_triggering_actor, test_debug, test_release, define_tags]
125+
needs: [check_triggering_actor, test, create_release_commits]
88126
permissions:
89127
contents: write
90128
steps:
91129
- name: Checkout repository
92130
uses: actions/checkout@v4
93-
- name: Create release commits
94-
run: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
131+
- name: Apply release commits
132+
run: |
133+
git config --global --add safe.directory "$(realpath .)"
134+
git config --local user.name 'swift-ci'
135+
git config --local user.email '[email protected]'
136+
git am << EOF
137+
${{ needs.create_release_commits.outputs.release_commit_patch }}
138+
EOF
95139
- name: Tag release
96140
run: |
97-
git tag "${{ needs.define_tags.outputs.swift_format_version }}"
98-
git push origin "${{ needs.define_tags.outputs.swift_format_version }}"
141+
git tag "${{ needs.create_release_commits.outputs.swift_format_version }}"
142+
git push origin "${{ needs.create_release_commits.outputs.swift_format_version }}"
99143
- name: Create release
100144
env:
101145
GH_TOKEN: ${{ github.token }}
@@ -104,6 +148,6 @@ jobs:
104148
# Only create a release automatically for prereleases. For real releases, release notes should be crafted by hand.
105149
exit
106150
fi
107-
gh release create "${{ needs.define_tags.outputs.swift_format_version }}" \
108-
--title "${{ needs.define_tags.outputs.swift_format_version }}" \
151+
gh release create "${{ needs.create_release_commits.outputs.swift_format_version }}" \
152+
--title "${{ needs.create_release_commits.outputs.swift_format_version }}" \
109153
--prerelease

0 commit comments

Comments
 (0)