Publish Package Release #31
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 Package Release | |
on: | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: Release version tag | |
required: true | |
type: string | |
default: 'latest' | |
commit: | |
description: Optional commit to publish from | |
required: false | |
type: string | |
package: | |
description: 'Package' | |
required: true | |
default: 'realm' | |
type: choice | |
options: | |
- '@realm/babel-plugin' | |
- '@realm/common' | |
- '@realm/react' | |
- '@realm/tools' | |
- '@realm/web' | |
- '@realm/fetch' | |
jobs: | |
publish-package-release: | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: write | |
pull-requests: write | |
steps: | |
- run: echo "Publishing release for ${{inputs.package}}" | |
- uses: kanga333/[email protected] | |
name: Map package to environment variables | |
with: | |
key: "${{inputs.package}}" | |
map: | | |
{ | |
"@realm/babel-plugin": { | |
"PACKAGE_PATH": "packages/babel-plugin", | |
"PREPARE_SCRIPT_NAME": "bundle", | |
"PACKAGE_NAME": "@realm/babel-plugin", | |
"VERSION_PREFIX": "babel-plugin-", | |
"RELEASE_TITLE": "Realm Babel Plugin", | |
"SDK_NAME": "Babel Plugin" | |
}, | |
"@realm/common": { | |
"PACKAGE_PATH": "packages/realm-common", | |
"PREPARE_SCRIPT_NAME": "bundle", | |
"PACKAGE_NAME": "@realm/common", | |
"VERSION_PREFIX": "realm-common-", | |
"RELEASE_TITLE": "Realm Common", | |
"SDK_NAME": "Common" | |
}, | |
"@realm/react": { | |
"PACKAGE_PATH": "packages/realm-react", | |
"PREPARE_SCRIPT_NAME": "bundle", | |
"PACKAGE_NAME": "@realm/react", | |
"VERSION_PREFIX": "realm-react-", | |
"RELEASE_TITLE": "Realm React", | |
"SDK_NAME": "React" | |
}, | |
"@realm/tools": { | |
"PACKAGE_PATH": "packages/realm-tools", | |
"PREPARE_SCRIPT_NAME": "bundle", | |
"PACKAGE_NAME": "@realm/tools", | |
"VERSION_PREFIX": "realm-tools-", | |
"RELEASE_TITLE": "Realm Tools", | |
"SDK_NAME": "Tools" | |
}, | |
"@realm/web": { | |
"PACKAGE_PATH": "packages/realm-web", | |
"PREPARE_SCRIPT_NAME": "bundle", | |
"PACKAGE_NAME": "realm-web", | |
"VERSION_PREFIX": "realm-web-", | |
"RELEASE_TITLE": "Realm Web", | |
"SDK_NAME": "Web" | |
}, | |
"@realm/fetch": { | |
"PACKAGE_PATH": "packages/fetch", | |
"PREPARE_SCRIPT_NAME": "build", | |
"PACKAGE_NAME": "@realm/fetch", | |
"VERSION_PREFIX": "realm-fetch-", | |
"RELEASE_TITLE": "Realm Fetch", | |
"SDK_NAME": "Fetch" | |
} | |
} | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
ref: ${{ inputs.commit || github.event.pull_request.head.sha }} | |
- name: Setup node version | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: 'https://registry.npmjs.org' | |
cache: 'npm' | |
cache-dependency-path: '**/package-lock.json' | |
- name: Install node modules | |
run: npm ci --ignore-scripts | |
- name: Bundle package | |
run: npm run ${{ env.PREPARE_SCRIPT_NAME }} --workspace=${{ env.PACKAGE_NAME }} | |
- name: Read version | |
id: get-version | |
run: | | |
pkgVersion=$(jq -r .version ${{ env.PACKAGE_PATH }}/package.json) | |
echo "version=$pkgVersion" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Publish ${{ env.RELEASE_TITLE }} v${{ steps.get-version.outputs.version }} on NPM | |
working-directory: ${{ env.PACKAGE_PATH }} | |
run: npm publish --provenance --tag '${{ inputs.tag}}' | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Find Release PR | |
uses: juliangruber/[email protected] | |
id: find-pull-request | |
with: | |
branch: ${{ github.ref }} | |
- name: Merge Pull Request | |
uses: juliangruber/merge-pull-request-action@v1 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
number: ${{ steps.find-pull-request.outputs.number }} | |
method: squash | |
- name: Checkout base branch (after merge) | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
ref: ${{ steps.find-pull-request.outputs.base-ref }} | |
- name: Install node modules | |
run: npm ci --ignore-scripts | |
- name: Extract Changelog | |
run: node scripts/extract-changelog.js ${{ steps.get-version.outputs.version }} ${{ github.workspace }}/${{ env.PACKAGE_PATH }}/CHANGELOG.md > EXTRACTED_CHANGELOG.md | |
- name: Create Github Release | |
uses: ncipollo/release-action@v1 | |
with: | |
bodyFile: EXTRACTED_CHANGELOG.md | |
name: ${{ env.RELEASE_TITLE }} v${{ steps.get-version.outputs.version }} | |
tag: ${{ env.VERSION_PREFIX }}v${{ steps.get-version.outputs.version }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
draft: false | |
- name: 'Post to #realm-releases' | |
uses: realm/ci-actions/release-to-slack@9166f8af1cc0739f03702c66294ed2fe4cc55f4c | |
with: | |
changelog: EXTRACTED_CHANGELOG.md | |
sdk: ${{ env.SDK_NAME }} | |
webhook-url: ${{ secrets.SLACK_RELEASE_WEBHOOK }} | |
version: ${{ steps.get-version.outputs.version }} | |
# This job might fail due to failed markdown-to-slack conversion. | |
continue-on-error: true | |
- name: Update Changelog | |
run: npm run prepend-changelog-header -- ${{ github.workspace }}/${{ env.PACKAGE_PATH }}/CHANGELOG.md | |
- name: Create vNext PR | |
id: vnext-pr | |
uses: peter-evans/create-pull-request@v4 | |
with: | |
branch: prepare-${{ env.VERSION_PREFIX }}vnext | |
title: Prepare for ${{ env.RELEASE_TITLE }} vNext | |
body: Update Changelog for vNext | |
delete-branch: true | |
commit-message: Prepare for vNext | |
base: ${{ steps.find-pull-request.outputs.base-ref }} | |
labels: no-jira-ticket | |
- name: Merge Pull Request | |
uses: juliangruber/merge-pull-request-action@v1 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
number: ${{ steps.vnext-pr.outputs.pull-request-number }} | |
method: squash |