Publish Release #130
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}/packages/realm_dart/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 "$directory" --output-file "${{ github.workspace }}/$targetFile" | |
done | |
working-directory: packages/realm_dart | |
- 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|dart):(\\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|dart):(\\n|\\r\\n) path:.*" | |
replace: " realm_$1:\n path: ../realm_$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 realm_common | |
run: | | |
cp -Lr ../packages/realm_common . | |
cd realm_common | |
dart pub publish --dry-run || true | |
working-directory: release | |
- name: Package realm_generator | |
run: | | |
cp -Lr ../packages/realm_generator . | |
cd realm_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 packages/realm/android/src/main/cpp/lib | |
rm packages/realm/ios/src | |
rm packages/realm/ios/realm_dart.xcframework | |
rm packages/realm/linux/binary | |
rm packages/realm/windows/binary | |
rm packages/realm/macos/librealm_dart.dylib | |
rm packages/realm/example/binary | |
- name: Package realm (flutter) | |
run: | | |
cp -Lr ../packages/realm realm | |
cd realm | |
flutter pub publish --dry-run || true | |
working-directory: release | |
- name: Package realm_dart | |
run: | | |
mkdir realm_dart | |
cp -Lr ../packages/realm_dart/bin ../packages/realm_dart/example ../packages/realm_dart/lib ../packages/realm_dart/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 realm_common --force | |
dart pub publish --directory realm_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 |