NPM Release #220
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: NPM Release | |
| on: | |
| push: | |
| branches: | |
| - main # -> prerelease published under the "next" dist-tag | |
| tags: | |
| - "v*" # -> release published under the "latest" dist-tag | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Release version to cut, e.g. 9.1.0 (creates tag v<version> and publishes 'latest'). Leave empty for a manual 'next' build." | |
| required: false | |
| default: "" | |
| env: | |
| NPM_TAG: "next" | |
| EMULATOR_NAME: "runtime-emu" | |
| NDK_VERSION: r27d | |
| ANDROID_API: 33 | |
| ANDROID_ABI: x86_64 | |
| NDK_ARCH: linux | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| outputs: | |
| npm_version: ${{ steps.npm_version_output.outputs.NPM_VERSION }} | |
| npm_tag: ${{ steps.npm_version_output.outputs.NPM_TAG }} | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| fetch-depth: 0 | |
| submodules: true | |
| - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 | |
| with: | |
| node-version: 22 | |
| registry-url: "https://registry.npmjs.org" | |
| - uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 | |
| with: | |
| distribution: "temurin" | |
| java-version: "21" | |
| cache: gradle | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@651bceb6f9ca583f16b8d75b62c36ded2ae6fc9c # v4.0.0 | |
| - name: Setup NDK | |
| run: | | |
| echo "y" | sdkmanager "cmake;3.6.4111459" | |
| wget -q https://dl.google.com/android/repository/android-ndk-$NDK_VERSION-$NDK_ARCH.zip | |
| chmod +x android-ndk-$NDK_VERSION-$NDK_ARCH.zip | |
| unzip -q android-ndk-$NDK_VERSION-$NDK_ARCH.zip | |
| rm -rf android-ndk-$NDK_VERSION-$NDK_ARCH.zip | |
| export ANDROID_NDK_HOME=`pwd`/android-ndk-$NDK_VERSION | |
| echo ANDROID_NDK_HOME=${ANDROID_NDK_HOME} >> $GITHUB_ENV | |
| echo ANDROID_NDK=${ANDROID_NDK_HOME} >> $GITHUB_ENV | |
| echo ${ANDROID_NDK_HOME} >> $GITHUB_PATH | |
| - name: Install Dependencies | |
| run: | | |
| npm install | |
| npm install --prefix ./test-app/tools | |
| - name: Get Current Version | |
| run: | | |
| NPM_VERSION=$(node -e "console.log(require('./package.json').version);") | |
| echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV | |
| - name: Set manual release version | |
| # manual dispatch with a version: cut tag v<input> and publish ('latest' | |
| # unless the version is a prerelease) | |
| if: ${{ inputs.version != '' }} | |
| env: | |
| INPUT_VERSION: ${{ inputs.version }} | |
| run: | | |
| NPM_VERSION="${INPUT_VERSION#v}" | |
| echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV | |
| npm version $NPM_VERSION --no-git-tag-version --allow-same-version | |
| - name: Bump version for dev release | |
| # branch push (main) or manual run without a version -> "next" prerelease | |
| if: ${{ !contains(github.ref, 'refs/tags/') && inputs.version == '' }} | |
| run: | | |
| NPM_VERSION=$(node ./scripts/get-next-version.js) | |
| echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV | |
| npm version $NPM_VERSION --no-git-tag-version | |
| - name: Output NPM Version and tag | |
| id: npm_version_output | |
| run: | | |
| NPM_TAG=$(node ./scripts/get-npm-tag.js) | |
| echo NPM_VERSION=$NPM_VERSION >> $GITHUB_OUTPUT | |
| echo NPM_TAG=$NPM_TAG >> $GITHUB_OUTPUT | |
| - name: Build npm package | |
| run: ./gradlew -PgitCommitVersion=${{ github.sha }} -PnoCCache --stacktrace | |
| - name: Upload npm package artifact | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: npm-package | |
| path: dist/nativescript-android-${{steps.npm_version_output.outputs.NPM_VERSION}}.tgz | |
| - name: Upload debug symbols | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: debug-symbols | |
| path: test-app/runtime/build/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib/* | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| submodules: true | |
| - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 | |
| with: | |
| node-version: 22 | |
| registry-url: "https://registry.npmjs.org" | |
| - uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 | |
| with: | |
| distribution: "temurin" | |
| java-version: "21" | |
| cache: gradle | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@651bceb6f9ca583f16b8d75b62c36ded2ae6fc9c # v4.0.0 | |
| - name: Setup NDK | |
| run: | | |
| echo "y" | sdkmanager "cmake;3.6.4111459" | |
| wget -q https://dl.google.com/android/repository/android-ndk-$NDK_VERSION-$NDK_ARCH.zip | |
| chmod +x android-ndk-$NDK_VERSION-$NDK_ARCH.zip | |
| unzip -q android-ndk-$NDK_VERSION-$NDK_ARCH.zip | |
| rm -rf android-ndk-$NDK_VERSION-$NDK_ARCH.zip | |
| export ANDROID_NDK_HOME=`pwd`/android-ndk-$NDK_VERSION | |
| echo ANDROID_NDK_HOME=${ANDROID_NDK_HOME} >> $GITHUB_ENV | |
| echo ANDROID_NDK=${ANDROID_NDK_HOME} >> $GITHUB_ENV | |
| echo ${ANDROID_NDK_HOME} >> $GITHUB_PATH | |
| - name: Install Dependencies | |
| run: | | |
| npm install | |
| npm install --prefix ./test-app/tools | |
| - name: SBG tests | |
| run: ./gradlew runSbgTests --stacktrace | |
| - name: Enable KVM | |
| run: | | |
| echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | |
| sudo udevadm control --reload-rules | |
| sudo udevadm trigger --name-match=kvm | |
| - name: Run unit tests | |
| uses: ReactiveCircus/android-emulator-runner@e89f39f1abbbd05b1113a29cf4db69e7540cae5a # v2.37.0 | |
| with: | |
| api-level: ${{env.ANDROID_API}} | |
| # this is needed on API 30+ | |
| #target: google_apis | |
| arch: ${{env.ANDROID_ABI}} | |
| script: ./gradlew runtestsAndVerifyResults --stacktrace | |
| - name: Upload Test Results | |
| if: ${{ !cancelled() }} # run this step even if previous step failed | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: android-unit-test-results | |
| path: test-app/dist/android_unit_test_results.xml | |
| publish: | |
| runs-on: ubuntu-latest | |
| environment: npm-publish | |
| needs: | |
| - build | |
| - test | |
| permissions: | |
| contents: read | |
| id-token: write | |
| env: | |
| NPM_VERSION: ${{needs.build.outputs.npm_version}} | |
| NPM_TAG: ${{needs.build.outputs.npm_tag}} | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 | |
| with: | |
| node-version: 22 | |
| registry-url: "https://registry.npmjs.org" | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: npm-package | |
| path: dist | |
| - name: Update npm (required for OIDC trusted publishing) | |
| run: | | |
| corepack enable npm | |
| corepack install -g npm@11.5.1 | |
| test "$(npm --version)" = "11.5.1" | |
| test "$(npx --version)" = "11.5.1" | |
| - name: Publish package (OIDC trusted publishing) | |
| if: ${{ vars.USE_NPM_TOKEN != 'true' }} | |
| run: | | |
| echo "Publishing @nativescript/android@$NPM_VERSION to NPM with tag $NPM_TAG via OIDC trusted publishing..." | |
| unset NODE_AUTH_TOKEN | |
| if [ -n "${NPM_CONFIG_USERCONFIG:-}" ]; then | |
| rm -f "$NPM_CONFIG_USERCONFIG" | |
| fi | |
| npm publish ./dist/nativescript-android-${{env.NPM_VERSION}}.tgz --tag $NPM_TAG --access public --provenance | |
| env: | |
| NODE_AUTH_TOKEN: "" | |
| - name: Publish package (granular token) | |
| if: ${{ vars.USE_NPM_TOKEN == 'true' }} | |
| run: | | |
| echo "Publishing @nativescript/android@$NPM_VERSION to NPM with tag $NPM_TAG via granular token..." | |
| npm publish ./dist/nativescript-android-${{env.NPM_VERSION}}.tgz --tag $NPM_TAG --access public --provenance | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} | |
| github-release: | |
| runs-on: ubuntu-latest | |
| # only runs on tagged commits, or a manual dispatch with a version (which | |
| # creates tag v<version> itself via the release action below) | |
| if: ${{ contains(github.ref, 'refs/tags/') || inputs.version != '' }} | |
| permissions: | |
| contents: write | |
| needs: | |
| - build | |
| - test | |
| env: | |
| NPM_VERSION: ${{needs.build.outputs.npm_version}} | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 | |
| with: | |
| node-version: 22 | |
| - name: Setup | |
| run: npm install | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: npm-package | |
| path: dist | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: debug-symbols | |
| path: dist/debug-symbols | |
| - name: Zip debug symbols | |
| working-directory: dist/debug-symbols | |
| run: zip -r debug-symbols.zip . | |
| - name: Partial Changelog | |
| run: npx conventional-changelog -p angular -r2 > body.md | |
| - uses: ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd # v1.21.0 | |
| with: | |
| # explicit tag + commit so a manual dispatch (no pushed tag ref) creates | |
| # tag v<version> at the dispatched commit; on tag pushes this resolves | |
| # to the pushed tag itself | |
| tag: "v${{ env.NPM_VERSION }}" | |
| name: "v${{ env.NPM_VERSION }}" | |
| commit: ${{ github.sha }} | |
| artifacts: "dist/nativescript-android-*.tgz,dist/debug-symbols/debug-symbols.zip" | |
| bodyFile: "body.md" | |
| prerelease: ${{needs.build.outputs.npm_tag != 'latest'}} | |
| allowUpdates: true |