|
| 1 | +# This workflow will build and test the TypeScript library |
| 2 | +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs |
| 3 | + |
| 4 | +name: TypeScript |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: # Manual trigger |
| 8 | + push: |
| 9 | + branches: [ "main" ] |
| 10 | + pull_request: |
| 11 | + branches: [ "main" ] |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + - name: Get version from git tag |
| 23 | + id: version |
| 24 | + run: | |
| 25 | + VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.1-preview") |
| 26 | + VERSION=${VERSION#v} |
| 27 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 28 | + - name: Setup Node.js |
| 29 | + uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + node-version: '20' |
| 32 | + cache: 'npm' |
| 33 | + cache-dependency-path: src/Typescript/package-lock.json |
| 34 | + - name: Install dependencies |
| 35 | + run: npm ci |
| 36 | + working-directory: src/Typescript |
| 37 | + - name: Set package version |
| 38 | + run: npm version ${{ steps.version.outputs.version }} --no-git-tag-version --allow-same-version |
| 39 | + working-directory: src/Typescript |
| 40 | + - name: Build |
| 41 | + run: npm run build |
| 42 | + working-directory: src/Typescript |
| 43 | + - name: Test |
| 44 | + run: npm test |
| 45 | + working-directory: src/Typescript |
| 46 | + - name: Pack npm package |
| 47 | + run: npm pack |
| 48 | + working-directory: src/Typescript |
| 49 | + - name: Upload npm package |
| 50 | + uses: actions/upload-artifact@v4 |
| 51 | + with: |
| 52 | + name: npm-package |
| 53 | + path: src/Typescript/*.tgz |
| 54 | + |
| 55 | + deploy: |
| 56 | + runs-on: ubuntu-latest |
| 57 | + needs: build |
| 58 | + if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' |
| 59 | + environment: npm-production |
| 60 | + |
| 61 | + steps: |
| 62 | + - name: Download npm package |
| 63 | + uses: actions/download-artifact@v4 |
| 64 | + with: |
| 65 | + name: npm-package |
| 66 | + path: ./package |
| 67 | + - name: Setup Node.js |
| 68 | + uses: actions/setup-node@v4 |
| 69 | + with: |
| 70 | + node-version: '20' |
| 71 | + registry-url: 'https://registry.npmjs.org' |
| 72 | + - name: Publish to npm |
| 73 | + run: npm publish ./package/*.tgz --access public |
| 74 | + env: |
| 75 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments