diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5f369d8..fb125b1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,145 +4,14 @@ on: push: branches: - main - schedule: - - cron: "30 0/3 * * *" - # Manual dispatch, only for testing purposes. See - # https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow - workflow_dispatch: jobs: - # Check and update - check_and_update: - runs-on: ubuntu-latest + test: + uses: mafalda-sfu/workflows/.github/workflows/main-no_coverage.yml@v1 - outputs: - new_version: ${{ steps.update.outputs.new_version }} + with: + node-version: lts/-1 + registry-url: https://npm.pkg.github.com - steps: - - uses: actions/checkout@v4 - with: - ssh-key: "${{secrets.COMMIT_KEY}}" - - # Setup Node.js - - name: Node.js - uses: actions/setup-node@v4 - with: - node-version: lts/-1 - - # Install dependencies - - run: npm ci --verbose - - # Config git user name and email - - name: Config git user name and email - run: | - git config user.name github-actions - git config user.email github-actions@github.com - - # Update tests - - name: Update tests - id: update - run: | - echo "old version: `node -p \"require('./package.json').version\"`" - new_version=`scripts/update.js` - echo "new version: ${new_version}" - echo "new_version=${new_version}" >> "$GITHUB_OUTPUT" - - # Update dependencies - - name: Update dependencies - if : ${{ steps.update.outputs.new_version != '' }} - run: | - npx npm-check-updates --target semver --upgrade - npm install --verbose - - # # Ensure extracted tests are working - # - name: Run tests - # if : ${{ steps.update.outputs.new_version != '' }} - # run: npm test - - # Commit and push changes - - name: Commit and push changes - if : ${{ steps.update.outputs.new_version != '' }} - run: npm run release - - - # - # Publish to registries and GitHub release - # - - # GitHub Package Registry - publish-gpr: - if : ${{ needs.check_and_update.outputs.new_version != '' }} - needs: check_and_update - runs-on: ubuntu-latest - permissions: - contents: read - id-token: write - packages: write - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ needs.check_and_update.outputs.new_version }} - - uses: actions/setup-node@v4 - with: - node-version: lts/-2 - registry-url: https://npm.pkg.github.com/ - - # Publish - - run: npm ci --verbose - - run: npm publish --provenance - env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} - - # NPM registry - publish-npm-registry: - if : ${{ needs.check_and_update.outputs.new_version != '' }} - needs: check_and_update - runs-on: ubuntu-latest - - permissions: - id-token: write - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ needs.check_and_update.outputs.new_version }} - - uses: actions/setup-node@v4 - with: - node-version: lts/-2 - registry-url: https://registry.npmjs.org/ - - # Publish - - run: npm ci --verbose - - run: npm publish --provenance - env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} - - # GitHub release - upload-to-github-release: - if : ${{ needs.check_and_update.outputs.new_version != '' }} - needs: check_and_update - permissions: - contents: write - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ needs.check_and_update.outputs.new_version }} - - uses: actions/setup-node@v4 - with: - node-version: lts/-2 - - # Create package - - run: npm ci --verbose - - run: npm pack - - # Create release - - name: Create release - uses: softprops/action-gh-release@v1 - with: - files: '*.tgz' - generate_release_notes: true - tag_name: ${{ needs.check_and_update.outputs.new_version }} - # --verify-tag + secrets: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/schedule.yml b/.github/workflows/schedule.yml new file mode 100644 index 0000000..10044ad --- /dev/null +++ b/.github/workflows/schedule.yml @@ -0,0 +1,30 @@ +name: schedule + +on: + schedule: + - cron: "30 0/4 * * *" + +jobs: + check_and_update: + uses: mafalda-sfu/workflows/.github/workflows/schedule.yml@v1 + + with: + destination-github-username: Mafalda-SFU + dependencies-update-latest: "@mafalda-sfu/* mediasoup" + destination-repository-name: Mafalda-SFU.github.io + reference-package-name: "@mafalda-sfu/scalabilitymodes" + update-script: scripts/update.js + user-email: bot@mafalda.io + user-name: Mafalda Bot + + # Docs + docs-coverage_gistID: ${{ vars.DOCS_COVERAGE_GISTID }} + + # Publish GitHub Packages Registry + gpr-npm-version_gistID: ${{ vars.GPR_NPM_VERSION_GISTID }} + + secrets: + GIST_SECRET: ${{ secrets.GIST_SECRET }} + npm_token: ${{ secrets.npm_token }} + SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }} + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} diff --git a/package.json b/package.json index c2bd26b..da59b0d 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,7 @@ }, "scripts": { "build": "tsc", - "prepare": "npm run build", - "release": "scripts/release.js", - "test": "echo \"Error: no test specified\" && exit 1", - "update": "scripts/update.js" + "prepare": "npm run build" }, "repository": { "type": "git", @@ -36,10 +33,7 @@ "h264-profile-level-id": "^2.0.0" }, "devDependencies": { - "@npmcli/package-json": "^5.0.0", "@types/node": "^20.11.0", - "semver": "^7.5.4", - "simple-git": "^3.22.0", "tar-stream": "^3.1.6", "typescript": "^5.3.3" } diff --git a/scripts/release.js b/scripts/release.js deleted file mode 100755 index 58872ef..0000000 --- a/scripts/release.js +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env node - -const PackageJson = require('@npmcli/package-json'); -const simpleGit = require('simple-git'); - - -(async function() -{ - const {content: {version}} = await PackageJson.load('.') - - const git = simpleGit() - - await git.add('.') - await git.commit(`Update to mediasoup@${version}`) - await git.addTag(version) - - await Promise.all([ - git.push(), - git.pushTags() - ]) -})() diff --git a/scripts/update.js b/scripts/update.js index fb36765..8feff36 100755 --- a/scripts/update.js +++ b/scripts/update.js @@ -6,10 +6,6 @@ const {Readable} = require('node:stream'); const {text} = require('node:stream/consumers'); const {createGunzip} = require('node:zlib'); -const PackageJson = require('@npmcli/package-json'); -const eq = require('semver/functions/eq.js'); -const lt = require('semver/functions/lt.js'); -const simpleGit = require('simple-git'); const tar = require('tar-stream'); const ts = require('typescript'); @@ -18,36 +14,13 @@ const options = {force: true, recursive: true} const repo = 'versatica/mediasoup' -function isNotRustRelease({tag_name}) -{ - return !tag_name.startsWith('rust-') -} +const {argv: [,, version]} = process (async function() { - const releases = await fetch(`https://api.github.com/repos/${repo}/releases`) - .then(res => res.json()) - - const {url} = releases.find(isNotRustRelease) - - const [{tag_name: version, tarball_url}, pkgJson] = await Promise.all([ - fetch(url) - .then(res => res.json()), - PackageJson.load('.') - ]) - - if(lt(version, pkgJson.content.version)) - throw new Error( - `Published mediasoup version ${version} is older than version ` + - `${pkgJson.content.version} from the package.json file. Maybe there's ` + - `a mistake in the package.json version?` - ) - - if(eq(version, pkgJson.content.version)) return - const [{body}] = await Promise.all([ - fetch(tarball_url), + fetch(`https://api.github.com/repos/${repo}/tarball/${version}`), rm('src', options) .then(mkdir.bind(null, 'src', options)) ]) @@ -230,27 +203,4 @@ function isNotRustRelease({tag_name}) entry.resume() } - - const git = simpleGit() - const {files: {length}} = await git.status() - if(!length) return - - const { - content: { - dependencies, devDependencies, optionalDependencies, peerDependencies - } - } = pkgJson - - pkgJson.update({ - dependencies, - devDependencies, - optionalDependencies, - peerDependencies, - version - }) - - await pkgJson.save() - - // Print new version - console.log(version) })()