|
| 1 | +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created |
| 2 | +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages |
| 3 | + |
| 4 | +name: Publish Package |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Node.js |
| 18 | + uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version-file: '.node-version' |
| 21 | + |
| 22 | + - name: Install dependencies |
| 23 | + run: | |
| 24 | + if [ -f package-lock.json ]; then |
| 25 | + echo "package-lock.json found, using 'npm ci'" |
| 26 | + npm ci |
| 27 | + else |
| 28 | + echo "package-lock.json not found, using 'npm install'" |
| 29 | + npm install |
| 30 | + fi |
| 31 | +
|
| 32 | + - name: Run test |
| 33 | + run: npm test |
| 34 | + |
| 35 | + - name: Run build |
| 36 | + run: npm run build |
| 37 | + |
| 38 | + - name: Dry run publish |
| 39 | + run: npm pack -dry-run |
| 40 | + |
| 41 | + - name: Upload artifact |
| 42 | + uses: actions/upload-artifact@v4 |
| 43 | + with: |
| 44 | + name: dist |
| 45 | + path: dist |
| 46 | + retention-days: 1 |
| 47 | + |
| 48 | + publish: |
| 49 | + env: |
| 50 | + CHECK_NPM_TOKEN: ${{ secrets.NPM_TOKEN != '' }} |
| 51 | + needs: build |
| 52 | + runs-on: ubuntu-latest |
| 53 | + permissions: |
| 54 | + contents: read |
| 55 | + id-token: write |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Download artifact |
| 60 | + uses: actions/download-artifact@v4 |
| 61 | + with: |
| 62 | + path: . |
| 63 | + |
| 64 | + - name: Set npm registry url |
| 65 | + uses: actions/setup-node@v4 |
| 66 | + with: |
| 67 | + node-version-file: '.node-version' |
| 68 | + registry-url: 'https://registry.npmjs.org' |
| 69 | + |
| 70 | + - name: Dry run publish |
| 71 | + run: npm pack -dry-run |
| 72 | + |
| 73 | + - name: Publish |
| 74 | + if: ${{ env.CHECK_NPM_TOKEN == 'true'}} |
| 75 | + env: |
| 76 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 77 | + run: npm publish . --provenance --access public |
| 78 | + |
| 79 | + - name: Clean up |
| 80 | + uses: geekyeggo/delete-artifact@v5 |
| 81 | + with: |
| 82 | + name: dist |
0 commit comments