diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..4b17ea8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,59 @@ +name: publish + +on: + workflow_call: + push: + branches: + - master + paths: + - package.json + +env: + CI: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v3 + - uses: actions/checkout@v3 + - run: npm install + - run: npm test + + publish-npm: + needs: [ build ] + runs-on: ubuntu-latest + environment: npm + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: true + - uses: actions/setup-node@v3 + with: + registry-url: https://registry.npmjs.org/ + - name: publish to NPM + run: npm publish --access=public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + + publish-gpr: + needs: [ build ] + runs-on: ubuntu-latest + environment: ghpm + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - uses: actions/setup-node@v3 + with: + registry-url: https://npm.pkg.github.com/ + scope: "@nodertc" + - name: rename package with @nodertc scope + run: node .npm/prepend-scope.cjs @nodertc + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.npm/prepend-scope.cjs b/.npm/prepend-scope.cjs new file mode 100755 index 0000000..0267685 --- /dev/null +++ b/.npm/prepend-scope.cjs @@ -0,0 +1,16 @@ +#!node +function usage () { + console.log(`${process.argv[1]} `) + process.exit(1) +} +const scope = process.argv[2]; if (!scope) usage() +const fs = require('fs') +const pkg = JSON.parse(fs.readFileSync('./package.json')) +const checkExistsRe = new RegExp(`^${scope}/`, 'g') +// console.log(`name: ${pkg.name}, scope: ${scope}, re: ${checkExistsRe}`) +if (checkExistsRe.test(pkg.name)) { + console.error(`already scoped to ${scope}`) + process.exit(1) +} +pkg.name = `${scope}/${pkg.name}` +fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2))