mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
* feat: pmg publish to npm * feat: add github action for publishing to npm * Update publish/npm/install.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> * Update .github/workflows/publish-npm.yml Co-authored-by: Omkar Phansopkar <omkarphansopkar@gmail.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> * refactor: define constants * refactor: improve npm package reliability with removing dynamic handlers and better error handling and validation * fix: publish-npm workflow * Update publish/npm/test.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> * refactor(npm-workflow): use a more portable loop construct * refactor: remove version field from package.json * feat: use os.tmpdir() with mkdtempSync for cleaner temp directory handling * fix: add redirect limit and cleanup to prevent infinite redirects and resource leaks * remove test.js for npm publisher pack * chore: test cmd cleanup --------- Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Omkar Phansopkar <omkarphansopkar@gmail.com>
98 lines
2.6 KiB
YAML
98 lines
2.6 KiB
YAML
name: Publish NPM Package
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v[0-9]+.[0-9]+.[0-9]+"
|
|
|
|
jobs:
|
|
publish-npm:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
id-token: write
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "18"
|
|
registry-url: "https://registry.npmjs.org"
|
|
|
|
- name: Extract version from tag
|
|
id: version
|
|
run: |
|
|
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Wait for GitHub release
|
|
run: |
|
|
echo "Waiting for GitHub release v${{ steps.version.outputs.version }}..."
|
|
i=1
|
|
while [ $i -le 30 ]; do
|
|
if curl -s -f "https://api.github.com/repos/safedep/pmg/releases/tags/v${{ steps.version.outputs.version }}" > /dev/null; then
|
|
echo "Release found!"
|
|
break
|
|
fi
|
|
if [ $i -eq 30 ]; then
|
|
echo "Release not found after 10 minutes"
|
|
exit 1
|
|
fi
|
|
echo "Waiting... ($i/30)"
|
|
sleep 20
|
|
i=$((i + 1))
|
|
done
|
|
|
|
- name: Prepare package
|
|
run: |
|
|
cd publish/npm
|
|
npm version ${{ steps.version.outputs.version }} --no-git-tag-version
|
|
|
|
- name: Publish to npm
|
|
run: |
|
|
cd publish/npm
|
|
npm publish --provenance
|
|
env:
|
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
|
|
test-installation:
|
|
needs: publish-npm
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
matrix:
|
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
node-version: ["16", "18", "20"]
|
|
|
|
steps:
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ matrix.node-version }}
|
|
|
|
- name: Extract version from tag
|
|
id: version
|
|
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Wait for npm package
|
|
run: |
|
|
echo "Waiting for npm package..."
|
|
i=1
|
|
while [ $i -le 20 ]; do
|
|
if npm view @safedep/pmg@${{ steps.version.outputs.version }} > /dev/null 2>&1; then
|
|
echo "Package available!"
|
|
break
|
|
fi
|
|
if [ $i -eq 20 ]; then
|
|
echo "Package not available after 10 minutes"
|
|
exit 1
|
|
fi
|
|
echo "Waiting... ($i/20)"
|
|
sleep 30
|
|
i=$((i + 1))
|
|
done
|
|
|
|
- name: Test installation
|
|
run: |
|
|
npm install -g @safedep/pmg@${{ steps.version.outputs.version }}
|
|
pmg --version
|
|
pmg --help || true
|