From f37eae07aa35e11c8440e9cf11308132eac663d8 Mon Sep 17 00:00:00 2001 From: Dmytro Demchenko <91938357+DimaDemchenko@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:25:22 +0200 Subject: [PATCH] Feat: npm autodeploy (#350) * npm-publish workflow * Update .github/workflows/npm-publish.yml * improvements * publish on tags * removed deprecated command * Rewrited npm-publish action * added support for different versions * removed redundant func since it doesn't affect logic * removed auto commit * updated packages.json for npm publish --------- Co-authored-by: Andriy Lysnevych --- .github/workflows/npm-publish.yml | 50 ++++++++++++++++++++ packages/p2p-media-loader-core/package.json | 24 ++++++++++ packages/p2p-media-loader-hlsjs/package.json | 22 +++++++++ packages/p2p-media-loader-shaka/package.json | 23 +++++++++ scripts/update-versions.js | 35 ++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 .github/workflows/npm-publish.yml create mode 100644 scripts/update-versions.js diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 00000000..52e960f9 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,50 @@ +on: + push: + tags: + - "*" + +jobs: + setup_and_build: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-node@v4 + with: + node-version: "20" + registry-url: "https://registry.npmjs.org/" + + - name: Setup pnpm + uses: pnpm/action-setup@v3 + with: + version: 8 + + - name: Install Dependencies + run: pnpm install + + - name: Extract version from tag + id: get_version + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - name: Update package.json version + run: | + export TAG=$VERSION + node update-versions.js + working-directory: ./scripts + + - name: Build + run: pnpm run build + + - name: Pack Packages + run: pnpm run pack-packages + + - name: NPM Publish Packages + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + for package in p2p-media-loader-core p2p-media-loader-hlsjs p2p-media-loader-shaka; do + pnpm publish ./packages/$package/$package-$VERSION.tgz --access public + done diff --git a/packages/p2p-media-loader-core/package.json b/packages/p2p-media-loader-core/package.json index 5a440215..561008dd 100644 --- a/packages/p2p-media-loader-core/package.json +++ b/packages/p2p-media-loader-core/package.json @@ -1,5 +1,29 @@ { "name": "p2p-media-loader-core", + "description": "P2P Media Loader core functionality", + "license": "Apache-2.0", + "author": "Novage", + "homepage": "https://github.com/Novage/p2p-media-loader", + "repository": { + "type": "git", + "url": "https://github.com/Novage/p2p-media-loader/tree/v1", + "directory": "packages/p2p-media-loader-core" + }, + "keywords": [ + "p2p", + "peer-to-peer", + "hls", + "dash", + "webrtc", + "video", + "mse", + "player", + "torrent", + "bittorrent", + "webtorrent", + "hlsjs", + "shaka player" + ], "version": "1.0.0", "files": [ "dist", diff --git a/packages/p2p-media-loader-hlsjs/package.json b/packages/p2p-media-loader-hlsjs/package.json index f32b6f62..0c180bad 100644 --- a/packages/p2p-media-loader-hlsjs/package.json +++ b/packages/p2p-media-loader-hlsjs/package.json @@ -1,6 +1,28 @@ { "name": "p2p-media-loader-hlsjs", "version": "1.0.0", + "description": "P2P Media Loader hls.js integration", + "license": "Apache-2.0", + "author": "Novage", + "homepage": "https://github.com/Novage/p2p-media-loader", + "repository": { + "type": "git", + "url": "https://github.com/Novage/p2p-media-loader/tree/v1", + "directory": "packages/p2p-media-loader-hlsjs" + }, + "keywords": [ + "p2p", + "peer-to-peer", + "hls", + "webrtc", + "video", + "mse", + "player", + "torrent", + "bittorrent", + "webtorrent", + "hlsjs" + ], "files": [ "dist", "lib", diff --git a/packages/p2p-media-loader-shaka/package.json b/packages/p2p-media-loader-shaka/package.json index e4b01204..c7678e12 100644 --- a/packages/p2p-media-loader-shaka/package.json +++ b/packages/p2p-media-loader-shaka/package.json @@ -1,6 +1,29 @@ { "name": "p2p-media-loader-shaka", "version": "1.0.0", + "description": "P2P Media Loader Shaka Player integration", + "license": "Apache-2.0", + "author": "Novage", + "homepage": "https://github.com/Novage/p2p-media-loader", + "repository": { + "type": "git", + "url": "https://github.com/Novage/p2p-media-loader/tree/v1", + "directory": "packages/p2p-media-loader-shaka" + }, + "keywords": [ + "p2p", + "peer-to-peer", + "hls", + "dash", + "webrtc", + "video", + "mse", + "player", + "torrent", + "bittorrent", + "webtorrent", + "shaka player" + ], "files": [ "dist", "lib", diff --git a/scripts/update-versions.js b/scripts/update-versions.js new file mode 100644 index 00000000..bfa9377a --- /dev/null +++ b/scripts/update-versions.js @@ -0,0 +1,35 @@ +const fs = require("fs"); +const path = require("path"); + +const packages = [ + "../packages/p2p-media-loader-core/package.json", + "../packages/p2p-media-loader-hlsjs/package.json", + "../packages/p2p-media-loader-shaka/package.json", +]; + +function updateVersion(packagePath, newVersion) { + const fullPath = path.resolve(packagePath); + const packageJson = require(fullPath); + const updatedPackageJson = { ...packageJson, version: newVersion }; + fs.writeFileSync( + fullPath, + JSON.stringify(updatedPackageJson, null, 2) + "\n", + ); +} + +function main() { + const newVersion = process.env.TAG; + if (!newVersion) { + console.error( + "ERROR: No version provided. Please set the TAG environment variable.", + ); + process.exit(1); + } + + packages.forEach((packagePath) => { + updateVersion(packagePath, newVersion); + console.log(`Updated ${packagePath} to version ${newVersion}`); + }); +} + +main();