Skip to content

Commit

Permalink
Improving "publish release" workflow (#4898)
Browse files Browse the repository at this point in the history
* Update publish-release.yml

* Update publish-release.yml

* Update publish-release.yml

* Update publish-release.yml

* Update publish-release.yml

* Update publish-release.yml

* Extracting changelog using a JS script

* Updated the naming when slacking

* Reverting comments

* Arming the slack action

* Adding a note on the forked action

* Update .gitignore
  • Loading branch information
kraenhansen authored Sep 13, 2022
1 parent 2ed4a42 commit a7c8c9f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 15 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Find Release PR
uses: juliangruber/find-pull-request-action@f9f7484f8237cf8485e5ab826e542ba5dd9e9c6e
# TODO: Revert this to upstream action once https://github.com/juliangruber/find-pull-request-action/pull/33 gets merged
uses: kraenhansen/find-pull-request-action@master
id: find-pull-request
with:
branch: ${{ github.ref }}
Expand All @@ -100,13 +101,19 @@ jobs:
number: ${{ steps.find-pull-request.outputs.number }}
method: squash

- name: Checkout base branch (after merge)
uses: actions/checkout@v3
with:
submodules: recursive
ref: ${{ github.event.pull_request.base.ref }}

- name: Extract Changelog
run: scripts/extract-changelog.sh ${{ steps.get-version.outputs.version }} > ExtractedChangelog.md
run: node scripts/extract-changelog.js ${{ steps.get-version.outputs.version }} > EXTRACTED_CHANGELOG.md

- name: Create Github Release
uses: ncipollo/release-action@10c84d509b28aae3903113151bfd832314964f2e
with:
bodyFile: ExtractedChangelog.md
bodyFile: EXTRACTED_CHANGELOG.md
name: ${{ steps.get-version.outputs.version }}
tag: v${{ steps.get-version.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -116,8 +123,8 @@ jobs:
- name: 'Post to #realm-releases'
uses: realm/ci-actions/release-to-slack@v3
with:
changelog: ExtractedChangelog.md
sdk: JS
changelog: EXTRACTED_CHANGELOG.md
sdk: JavaScript
webhook-url: ${{ secrets.SLACK_RELEASE_WEBHOOK }}
version: ${{ steps.get-version.outputs.version }}
# This job might fail due to failed markdown-to-slack conversion.
Expand All @@ -135,7 +142,7 @@ jobs:
body: Update Changelog for vNext
delete-branch: true
commit-message: Prepare for vNext
base: master
base: ${{ steps.find-pull-request.outputs.base-ref }}

- name: Merge Pull Request
uses: juliangruber/merge-pull-request-action@8a13f2645ad8b6ada32f829b2fae9c0955a5265d
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ vendor/realm-*
!vendor/realm-core

# extracted changelog
ExtractedChangelog.md
EXTRACTED_CHANGELOG.md

# jsdoc
/docs/output
Expand Down
41 changes: 41 additions & 0 deletions scripts/extract-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2022 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

const fs = require("node:fs");
const path = require("node:path");

function extractRelease(changelog, expectedVersion) {
// Inspired by https://github.com/realm/ci-actions/blob/main/update-changelog/src/helpers.ts
const changelogRegex = /^## (?<version>[^\s]+) \((?<date>[^)]+)\)\s+(?<body>.*?)\s+(?=^## )/gms;
let match;
while ((match = changelogRegex.exec(changelog))) {
const release = match.groups;
if (!expectedVersion || expectedVersion === release.version) {
return release;
}
}
throw new Error("Unable to extract release");
}

if (require.main === module) {
const changelogPath = path.resolve(__dirname, "../CHANGELOG.md");
const changelog = fs.readFileSync(changelogPath, { encoding: "utf8" });
const version = process.argv[2];
const release = extractRelease(changelog, version);
console.log(release.body);
}
8 changes: 0 additions & 8 deletions scripts/extract-changelog.sh

This file was deleted.

0 comments on commit a7c8c9f

Please sign in to comment.