-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes FEPLT-1675 chore: bump lerna to v7 chore: add post-changelog script chore: replace SLACK_API_POST_RELEASE_MESSAGE env var with variable docs: add publish releases section to contributing ci: fix lerna.json nesting
- Loading branch information
1 parent
f234800
commit 65adbd9
Showing
11 changed files
with
1,173 additions
and
1,704 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,51 @@ | ||
name: Publish | ||
|
||
on: workflow_dispatch | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
dryrun: | ||
description: "Dry run" | ||
required: false | ||
default: false | ||
type: boolean | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write # create commits and releases | ||
steps: | ||
- name: Publish dummy job | ||
run: echo "Hello publish dummy job!" | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # fetch tags | ||
|
||
- name: Node | ||
uses: ./.github/actions/node | ||
|
||
- name: Setup git config | ||
run: | | ||
git config user.name "GitHub Actions Bot" | ||
git config user.email "<>" | ||
- name: Dry run | ||
if: ${{ github.event.inputs.dryrun == 'true' }} | ||
run: | | ||
yarn lerna version --no-private --no-push --no-git-tag-version --yes | ||
git diff | ||
yarn zx scripts/post-changelog.mjs --dry | ||
- name: Publish | ||
if: ${{ github.event.inputs.dryrun == 'false' }} | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} # must be of type Automation to create releases | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
echo "scope=@kiwicom" > ~/.npmrc | ||
echo "access=public" >> ~/.npmrc | ||
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc | ||
echo "//registry.npmjs.org/:always-auth=true" >> ~/.npmrc | ||
yarn lerna publish --no-private --conventional-commits --create-release github --yes | ||
yarn docs changelog | ||
git add docs/src/data/log.md && git commit -m "docs: update changelog" && git push | ||
yarn zx scripts/post-changelog.mjs |
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import { $, fetch, argv } from "zx"; | ||
import dotenv from "dotenv-safe"; | ||
import conventionalChangelog from "conventional-changelog"; | ||
import { getPackages } from "@lerna/project"; | ||
import slackify from "slackify-markdown"; | ||
import { simpleGit } from "simple-git"; | ||
import gitDiffParser from "gitdiff-parser"; | ||
|
||
/* eslint-disable no-console */ | ||
|
||
const CHANNEL = `orbit-react`; | ||
const COLOR_CORE = `#00A58E`; | ||
const PACKAGES = ["orbit-components", "orbit-tailwind-preset"]; | ||
const PACKAGE_PREFIX = "@kiwicom"; | ||
const SLACK_API_POST_RELEASE_MESSAGE = "https://slack.com/api/chat.postMessage"; | ||
|
||
function getTitle(pkg) { | ||
return `New ${pkg} release 🚀`; | ||
} | ||
|
||
const apiRequest = async ({ method = "GET", url, body }) => | ||
fetch(url, { | ||
method, | ||
body, | ||
headers: { | ||
"Content-Type": "application/json; charset=utf-8", | ||
Authorization: `Bearer ${process.env.SLACK_TOKEN}`, | ||
Accept: "application/json", | ||
}, | ||
}); | ||
|
||
function adjustChangelog(str) { | ||
const output = str | ||
.replace("Bug Fixes", "Bug Fixes 🐛") | ||
.replace("Features", "Features 🆕") | ||
.replace("BREAKING CHANGES", "BREAKING CHANGES 🚨") | ||
.replace("Reverts", "Reverts 🔄"); | ||
|
||
return output; | ||
} | ||
|
||
function getDiff(tag, path) { | ||
return simpleGit().show([tag, path]); | ||
} | ||
|
||
function changelogPath(package_) { | ||
return `packages/${package_}/CHANGELOG.md`; | ||
} | ||
|
||
async function postSlackNotification(changelog, package_) { | ||
try { | ||
$.verbose = false; | ||
const res = await apiRequest({ | ||
url: SLACK_API_POST_RELEASE_MESSAGE, | ||
method: "POST", | ||
body: JSON.stringify({ | ||
channel: CHANNEL, | ||
attachments: [ | ||
{ | ||
title: getTitle(package_), | ||
text: changelog, | ||
color: COLOR_CORE, | ||
}, | ||
], | ||
}), | ||
}); | ||
return res; | ||
} catch (err) { | ||
console.log("Error posting to Slack"); | ||
console.error(err); | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
async function configureSlackToken() { | ||
try { | ||
dotenv.config({ | ||
allowEmptyValues: true, | ||
example: ".env.example", | ||
}); | ||
} catch (err) { | ||
if (/SLACK_TOKEN/g.test(err.message)) { | ||
throw new Error( | ||
"Slack token is missing in the .env file, please add it.\nLearn how to create one: https://slack.com/intl/en-cz/help/articles/215770388-Create-and-regenerate-API-tokens", | ||
); | ||
} | ||
} | ||
} | ||
|
||
async function getChangelogMessage(package_) { | ||
const packages = await getPackages(); | ||
|
||
return new Promise((resolve, reject) => { | ||
let changelog = ""; | ||
const pkg = packages.find(p => p.name === package_); | ||
|
||
const stream = conventionalChangelog( | ||
{ | ||
lernaPackage: pkg.name, | ||
preset: "angular", | ||
}, | ||
{ | ||
host: "https://github.com", | ||
title: package_, | ||
owner: "kiwicom", | ||
repository: "orbit", | ||
linkCompare: true, | ||
version: pkg.version, | ||
}, | ||
{ path: pkg.location }, | ||
); | ||
|
||
stream.on("data", data => { | ||
changelog += data.toString(); | ||
}); | ||
|
||
stream.on("end", () => { | ||
changelog = slackify(adjustChangelog(changelog)); | ||
resolve(changelog); | ||
}); | ||
|
||
stream.on("error", err => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
async function publishChangelog(package_) { | ||
try { | ||
const changelog = await getChangelogMessage(`${PACKAGE_PREFIX}/${package_}`); | ||
|
||
await simpleGit().fetch(["origin", "master", "--tags"]); | ||
const tags = await simpleGit().tags(); | ||
const diff = await getDiff(tags.latest ?? "", changelogPath(package_)); | ||
const files = gitDiffParser.parse(diff); | ||
if (files.length === 0) { | ||
console.log(`No changes in ${package_}`); | ||
return; | ||
} | ||
|
||
if (argv.dry) { | ||
console.info(changelog); | ||
} else { | ||
await configureSlackToken(); | ||
await postSlackNotification(changelog, package_); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
(async () => { | ||
await Promise.all( | ||
PACKAGES.map(async package_ => { | ||
await publishChangelog(package_); | ||
}), | ||
); | ||
process.exit(0); | ||
})(); |
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
Oops, something went wrong.