Skip to content

Commit c1d4518

Browse files
authored
feat: publish npm package on npmjs.com registry (#3908)
Refs #3900 Refs #3907 Refs #3906 Refs #3901
1 parent d41c0ee commit c1d4518

File tree

7 files changed

+215
-89
lines changed

7 files changed

+215
-89
lines changed

.github/workflows/docker-build-push.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@ jobs:
4444
mkdir build
4545
unzip build.zip -d build
4646
47+
- name: Determine released version
48+
uses: actions/github-script@v6
49+
with:
50+
script: |
51+
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
run_id: context.payload.workflow_run.id,
55+
});
56+
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
57+
return artifact.name == "released-version"
58+
})[0];
59+
const download = await github.rest.actions.downloadArtifact({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
artifact_id: matchArtifact.id,
63+
archive_format: 'zip',
64+
});
65+
const fs = require('fs');
66+
fs.writeFileSync('${{github.workspace}}/released-version.zip', Buffer.from(download.data));
67+
- run: |
68+
unzip released-version.zip
69+
RELEASED_VERSION=$(cat released-version.txt)
70+
echo "RELEASED_VERSION=RELEASED_VERSION" >> $GITHUB_ENV
71+
4772
- name: Set up QEMU
4873
uses: docker/setup-qemu-action@v2
4974

@@ -60,15 +85,15 @@ jobs:
6085
uses: docker/build-push-action@v4
6186
with:
6287
context: .
63-
push: true
88+
push: false
6489
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/386,linux/ppc64le,linux/s390x
65-
tags: swaggerapi/swagger-editor:next-v5
90+
tags: swaggerapi/swagger-editor:next-v5,swaggerapi/swagger-editor:v${{ env.RELEASED_VERSION }}
6691

6792
- name: Build unprivileged docker image and push
6893
uses: docker/build-push-action@v4
6994
with:
7095
context: .
7196
file: Dockerfile.unprivileged
72-
push: true
97+
push: false
7398
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/386,linux/ppc64le,linux/s390x
74-
tags: swaggerapi/swagger-editor:next-v5-unprivileged
99+
tags: swaggerapi/swagger-editor:next-v5-unprivileged,swaggerapi/swagger-editor:v${{ env.RELEASED_VERSION }}-unprivileged

.github/workflows/release.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ jobs:
2727
env:
2828
GITHUB_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
2929
NPM_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
30-
NODE_AUTH_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
3130

3231
- name: Nothing to release
3332
if: ${{ env.NEXT_RELEASE_VERSION == '' }}
@@ -44,28 +43,27 @@ jobs:
4443
- name: Install dependencies
4544
run: npm ci
4645

47-
- name: Prepare for the Release
48-
env:
49-
REACT_APP_VERSION: ${{ env.NEXT_RELEASE_VERSION }}
50-
run: |
51-
npm run lint
52-
npm run test
53-
npm run build:app
54-
npm run cy:ci
55-
npm run build:bundle:esm
56-
npm run build:bundle:umd
46+
# - name: Prepare for the Release
47+
# env:
48+
# REACT_APP_VERSION: ${{ env.NEXT_RELEASE_VERSION }}
49+
# run: |
50+
# npm run lint
51+
# npm run test
52+
# npm run build:app
53+
# npm run cy:ci
54+
# npm run build:bundle:esm
55+
# npm run build:bundle:umd
5756

5857
- name: Semantic Release
5958
id: semantic
6059
uses: cycjimmy/semantic-release-action@v3
6160
with:
62-
dry_run: false
61+
dry_run: true
6362
extra_plugins: |
6463
@semantic-release/git
6564
env:
6665
GITHUB_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
6766
NPM_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
68-
NODE_AUTH_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
6967

7068
- name: Release failed
7169
if: steps.semantic.outputs.new_release_published == 'false'
@@ -86,3 +84,15 @@ jobs:
8684
with:
8785
name: build
8886
path: ./build
87+
88+
89+
- name: Prepare released version for uploading
90+
shell: bash
91+
run: |
92+
echo ${{ steps.semantic.outputs.new_release_version }} > released-version.txt
93+
- name: Upload released version
94+
uses: actions/upload-artifact@v3
95+
with:
96+
name: released-version
97+
path: ./released-version.txt
98+
retention-days: 1

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
/.commitlintrc.json
2121
/cypress.config.js
2222
/Dockerfile
23+
/Dockerfile.unprivileged
2324
/.eslintrc
25+
/.gitattributes
2426
/.editorconfig
2527
/swagger-api-swagger-editor-*.tgz

README.md

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,49 +32,23 @@ These prerequisites are required both for installing SwaggerEditor as a npm pack
3232
### Installation
3333

