Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: npm autodeploy #350

Merged
merged 11 commits into from
Mar 18, 2024
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();