Skip to content

Commit

Permalink
Merge pull request #23 from editor-js/fix-notification
Browse files Browse the repository at this point in the history
fix(publish): fixed publishing notification
  • Loading branch information
e11sy authored Aug 22, 2024
2 parents c4afde7 + 0963ec4 commit 55a8924
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 125 deletions.
20 changes: 1 addition & 19 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,9 @@ jobs:
- name: Install dependencies
run: yarn install

- name: Create .npmrc and publish packages
- name: Create .yarnrc.yml and publish packages
run: |
echo "npmAuthToken: ${{ secrets.NPM_TOKEN }}" >> .yarnrc.yml
yarn publish:ci
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

notify:
needs: publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Get package info
id: package
uses: codex-team/action-nodejs-package-info@v1

- name: Send a message
uses: codex-team/action-codexbot-notify@v1
with:
webhook: ${{ env.NOTIFY_WEBHOOK_LINK }}
message: '📦 [${{ steps.package.outputs.name }}](${{ steps.package.outputs.npmjs-link }}) ${{ steps.package.outputs.version }} was published'
parse_mode: 'markdown'
disable_web_page_preview: true
Binary file modified .yarn/install-state.gz
Binary file not shown.
4 changes: 3 additions & 1 deletion packages/caret/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "@editorjs/caret",
"description": "Utils useful for work with caret for Editor.js tools development",
"version": "0.0.7",
"repository": "https://github.com/editor-js/utils/tree/main/packages/caret",
"link": "https://github.com/editor-js/utils/tree/main/packages/caret",
"version": "0.0.8",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion packages/dom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "@editorjs/dom",
"description": "Utils useful for work with dom for Editor.js tools development",
"version": "0.0.7",
"repository": "https://github.com/editor-js/utils/tree/main/packages/dom",
"link": "https://github.com/editor-js/utils/tree/main/packages/dom",
"version": "0.0.8",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion packages/helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "@editorjs/helpers",
"description": "Utils useful for Editor.js tools development",
"version": "0.0.7",
"repository": "https://github.com/editor-js/utils/tree/main/packages/helpers",
"link": "https://github.com/editor-js/utils/tree/main/packages/helpers",
"version": "0.0.8",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion packages/keyboard/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "@editorjs/keyboard",
"description": "Utils useful for work with keyboard for Editor.js tools development",
"version": "0.0.7",
"repository": "https://github.com/editor-js/utils/tree/main/packages/keyboard",
"link": "https://github.com/editor-js/utils/tree/main/packages/keyboard",
"version": "0.0.8",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down
57 changes: 51 additions & 6 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
import { execSync } from 'child_process';
import * as process from 'process';
import * as path from 'path';
import { pathExistsSync, statSync, readdirSync } from 'fs-extra';
import { pathExistsSync, statSync, readdirSync, readJsonSync } from 'fs-extra';

const packagesDir = path.join(__dirname, '..', 'packages');

/**
* Interface that represents package.json used data
*/
interface Package {
/**
* Name of the package
*/
name: string;

/**
* Version of the package
*/
version: string;

/**
* Link to the published npm package
*/
link: string;
}

/**
* Function that returns names of all packages in /packages directory
*/
function getPackages(): string[] {
function getPackages(): Package[] {
const directories = readdirSync(packagesDir).filter((dir) => {
/**
* Actutal path to the package in project
Expand All @@ -21,7 +42,11 @@ function getPackages(): string[] {
return statSync(pathToPackage).isDirectory() && pathExistsSync(path.join(pathToPackage, 'package.json'));
});

return directories;
const packages: Package[] = directories.map((dir) => {
return readJsonSync(path.join('packages', dir, 'package.json')) as Package;
});

return packages;
}

execSync('npm run build', { stdio: 'inherit' });
Expand All @@ -33,7 +58,27 @@ const packages = getPackages();
/**
* For each package run yarn npm publish
*/
for (const name of packages) {
execSync(command, { stdio: 'inherit',
cwd: path.join('packages', name) });
for (const { name, version, link } of packages) {
const response = execSync(command, { cwd: path.join('packages', name.replace('@editorjs/', '')),
encoding: 'utf8' });

/**
* If version of any package was updated, then notify, otherwise pass
*/
if (!response.includes('Registry already knows about version') && process.env.NOTIFY_WEBHOOK !== undefined) {
/**
* Use notification webhook from workflow (script will not work fro)
*/
fetch(process.env.NOTIFY_WEBHOOK, {
method: 'POST',
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
message: `📦 (${name})[${link}] ${version} was published`,
}),
})
.catch(error => console.error('Error:', error));
}
}
Loading

0 comments on commit 55a8924

Please sign in to comment.