|
| 1 | +name: TypeScript API Client Library |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + release: |
| 7 | + types: [ published ] |
| 8 | + pull_request: |
| 9 | + branches: [ main ] |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-publish-npm-package: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + timeout-minutes: 30 |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + packages: write |
| 18 | + |
| 19 | + steps: |
| 20 | + - uses: FranzDiebold/github-env-vars-action@v2 |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + - uses: actions/setup-java@v3 |
| 23 | + with: |
| 24 | + distribution: 'temurin' |
| 25 | + java-version: '17' |
| 26 | + cache: 'gradle' |
| 27 | + - uses: actions/setup-node@v3 |
| 28 | + with: |
| 29 | + node-version: 16 |
| 30 | + cache: 'npm' |
| 31 | + registry-url: 'https://registry.npmjs.org' |
| 32 | + cache-dependency-path: ./extensions/wrapper/client-ts/package-lock.json |
| 33 | + - name: Generate openapi.yaml & Client Code |
| 34 | + run: | |
| 35 | + ./gradlew :extensions:wrapper:wrapper:clean :extensions:wrapper:wrapper:build -x test --no-daemon |
| 36 | + - name: Decide Package Version |
| 37 | + working-directory: ./extensions/wrapper/client-ts |
| 38 | + run: | |
| 39 | + # We re-use the maven module version |
| 40 | + VERSION=$(cat ../../../gradle.properties | sed -n "s/^sovityEdcExtensionsVersion=\(.*\)$/\1/p") |
| 41 | +
|
| 42 | + # We add the date in milis as "pre-release" version to ensure re-running the pipeline does not fail |
| 43 | + # due to a version already existing |
| 44 | + DATE_IN_UTC_MILIS="$(date +%s%3N)" |
| 45 | + if [[ "$VERSION" == *-SNAPSHOT ]]; then |
| 46 | + VERSION="$VERSION.$DATE_IN_UTC_MILIS" |
| 47 | + else |
| 48 | + VERSION="$VERSION-$DATE_IN_UTC_MILIS" |
| 49 | + fi |
| 50 | +
|
| 51 | + # Updates package.json |
| 52 | + npm version $VERSION |
| 53 | + - name: NPM Package Dist Tag |
| 54 | + run: | |
| 55 | + if [ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]; then |
| 56 | + # Only releases will build with the latest tag |
| 57 | + # Other tags will be ignored for default npm installs |
| 58 | + DIST_TAG=latest |
| 59 | + elif [ "$CI_REF_NAME" = "refs/heads/main" ]; then |
| 60 | + # The next tag is a common tag used for unstable versions |
| 61 | + DIST_TAG=next |
| 62 | + else |
| 63 | + # Branches and PRs will be built under special tags |
| 64 | + DIST_TAG=$CI_REF_SLUG |
| 65 | + fi |
| 66 | + echo "DIST_TAG=$DIST_TAG" >> $GITHUB_ENV |
| 67 | + - name: Build NPM Library |
| 68 | + working-directory: ./extensions/wrapper/client-ts |
| 69 | + run: | |
| 70 | + npm ci && npm run build |
| 71 | + - name: Publish NPM Library |
| 72 | + working-directory: ./extensions/wrapper/client-ts |
| 73 | + run: | |
| 74 | + npm set //registry.npmjs.org/:_authToken $NODE_AUTH_TOKEN |
| 75 | + npm set //registry.npmjs.org/:username $NODE_USER |
| 76 | + npm publish --access public --tag "${{ env.DIST_TAG }}" |
| 77 | + env: |
| 78 | + NODE_USER: richardtreier-sovity |
| 79 | + NODE_AUTH_TOKEN: ${{ secrets.SOVITY_EDC_CLIENT_NPM_AUTH }} |
0 commit comments