Skip to content

Publish Release

Publish Release #163

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@v4
with:
submodules: false
- name: Read version
id: get-version
run: |
pkgVersion=$(sed -ne "s/^version: \(.*\)/\1/p" packages/realm_dart/pubspec.yaml)
pkgSuffix="${{ github.event.inputs.environment != 'Production' && format('-{0}', github.sha) || '' }}"
echo "version=$pkgVersion$pkgSuffix" >> $GITHUB_OUTPUT
shell: bash
- name: Setup Runner
uses: ./.github/actions/setup-runner
- name: Download all artifacts
uses: dawidd6/action-download-artifact@71072fbb1229e1317f1a8de6b04206afb461bd67 # 3.1.2
with:
workflow: ci.yml
commit: ${{ github.sha }}
path: ${{ github.workspace }}/binary/
workflow_conclusion: completed
github_token: ${{ secrets.REALM_CI_PAT }}
# 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 ${{ github.workspace }}/release
for directory in ${{ github.workspace }}/binary/*; do
artifactFolder=$(basename $directory)
targetFile="${{ github.workspace }}/release/${artifactFolder#*-}.tar.gz"
dart run realm_dart archive --source-dir "$directory" --output-file "$targetFile"
done
working-directory: packages/realm_dart
shell: bash
- name: Update pubspec.yaml version (Staging)
if: ${{ github.event.inputs.environment != 'Production' }}
run: REALM_VERSION=${{ steps.get-version.outputs.version }} melos run update:version:realm
- 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 symlinks
run: |
rm packages/realm/android/src/main/cpp/lib
rm packages/realm/ios/realm_dart.xcframework
rm packages/realm/linux/binary
rm packages/realm/windows/binary
rm -rf packages/realm/tests/linux/flutter/ephemeral
rm -rf packages/realm/tests/windows/flutter/ephemeral
- 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 -vtL ../packages/realm_dart/* 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@v4
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 realm_common realm_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@v4
with:
submodules: false
- name: Download release folder
uses: actions/download-artifact@v4
with:
name: release-bundle
path: release
- name: Setup Runner
uses: ./.github/actions/setup-runner
# realm_flutter has symlinks to native binaries which should not be packaged
- name: Cleanup symlinks
run: |
rm packages/realm/android/src/main/cpp/lib
rm packages/realm/ios/realm_dart.xcframework
rm packages/realm/linux/binary
rm packages/realm/windows/binary
rm -rf packages/realm/tests/linux/flutter/ephemeral
rm -rf packages/realm/tests/windows/flutter/ephemeral
- name: Publish packages to pub.dev
run: |
mkdir -p $HOME/.config/dart
echo '${{ secrets.PUB_CREDENTIALS }}' >> $HOME/.config/dart/pub-credentials.json
melos exec --no-published --no-private -- dart pub publish --force --skip-validation
- name: Reset repo state
run: git reset --hard
- 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:
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 #appx-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: 15.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
labels: no-jira-ticket
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