-
Notifications
You must be signed in to change notification settings - Fork 233
153 lines (146 loc) · 6.79 KB
/
publish_release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Publish Release
on:
workflow_dispatch:
inputs:
prerelease:
type: boolean
description: "Prerelease"
# Whether to create a prerelease or proper release
default: true
required: true
swift_format_version:
type: string
default: 601.0.0
description: "swift-format version"
# The version of swift-format to tag. If this is a prerelease, `-prerelease-<date>` is added to this version.
required: true
swift_syntax_tag:
type: string
default: 601.0.0
description: "swift-syntax version"
# The swift-syntax version to depend on. If this is a prerelease, the latest swift-syntax prerelease tag for this version is used.
required: true
jobs:
check_triggering_actor:
name: Check user is allowed to create release
# Only a single user should be allowed to create releases to avoid two people triggering the creation of a release
# at the same time. If the release manager changes between users, update this condition.
runs-on: ubuntu-latest
steps:
- run: |
if [[ "${{ github.triggering_actor }}" != "ahoppen" ]]; then
echo "${{ github.triggering_actor }} is not allowed to create a release"
exit 1
fi
create_release_commits:
name: Create release commits
runs-on: ubuntu-latest
outputs:
swift_format_version: ${{ steps.swift_format_version.outputs.swift_format_version }}
release_commit_patch: ${{ steps.create_release_commits.outputs.release_commit_patch }}
steps:
- name: Determine swift-syntax tag to depend on
id: swift_syntax_tag
shell: bash
run: |
if [[ "${{ github.event.inputs.prerelease }}" == "false" ]]; then
SWIFT_SYNTAX_TAG="${{ github.event.inputs.swift_syntax_tag }}"
else
git clone https://github.com/swiftlang/swift-syntax.git
cd swift-syntax
SWIFT_SYNTAX_TAG="$(git tag | grep ${{ github.event.inputs.swift_syntax_tag }}-prerelease | sort -r | head -1)"
fi
echo "Using swift-syntax tag: $SWIFT_SYNTAX_TAG"
echo "swift_syntax_tag=$SWIFT_SYNTAX_TAG" >> "$GITHUB_OUTPUT"
- name: Determine swift-format prerelease version
id: swift_format_version
run: |
if [[ "${{ github.event.inputs.prerelease }}" == "false" ]]; then
SWIFT_FORMAT_VERSION="${{ github.event.inputs.swift_format_version }}"
else
SWIFT_FORMAT_VERSION="${{ github.event.inputs.swift_format_version }}-prerelease-$(date +'%Y-%m-%d')"
fi
echo "Using swift-format version: $SWIFT_FORMAT_VERSION"
echo "swift_format_version=$SWIFT_FORMAT_VERSION" >> "$GITHUB_OUTPUT"
- name: Checkout repository
uses: actions/checkout@v4
- name: Create release commits
id: create_release_commits
run: |
# Without this, we can't perform git operations in GitHub actions.
git config --global --add safe.directory "$(realpath .)"
git config --local user.name 'swift-ci'
git config --local user.email '[email protected]'
BASE_COMMIT=$(git rev-parse HEAD)
sed -E -i "s#branch: \"(main|release/[0-9]+\.[0-9]+)\"#from: \"${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}\"#" Package.swift
git add Package.swift
git commit -m "Change swift-syntax dependency to ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}"
sed -E -i "s#print\(\".*\"\)#print\(\"${{ steps.swift_format_version.outputs.swift_format_version }}\"\)#" Sources/swift-format/PrintVersion.swift
git add Sources/swift-format/PrintVersion.swift
git commit -m "Change version to ${{ steps.swift_format_version.outputs.swift_format_version }}"
{
echo 'release_commit_patch<<EOF'
git format-patch "$BASE_COMMIT"..HEAD --stdout
echo EOF
} >> "$GITHUB_OUTPUT"
test:
name: Test in ${{ matrix.release && 'Release' || 'Debug' }} configuration
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
needs: create_release_commits
strategy:
fail-fast: false
matrix:
release: [true, false]
with:
enable_windows_docker: false # Dockerless Windows is 5-10 minutes faster than Docker on Windows
linux_pre_build_command: |
git config --global --add safe.directory "$(realpath .)"
git config --local user.name 'swift-ci'
git config --local user.email '[email protected]'
git am << EOF
${{ needs.create_release_commits.outputs.release_commit_patch }}
EOF
windows_pre_build_command: |
git config --local user.name "swift-ci"
git config --local user.email "[email protected]"
echo @"
${{ needs.create_release_commits.outputs.release_commit_patch }}
"@ > $env:TEMP\patch.diff
# For some reason `git am` fails in Powershell with the following error. Executing it in cmd works...
# fatal: empty ident name (for <>) not allowed
cmd /c "type $env:TEMP\patch.diff | git am || (exit /b 1)"
# We require that releases of swift-format build without warnings
linux_build_command: swift test -Xswiftc -warnings-as-errors ${{ matrix.release && '-c release' || '' }}
windows_build_command: swift test -Xswiftc -warnings-as-errors ${{ matrix.release && '-c release' || '' }}
create_tag:
name: Create Tag
runs-on: ubuntu-latest
needs: [check_triggering_actor, test, create_release_commits]
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Apply release commits
run: |
git config --global --add safe.directory "$(realpath .)"
git config --local user.name 'swift-ci'
git config --local user.email '[email protected]'
git am << EOF
${{ needs.create_release_commits.outputs.release_commit_patch }}
EOF
- name: Tag release
run: |
git tag "${{ needs.create_release_commits.outputs.swift_format_version }}"
git push origin "${{ needs.create_release_commits.outputs.swift_format_version }}"
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: |
if [[ "${{ github.event.inputs.prerelease }}" != "true" ]]; then
# Only create a release automatically for prereleases. For real releases, release notes should be crafted by hand.
exit
fi
gh release create "${{ needs.create_release_commits.outputs.swift_format_version }}" \
--title "${{ needs.create_release_commits.outputs.swift_format_version }}" \
--prerelease