3434
Assuming [prerequisites](#prerequisites) are already installed, SwaggerEditor npm package is installable and works with `Node.js >= 12.22.0`.
35-
SwaggerEditor npm package is currently hosted on [GitHub packages registry](https://docs.github.com/en/packages/learn-github-packages/introduction-to-github-packages).
36-
37-
You can authenticate to GitHub Packages with npm by either editing your per-user *~/.npmrc*
38-
file to include your personal access token (classic) or by logging in to npm on the command line using your username and personal access token.
39-
40-
To authenticate by adding your personal access token (classic) to your *~/.npmrc* file,
41-
edit the *~/.npmrc* file for your project to include the following line,
42-
replacing TOKEN with your personal access token. Create a new *~/.npmrc* file if one doesn't exist.
43-
You can find more information about authenticating to GitHub Packages in [GitHub documentation](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#authenticating-to-github-packages).
44-
45-
Last step is to include a line to the *.npmrc* file, specifying GitHub Packages URL and the namespace *(@swagger-api)* where the package is hosted.
46-
47-
```
48-
@swagger-api:registry=https://npm.pkg.github.com
49-
//npm.pkg.github.com/:_authToken=TOKEN
50-
```
51-
52-
You can now install SwaggerEditor package using `npm`:
35+
You can install SwaggerEditor via [npm CLI](https://docs.npmjs.com/cli) by running the following command:
5336

5437
```sh
55-
$ npm install @swagger-api/swagger-editor
38+
$ npm install swagger-editor@>=5
5639
````
5740

58-
For more information about installing npm packages from GitHub packages registry please visit [Installing a package](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#installing-a-package)
59-
section in GitHub documentation.
60-
6141
### Usage
6242

63-
Install the package:
64-
65-
```sh
66-
$ npm install @swagger-api/swagger-editor
67-
````
68-
6943
Use the package in you application:
7044

7145
**index.js**:
7246

7347
```js
7448
import React from 'react';
7549
import ReactDOM from 'react-dom';
76-
import SwaggerEditor from '@swagger-api/swagger-editor';
77-
import '@swagger-api/swagger-editor/swagger-editor.css';
50+
import SwaggerEditor from 'swagger-editor';
51+
import 'swagger-editor/swagger-editor.css';
7852
7953
const url = "https://raw.githubusercontent.com/asyncapi/spec/v2.2.0/examples/streetlights-kafka.yml";
8054
@@ -118,8 +92,8 @@ module.exports = {
11892
mode: 'production',
11993
entry: {
12094
app: './index.js',
121-
'apidom.worker': '@swagger-api/swagger-editor/apidom.worker',
122-
'editor.worker': '@swagger-api/swagger-editor/editor.worker',
95+
'apidom.worker': 'swagger-editor/apidom.worker',
96+
'editor.worker': 'swagger-editor/editor.worker',
12397
},
12498
output: {
12599
globalObject: 'self',
@@ -303,11 +277,11 @@ module.exports = {
303277
new CopyWebpackPlugin({
304278
patterns: [
305279
{
306-
from: 'node_modules/@swagger-api/swagger-editor/dist/umd/apidom.worker.js',
280+
from: 'node_modules/swagger-editor/dist/umd/apidom.worker.js',
307281
to: 'static/js',
308282
},
309283
{
310-
from: 'node_modules/@swagger-api/swagger-editor/dist/umd/editor.worker.js',
284+
from: 'node_modules/swagger-editor/dist/umd/editor.worker.js',
311285
to: 'static/js',
312286
}
313287
]
@@ -452,7 +426,7 @@ It's bundled with React defined as external. This allows consumer to use his own
452426
453427
**npm**
454428
455-
SwaggerEditor is released as `@swagger-api/swagger-editor` npm package on [GitHub packages registry](https://docs.github.com/en/packages/learn-github-packages/introduction-to-github-packages).
429+
SwaggerEditor is released as `swagger-editor@5` npm package on [npmjs.com](https://npmjs.com).
456430
Package can also be produced manually by running following commands (assuming you're already followed [setting up](#setting-up) steps):
457431
458432
```sh
@@ -527,7 +501,7 @@ import React from 'react';
527501
import ReactDOM from 'react-dom';
528502
import SwaggerUI from 'swagger-ui-react';
529503
import 'swagger-ui-react/swagger-ui.css';
530-
import SwaggerEditor from '@swagger-api/swagger-editor';
504+
import SwaggerEditor from 'swagger-editor';
531505
532506
const plugins = [
533507
SwaggerEditor.plugins.EditorContentType,

docs/customization/plug-points/editor-monaco.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Static extension involves need to use a build system like webpack.
6262
**my-custom-apidom.worker.js**
6363

6464
```js
65-
import { initialize, makeCreate, ApiDOMWorker } from '@swagger-api/swagger-editor/apidom.worker';
65+
import { initialize, makeCreate, ApiDOMWorker } from 'swagger-editor/apidom.worker';
6666

6767
class ApiDOMWorkerExtended extends ApiDOMWorker {
6868
// implementation of extensions
@@ -89,7 +89,7 @@ This is the part of the configuration that will change.
8989
entry: {
9090
app: './index.js',
9191
'apidom.worker': './my-custom-apidom.worker.js',
92-
'editor.worker': '@swagger-api/swagger-editor/editor.worker',
92+
'editor.worker': 'swagger-editor/editor.worker',
9393
}
9494
```
9595

@@ -146,7 +146,7 @@ Whenever you extend the `ApiDOMWorker` class you will have `_createData` public
146146
**my-custom-apidom.worker.js**
147147

148148
```js
149-
import { initialize, makeCreate, ApiDOMWorker } from '@swagger-api/swagger-editor/apidom.worker';
149+
import { initialize, makeCreate, ApiDOMWorker } from 'swagger-editor/apidom.worker';
150150

151151
class ApiDOMWorkerExtended extends ApiDOMWorker {
152152
async loadData() {

0 commit comments

Comments
 (0)