|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: Validate tests and build npm package |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v6 |
| 18 | + with: |
| 19 | + # Fetch all to count number of commits and compute pkg version |
| 20 | + fetch-depth: 0 |
| 21 | + - uses: actions/setup-node@v6 |
| 22 | + with: |
| 23 | + node-version: lts/* |
| 24 | + cache: npm |
| 25 | + - name: Install dependencies |
| 26 | + run: npm ci |
| 27 | + - name: Build npm package |
| 28 | + run: node scripts/build-npm-package.js |
| 29 | + - name: Check that JSON files match their TypeScript types |
| 30 | + run: node scripts/check-types.js |
| 31 | + - name: Pack npm package |
| 32 | + run: mkdir -p dist && npm pack ./npm-package --pack-destination dist |
| 33 | + - name: Upload package tarball |
| 34 | + uses: actions/upload-artifact@v7 |
| 35 | + with: |
| 36 | + name: npm-package |
| 37 | + path: dist/*.tgz |
| 38 | + if-no-files-found: error |
| 39 | + retention-days: 7 |
| 40 | + |
| 41 | + publish: |
| 42 | + name: Publish to npm |
| 43 | + needs: build |
| 44 | + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && github.repository == 'tc39/source-map-tests' |
| 45 | + runs-on: ubuntu-latest |
| 46 | + permissions: |
| 47 | + contents: read |
| 48 | + id-token: write # for npm trusted publishing |
| 49 | + concurrency: |
| 50 | + group: npm-publish |
| 51 | + cancel-in-progress: false |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v6 |
| 54 | + with: |
| 55 | + fetch-depth: 0 |
| 56 | + - uses: actions/setup-node@v6 |
| 57 | + with: |
| 58 | + node-version: lts/* |
| 59 | + registry-url: https://registry.npmjs.org |
| 60 | + - name: Build npm package |
| 61 | + run: node scripts/build-npm-package.js |
| 62 | + - name: Publish |
| 63 | + run: | |
| 64 | + name=$(node -p "require('./npm-package/package.json').name") |
| 65 | + version=$(node -p "require('./npm-package/package.json').version") |
| 66 | + if [ -n "$(npm view "$name@$version" version 2>/dev/null)" ]; then |
| 67 | + echo "$name@$version is already published, skipping." |
| 68 | + else |
| 69 | + npm publish ./npm-package --access public |
| 70 | + fi |
0 commit comments