Build and deploy #41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and deploy | |
| on: | |
| push: | |
| tags: | |
| - "v*.*.*" | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Tag version to deploy (e.g., v1.2.3)" | |
| required: true | |
| type: string | |
| workflow_call: | |
| inputs: | |
| tag: | |
| description: "Tag version to deploy" | |
| required: true | |
| type: string | |
| permissions: | |
| id-token: write | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| env: | |
| NODE_VERSION: 22 | |
| steps: | |
| - name: Сheckout repo | |
| uses: actions/checkout@v5 | |
| - name: Use Node.js ${{ env.NODE_VERSION }} | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| - name: Cache node modules | |
| uses: actions/cache@v4 | |
| env: | |
| cache-name: cache-node-modules | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-build-${{ env.cache-name }}- | |
| ${{ runner.os }}-build- | |
| ${{ runner.os }}- | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run builder | |
| run: npm run build | |
| - name: Archiving dist directory | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: ${{ github.workspace }}/dist | |
| test: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: build | |
| strategy: | |
| matrix: | |
| node-version: [20, 22] | |
| steps: | |
| - name: Сheckout repo | |
| uses: actions/checkout@v5 | |
| - name: Unarchiving dist directory | |
| uses: actions/download-artifact@v5 | |
| with: | |
| name: dist | |
| path: ${{ github.workspace }}/dist | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Cache node modules | |
| uses: actions/cache@v4 | |
| env: | |
| cache-name: cache-node-modules | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-build-${{ env.cache-name }}- | |
| ${{ runner.os }}-build- | |
| ${{ runner.os }}- | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run test | |
| run: npm run test | |
| deploy: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: [build, test] | |
| env: | |
| NODE_VERSION: 22 | |
| steps: | |
| - name: Сheckout repo | |
| uses: actions/checkout@v5 | |
| - name: Unarchiving dist directory | |
| uses: actions/download-artifact@v5 | |
| with: | |
| name: dist | |
| path: ${{ github.workspace }}/dist | |
| - name: Use Node.js ${{ env.NODE_VERSION }} | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| - name: Cache node modules | |
| uses: actions/cache@v4 | |
| env: | |
| cache-name: cache-node-modules | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-build-${{ env.cache-name }}- | |
| ${{ runner.os }}-build- | |
| ${{ runner.os }}- | |
| - name: Install modules | |
| run: npm ci | |
| - name: Set RELEASE_VERSION env | |
| run: | | |
| if [ -n "${{ inputs.tag }}" ]; then | |
| RELEASE_VERSION="${{ inputs.tag }}" | |
| else | |
| RELEASE_VERSION="${GITHUB_REF#refs/*/}" | |
| fi | |
| echo "RELEASE_VERSION=${RELEASE_VERSION#v}" >> $GITHUB_ENV | |
| - name: Create Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ env.RELEASE_VERSION }} | |
| name: v${{ env.RELEASE_VERSION }} | |
| body_path: ${{ github.workspace }}/README.md | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| draft: false | |
| prerelease: ${{ !!endsWith(env.RELEASE_VERSION, '-beta') }} | |
| - name: Set registry npm packages | |
| if: ${{ !endsWith(env.RELEASE_VERSION, '-beta') }} | |
| uses: actions/setup-node@v6 | |
| with: | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Update npm to latest version | |
| run: npm install -g npm@latest | |
| - name: Publish package to NPM | |
| if: ${{ !endsWith(env.RELEASE_VERSION, '-beta') }} | |
| run: npm publish |