Skip to content

Commit

Permalink
Feat: npm autodeploy (#350)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
DimaDemchenko and mrlika authored Mar 18, 2024
1 parent 26361e4 commit f37eae0
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions packages/p2p-media-loader-core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
22 changes: 22 additions & 0 deletions packages/p2p-media-loader-hlsjs/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 23 additions & 0 deletions packages/p2p-media-loader-shaka/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
35 changes: 35 additions & 0 deletions scripts/update-versions.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit f37eae0

Please sign in to comment.