|
1 | 1 | name: Release
|
2 | 2 |
|
3 |
| -on: [push, pull_request] |
4 |
| - |
| 3 | +#----------------------------------------------------------------------------- |
| 4 | +# Events triggering this workflow |
| 5 | +#----------------------------------------------------------------------------- |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main # Trigger on pushes to the 'main' branch |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main # Trigger on pull requests to the 'main' branch |
| 13 | + |
| 14 | +#----------------------------------------------------------------------------- |
| 15 | +# Jobs: Tasks executed as part of the release workflow |
| 16 | +#----------------------------------------------------------------------------- |
5 | 17 | jobs:
|
| 18 | + # Build job |
6 | 19 | build:
|
| 20 | + name: Build the project |
7 | 21 | runs-on: ubuntu-latest
|
8 | 22 |
|
9 | 23 | strategy:
|
10 | 24 | matrix:
|
11 |
| - node-version: [21.x] |
| 25 | + node-version: [18, 21] # Test against Node.js 18 and 21 |
12 | 26 |
|
13 | 27 | steps:
|
14 |
| - - run: echo ${{github.ref}} |
15 |
| - |
16 |
| - - uses: actions/checkout@v3 |
| 28 | + # Step 1: Check out the repository |
| 29 | + - name: Check out code |
| 30 | + uses: actions/checkout@v3 |
17 | 31 |
|
18 |
| - |
| 32 | + # Step 2: Set up Node.js |
| 33 | + - name: Set up Node.js ${{ matrix.node-version }} |
| 34 | + uses: actions/setup-node@v3 |
19 | 35 | with:
|
20 |
| - version: 7 |
| 36 | + node-version: ${{ matrix.node-version }} # Use the Node.js version from the matrix |
| 37 | + cache: pnpm # Enable caching for pnpm dependencies |
21 | 38 |
|
22 |
| - - name: Use Node.js ${{ matrix.node-version }} |
23 |
| - uses: actions/setup-node@v3 |
| 39 | + # Step 3: Set up pnpm |
| 40 | + - name: Install pnpm |
| 41 | + |
24 | 42 | with:
|
25 |
| - node-version: ${{ matrix.node-version }} |
26 |
| - cache: "pnpm" |
| 43 | + version: 8.6.3 # Specify a stable pnpm version |
27 | 44 |
|
| 45 | + # Step 4: Install dependencies |
28 | 46 | - name: Install dependencies
|
29 |
| - run: pnpm install --no-frozen-lockfile |
| 47 | + run: pnpm install --frozen-lockfile # Ensure lockfile integrity |
30 | 48 |
|
31 |
| - - name: Build |
| 49 | + # Step 5: Build the project |
| 50 | + - name: Build the project |
32 | 51 | run: pnpm run build
|
33 | 52 |
|
34 |
| - # publish: |
35 |
| - # needs: build |
36 |
| - # runs-on: ubuntu-latest |
37 |
| - |
38 |
| - # steps: |
39 |
| - # - uses: actions/checkout@v2 |
40 |
| - |
41 |
| - |
42 |
| - # with: |
43 |
| - # version: 7 |
| 53 | + # Step 6: Upload build artifacts |
| 54 | + - name: Upload build artifacts |
| 55 | + uses: actions/upload-artifact@v3 |
| 56 | + with: |
| 57 | + name: dist # Artifact name |
| 58 | + path: ./dist # Directory containing the build output |
44 | 59 |
|
45 |
| - # - name: Install dependencies |
46 |
| - # run: pnpm install --no-frozen-lockfile |
| 60 | + # Publish to NPM and GitHub registries |
| 61 | + publish: |
| 62 | + name: Publish the package |
| 63 | + needs: build # Wait for the 'build' job to complete |
| 64 | + runs-on: ubuntu-latest |
47 | 65 |
|
48 |
| - # - name: Build |
49 |
| - # run: pnpm run build |
| 66 | + steps: |
| 67 | + # Step 1: Check out the repository |
| 68 | + - name: Check out code |
| 69 | + uses: actions/checkout@v3 |
50 | 70 |
|
51 |
| - # - name: Pack |
52 |
| - # run: pnpm pack |
| 71 | + # Step 2: Download build artifacts |
| 72 | + - name: Download build artifacts |
| 73 | + uses: actions/download-artifact@v3 |
| 74 | + with: |
| 75 | + name: dist # Artifact name from the 'build' job |
| 76 | + path: ./dist # Directory to place the downloaded artifacts |
53 | 77 |
|
54 |
| - # - name: Result |
55 |
| - # run: ls -al ./dist |
| 78 | + # Step 3: Set up Node.js |
| 79 | + - name: Set up Node.js |
| 80 | + uses: actions/setup-node@v3 |
| 81 | + with: |
| 82 | + node-version: 18 # Use Node.js version 18 |
| 83 | + cache: pnpm # Enable pnpm cache |
56 | 84 |
|
57 |
| - # - name: Publish to NPM |
58 |
| - # run: pnpm publish --access public --tag latest --no-git-checks |
59 |
| - # env: |
60 |
| - # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 85 | + # Step 4: Install pnpm |
| 86 | + - name: Install pnpm |
| 87 | + run: npm install -g pnpm |
61 | 88 |
|
62 |
| - # - name: Set package registry |
63 |
| - # run: pnpm config set registry https://npm.pkg.github.com |
| 89 | + # Step 5: Authenticate with npm registry |
| 90 | + - name: Authenticate with npm registry |
| 91 | + run: pnpm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }} |
64 | 92 |
|
65 |
| - # - name: Github package registry authentication |
66 |
| - # run: pnpm set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }} |
| 93 | + # Step 6: Publish to npm registry |
| 94 | + - name: Publish to npm registry |
| 95 | + run: pnpm publish --access public |
| 96 | + env: |
| 97 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
67 | 98 |
|
68 |
| - # - name: Npm registry authentication |
69 |
| - # run: pnpm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }} |
| 99 | + # Step 7: Authenticate with GitHub Package Registry |
| 100 | + - name: Authenticate with GitHub Package Registry |
| 101 | + run: pnpm set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }} |
70 | 102 |
|
71 |
| - # - name: Publish the package to Github package registry |
72 |
| - # run: pnpm publish --access public --tag latest --no-git-checks |
73 |
| - # env: |
74 |
| - # NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 103 | + # Step 8: Publish to GitHub Package Registry |
| 104 | + - name: Publish to GitHub Package Registry |
| 105 | + run: pnpm publish --access public |
75 | 106 |
|
76 |
| - publish-npm: |
77 |
| - needs: build |
78 |
| - runs-on: ubuntu-latest |
79 |
| - steps: |
80 |
| - - uses: actions/checkout@v2 |
81 |
| - - uses: actions/setup-node@v3 |
82 |
| - with: |
83 |
| - node-version: 16 |
84 |
| - - name: Install pnpm |
85 |
| - run: npm install -g pnpm |
86 |
| - - run: pnpm install |
87 |
| - - run: pnpm publish |
88 |
| - env: |
89 |
| - NODE_AUTH_TOKEN: ${{ secrets.npm_token }} |
90 |
| - - name: Set package registry |
91 |
| - run: pnpm config set registry https://npm.pkg.github.com |
92 |
| - - name: Github package registry authentication |
93 |
| - run: pnpm set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }} |
94 |
| - - name: Npm registry authentication |
95 |
| - run: pnpm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }} |
96 |
| - - name: Publish the package to Github and Npm package registries |
97 |
| - run: pnpm publish --access=public |
|
0 commit comments