|
1 | | -name: Release - Test, Build, Publish |
| 1 | +name: Build, Test, and Publish Library |
2 | 2 |
|
3 | 3 | on: |
4 | | - release: |
5 | | - types: [created] # Triggers when a new release is created |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - v1 # or whatever branch you want to test PRs against |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - 'v*.*.*' # trigger on new version tags for publishing to npm |
6 | 10 |
|
7 | 11 | jobs: |
8 | | - test_build_publish: |
| 12 | + test: |
9 | 13 | runs-on: ubuntu-latest |
10 | 14 | strategy: |
11 | 15 | matrix: |
12 | | - node-version: [14, 18, 23] # Test on Node.js versions 14, 18, and 23 |
13 | | - |
| 16 | + node-version: [14, 18, 23] # Define the Node.js versions to test on |
| 17 | + |
14 | 18 | steps: |
15 | 19 | - name: Checkout repository |
16 | | - uses: actions/checkout@v2 |
| 20 | + uses: actions/checkout@v2 # Checkout code |
17 | 21 |
|
18 | 22 | - name: Set up Node.js |
19 | 23 | uses: actions/setup-node@v3 |
20 | 24 | with: |
21 | | - node-version: ${{ matrix.node-version }} # Use the Node.js version from the matrix |
| 25 | + node-version: ${{ matrix.node-version }} # Use the version from the matrix |
22 | 26 |
|
23 | 27 | - name: Install dependencies |
24 | | - run: | |
25 | | - npm ci # Installs dependencies based on the lockfile (package-lock.json) |
| 28 | + run: npm ci # Install dependencies from the lockfile |
26 | 29 |
|
27 | 30 | - name: Build the library |
28 | | - run: npm run build # Runs your build script from package.json |
| 31 | + run: npm run build # Assuming you have a build script in package.json |
29 | 32 |
|
30 | 33 | - name: Run tests |
31 | | - run: npm test # Runs your test command |
| 34 | + run: npm test # Run your tests |
| 35 | + |
| 36 | + publish: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + needs: test # Ensure the tests are run first |
| 39 | + if: startsWith(github.ref, 'refs/tags/v') # Only run this on new version tags |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Checkout repository |
| 43 | + uses: actions/checkout@v2 |
| 44 | + |
| 45 | + - name: Set up Node.js |
| 46 | + uses: actions/setup-node@v3 |
| 47 | + with: |
| 48 | + node-version: 18 # Use any version (this is just for publishing) |
| 49 | + |
| 50 | + - name: Install dependencies |
| 51 | + run: npm ci # Install dependencies from the lockfile |
| 52 | + |
| 53 | + - name: Build the library |
| 54 | + run: npm run build # Build your library |
32 | 55 |
|
33 | 56 | - name: Publish to npm |
| 57 | + run: npm publish --access public # Publish to npm |
| 58 | + |
34 | 59 | env: |
35 | | - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Make sure to set NPM_TOKEN as a secret in GitHub |
36 | | - run: npm publish --access public # Publishes the package to npm |
| 60 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Ensure the token is set in GitHub Secrets |
0 commit comments