Javascript SDK tests #276
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: Javascript SDK release | |
| on: | |
| workflow_call: | |
| inputs: | |
| kestra_version: | |
| description: "Kestra version to test against" | |
| required: false | |
| type: string | |
| default: "develop" | |
| secrets: | |
| GCP_SERVICE_ACCOUNT: | |
| required: true | |
| KESTRA_EE_UNIT_TEST_LICENSE_FILE: | |
| required: true | |
| KESTRA_EE_UNIT_TEST_LICENSE_LEGACY_FILE: | |
| required: true | |
| workflow_dispatch: | |
| inputs: | |
| skip-test: | |
| description: "Skip test" | |
| required: false | |
| type: string | |
| default: "false" | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| name: Test Javascript SDK | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: ./javascript | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: "22.12" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: extract root version | |
| id: extract_version | |
| run: | | |
| # remove the .X or .x at the end of the version | |
| root_version=$(echo "${{ inputs.kestra_version }}" | sed 's/\.[xX]$//') | |
| echo "root_version=$root_version" >> $GITHUB_OUTPUT | |
| - name: Generate SDK | |
| # Generate SDK with develop version to check | |
| # for any difference with current code | |
| working-directory: . | |
| run: ./generate-sdks.sh 0.0.0-dev javascript | |
| - name: fail workflow if there is any difference after SDK generation | |
| run: | | |
| if [[ -n $(git status --porcelain) ]]; then | |
| echo "There are uncommitted changes after SDK generation. Please commit the changes." | |
| git --no-pager diff | |
| exit 1 | |
| else | |
| echo "No changes detected after SDK generation." | |
| fi | |
| - name: GCP - Auth with github service account | |
| uses: "google-github-actions/auth@v2" | |
| with: | |
| credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT }} | |
| - name: configure docker access to GCP registry for EE image | |
| run: gcloud auth configure-docker europe-west1-docker.pkg.dev | |
| - name: type check | |
| run: npm run test:typecheck | |
| - name: Select license file | |
| id: license | |
| uses: ./.github/actions/set-license-file | |
| with: | |
| kestra_version: ${{ steps.extract_version.outputs.root_version }} | |
| license_file: ${{ secrets.KESTRA_EE_UNIT_TEST_LICENSE_FILE }} | |
| license_legacy_file: ${{ secrets.KESTRA_EE_UNIT_TEST_LICENSE_LEGACY_FILE }} | |
| - name: Test with vitest | |
| if: inputs.skip-test != 'true' | |
| env: | |
| KESTRA_VERSION: ${{ steps.extract_version.outputs.root_version }} | |
| run: | | |
| echo "${{ steps.license.outputs.license }}" | base64 -d > ../test-utils/docker-setup/application-secrets.yml | |
| sh run-tests.sh $KESTRA_VERSION --no-build | |
| - name: publish test results | |
| if: inputs.skip-test != 'true' | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: coverage-report | |
| path: ./coverage | |
| publish: | |
| name: Publish to Npm | |
| runs-on: ubuntu-latest | |
| needs: test | |
| permissions: | |
| contents: read | |
| id-token: write | |
| if: | | |
| !cancelled() && ( | |
| github.ref == 'refs/heads/main' || | |
| (needs.test.result == 'success' && startsWith(github.ref, 'refs/heads/releases/')) | |
| ) | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Get OIDC Token | |
| env: | |
| AUDIENCE: "npm:registry.npmjs.org" | |
| run: | | |
| TOKEN_JSON=$(curl -s -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$AUDIENCE") | |
| ID_TOKEN=$(echo "$TOKEN_JSON" | jq -r .value) | |
| echo "$TOKEN_JSON" | |
| echo "NODE_AUTH_TOKEN=$ID_TOKEN" >> "$GITHUB_ENV" | |
| echo "$ID_TOKEN" | awk -F. '{print $2}' | base64 -d 2>/dev/null | jq -r | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: "22.18" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Compute next version | |
| id: resolveVersion | |
| run: | | |
| if [[ "${GITHUB_REF_NAME}" == releases/* || "${GITHUB_BASE_REF}" == releases/* ]]; then | |
| INPUT_VERSION=${{ inputs.kestra_version }} | |
| # strip leading "v" (npm versions are not v-prefixed) and trailing ".x"/".X" | |
| VERSION_PREFIX=$(echo "$INPUT_VERSION" | sed -e 's/^v//' -e 's/\.[xX]$//') | |
| echo "Version prefix: $VERSION_PREFIX" | |
| # list all versions and filter those that start with the current version prefix (e.g., 1.2.) | |
| # `|| true` so an empty grep does not abort the step under `bash -e` | |
| VERSIONS=$(npm view @kestra-io/kestra-sdk versions --json 2>/dev/null | jq -r '.[]' 2>/dev/null | grep "^${VERSION_PREFIX}\." || true) | |
| echo "Existing versions with prefix $VERSION_PREFIX: $VERSIONS" | |
| # get the highest patch version, default to -1 when no prior patches exist | |
| HIGHEST_PATCH=$(echo "$VERSIONS" | awk -F. '{print $NF}' | sort -nr | head -n 1) | |
| if [ -z "$HIGHEST_PATCH" ]; then | |
| HIGHEST_PATCH=-1 | |
| fi | |
| echo "Highest patch version: $HIGHEST_PATCH" | |
| # increment the patch version | |
| NEXT_PATCH=$((HIGHEST_PATCH + 1)) | |
| NEXT_VERSION="$VERSION_PREFIX.$NEXT_PATCH" | |
| echo "kestra_version=$NEXT_VERSION" >> $GITHUB_OUTPUT | |
| else | |
| HASH_SPEC=$(cat kestra-ee.yml | sha256sum | head -c 8) | |
| HASH_CODE=$(find javascript/javascript-sdk -type f | sort | xargs cat | sha256sum | head -c 8) | |
| echo "hash_spec=$HASH_SPEC" >> $GITHUB_OUTPUT | |
| echo "hash_code=$HASH_CODE" >> $GITHUB_OUTPUT | |
| echo "kestra_version=2.0.0-develop.$HASH_SPEC.$HASH_CODE" >> $GITHUB_OUTPUT | |
| fi | |
| # Trusted publishing need npm 11.+ | |
| - name: Upgrade npm | |
| run: | | |
| npm install -g npm@latest | |
| npm version | |
| - name: Check if version already published | |
| id: check | |
| run: | | |
| if npm show @kestra-io/kestra-sdk@${{ steps.resolveVersion.outputs.kestra_version }} version 2>/dev/null; then | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| echo "Version ${{ steps.resolveVersion.outputs.kestra_version }} already published — skipping." | |
| else | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Generate SDK | |
| if: steps.check.outputs.skip != 'true' | |
| working-directory: . | |
| run: ./generate-sdks.sh ${{ steps.resolveVersion.outputs.kestra_version }} | |
| javascript | |
| - name: Publish to npm with develop tag | |
| if: steps.check.outputs.skip != 'true' && github.ref == 'refs/heads/main' | |
| working-directory: ./javascript/javascript-sdk | |
| run: npm publish --tag develop --access public | |
| - name: Comment on commit with install instructions | |
| if: steps.check.outputs.skip != 'true' && github.ref == 'refs/heads/main' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh api repos/${{ github.repository }}/commits/${{ github.sha }}/comments \ | |
| -f body="$(cat <<'EOF' | |
| ### 📦 JavaScript SDK published | |
| Install this build with: | |
| ```sh | |
| npm install @kestra-io/kestra-sdk@${{ steps.resolveVersion.outputs.kestra_version }} | |
| ``` | |
| EOF | |
| )" | |
| - name: Publish to npm with latest tag | |
| if: steps.check.outputs.skip != 'true' && github.ref != 'refs/heads/main' | |
| working-directory: ./javascript/javascript-sdk | |
| run: npm publish --access public |