-
Notifications
You must be signed in to change notification settings - Fork 91
266 lines (230 loc) · 8.84 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
name: Publish Release
on:
workflow_dispatch:
inputs:
environment:
type: environment
required: true
description: Environment to publish packages to
jobs:
prepare-packages:
runs-on: ubuntu-latest
environment:
name: Staging
url: ${{ steps.upload-to-s3.outputs.url }}
name: Prepare packages
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
with:
submodules: false
- name: Read version
id: get-version
run: |
pkgVersion=$(sed -ne "s/^version: \(.*\)/\1/p" pubspec.yaml)
pkgSuffix="${{ github.event.inputs.environment != 'Production' && format('-{0}', github.sha) || '' }}"
echo "version=$pkgVersion$pkgSuffix" >> $GITHUB_OUTPUT
shell: bash
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'
- name: Download all artifacts
uses: dawidd6/action-download-artifact@d0f291cf39bd21965ea9c4c6e210fc355c3844ed
with:
workflow: ci.yml
commit: ${{ github.sha }}
path: ${{ github.workspace }}/binary/
workflow_conclusion: completed
# The rename is necessary because action-download-artifact will put things in a folder named the same
# as the artifact name - i.e. librealm-linux, etc.
- name: Archive binaries
run: |
mkdir -p release
for directory in binary/*; do
targetFile="release/${directory#*-}.tar.gz"
dart run realm_dart archive --source-dir "${{ github.workspace }}/$directory" --output-file "${{ github.workspace }}/$targetFile"
done
- name: Update realm_* path dependencies (Production)
uses: jacobtomlinson/gha-find-replace@b76729678e8d52dadb12e0e16454a93e301a919d #! 2.0.0
if: ${{ github.event.inputs.environment == 'Production' }}
with:
find: " realm_(common|generator):(\\n|\\r\\n) path:.*"
replace: " realm_$1: ${{ steps.get-version.outputs.version }}"
include: "**pubspec.yaml"
- name: Update realm_* path dependencies (Staging)
uses: jacobtomlinson/gha-find-replace@b76729678e8d52dadb12e0e16454a93e301a919d #! 2.0.0
if: ${{ github.event.inputs.environment != 'Production' }}
with:
find: " realm_(common|generator):(\\n|\\r\\n) path:.*"
replace: " realm_$1:\n path: ../$1"
include: "**pubspec.yaml"
- name: Update pubspec.yaml version (Staging)
uses: jacobtomlinson/gha-find-replace@b76729678e8d52dadb12e0e16454a93e301a919d #! 2.0.0
if: ${{ github.event.inputs.environment != 'Production' }}
with:
find: 'version: .*'
replace: 'version: ${{ steps.get-version.outputs.version }}'
include: '**pubspec.yaml'
- name: Remove pubspec.yaml/publish_to:none
uses: jacobtomlinson/gha-find-replace@b76729678e8d52dadb12e0e16454a93e301a919d #! 2.0.0
with:
find: "publish_to: none(\\n|\\r\\n)"
replace: " "
include: "**pubspec.yaml"
- name: Package common
run: |
cp -Lr ../common .
cd common
dart pub publish --dry-run || true
working-directory: release
- name: Package generator
run: |
cp -Lr ../generator .
cd generator
dart pub publish --dry-run || true
working-directory: release
# realm_flutter has symlinks to native binaries which should not be packaged
- name: Cleanup binary symlinks
run: |
rm -rf flutter/realm_flutter/android/src/main/cpp/lib
rm flutter/realm_flutter/ios/src
rm flutter/realm_flutter/ios/realm_dart.xcframework
rm flutter/realm_flutter/linux/binary
rm flutter/realm_flutter/windows/binary
rm example/binary
- name: Package realm (flutter)
run: |
cp -Lr ../flutter/realm_flutter realm
cd realm
flutter pub publish --dry-run || true
working-directory: release
- name: Package realm_dart
run: |
mkdir realm_dart
cp -Lr ../bin ../example ../lib ../test realm_dart
rsync -vt ../* realm_dart/
cd realm_dart
dart pub publish --dry-run || true
working-directory: release
- name: Extract Changelog
run: |
$match = Get-Content ../CHANGELOG.md -Raw | select-string -pattern "(?ms)^(?<latestVersionChanges>.+?)(?=(\n|\r\n)## )"
$latestChanges = $match.Matches[0].Groups["latestVersionChanges"].Value;
$latestChanges | Out-File ExtractedChangelog.md
working-directory: release
shell: pwsh
- name: Upload release folder
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb
with:
name: release-bundle
path: release/**
retention-days: 30
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_KEY }}
aws-region: us-east-1
- name: Upload release folder to S3
id: upload-to-s3
run: |
tar -zcvf packages.tar.gz common generator realm_dart realm ExtractedChangelog.md
rm -rf common generator realm_dart realm ExtractedChangelog.md
s3_folder="static.realm.io/downloads/dart/${{ steps.get-version.outputs.version }}"
aws s3 sync --acl public-read . "s3://$s3_folder"
echo "url=https://$s3_folder/packages.tar.gz" >> $GITHUB_OUTPUT
working-directory: release
publish-packages:
runs-on: ubuntu-latest
if: ${{ github.event.inputs.environment == 'Production' }}
environment:
name: 'Production'
url: https://pub.dev/packages/realm/versions/${{ needs.prepare-packages.outputs.version }}
name: Publish release
needs:
- prepare-packages
steps:
- name: Checkout code
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
with:
submodules: false
- name: Download release folder
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7
with:
name: release-bundle
path: release
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'
- name: Publish packages to pub.dev
run: |
mkdir -p $HOME/.config/dart
echo '${{ secrets.PUB_CREDENTIALS }}' >> $HOME/.config/dart/pub-credentials.json
dart pub publish --directory common --force
dart pub publish --directory generator --force
dart pub publish --directory realm_dart --force
dart pub publish --directory realm --force
working-directory: release
- name: Find Release PR
uses: juliangruber/find-pull-request-action@f9f7484f8237cf8485e5ab826e542ba5dd9e9c6e
id: find-pull-request
with:
branch: ${{ github.ref }}
- name: Merge Pull Request
uses: juliangruber/merge-pull-request-action@8a13f2645ad8b6ada32f829b2fae9c0955a5265d
with:
github-token: ${{ secrets.REALM_CI_PAT }}
number: ${{ steps.find-pull-request.outputs.number }}
method: squash
- name: Publish Github Release
uses: ncipollo/release-action@10c84d509b28aae3903113151bfd832314964f2e
with:
artifacts: release/*.tar.gz
bodyFile: release/ExtractedChangelog.md
name: ${{ needs.prepare-packages.outputs.version }}
commit: main
tag: ${{ needs.prepare-packages.outputs.version }}
token: ${{ secrets.REALM_CI_PAT }}
draft: false
- name: 'Post to #realm-releases'
uses: realm/ci-actions/release-to-slack@338bf3e7575015a28faec8b67614385d122aece7
continue-on-error: true
with:
changelog: release/ExtractedChangelog.md
sdk: Flutter/Dart
webhook-url: ${{ secrets.SLACK_RELEASES_WEBHOOK }}
version: ${{ needs.prepare-packages.outputs.version }}
- name: Update Changelog
run: |
echo "## vNext (TBD)
### Enhancements
* None
### Fixed
* None
### Compatibility
* Realm Studio: 13.0.0 or later.
### Internal
* Using Core x.y.z.
" | cat - CHANGELOG.md >> temp
mv temp CHANGELOG.md
shell: bash
- name: Add vNext Changelog header
id: vnext-pr
uses: peter-evans/create-pull-request@7380612b49221684fefa025244f2ef4008ae50ad
with:
branch: vnext-changelog
title: Add vNext Changelog header
body: Update Changelog for vNext
delete-branch: true
base: main
commit-message: Add vNext Changelog header
- name: Merge Pull Request
uses: juliangruber/merge-pull-request-action@8a13f2645ad8b6ada32f829b2fae9c0955a5265d
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.vnext-pr.outputs.pull-request-number }}
method: squash