diff --git a/.github/workflows/auth-react-test-1.yml b/.github/workflows/auth-react-test-1.yml index 48e4d5f1..cc0a1a46 100644 --- a/.github/workflows/auth-react-test-1.yml +++ b/.github/workflows/auth-react-test-1.yml @@ -6,9 +6,11 @@ on: - opened - reopened - synchronize + - labeled + - unlabeled push: - tags: - - dev-v[0-9]+.[0-9]+.[0-9]+ + branches: + - "[0-9]+.[0-9]+" # Only one instance of this workflow will run on the same ref (PR/Branch/Tag) # Previous runs will be cancelled. @@ -18,6 +20,7 @@ concurrency: jobs: define-versions: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') runs-on: ubuntu-latest outputs: fdiVersions: ${{ steps.versions.outputs.fdiVersions }} @@ -32,6 +35,7 @@ jobs: has-web-js: true setup-auth-react: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') runs-on: ubuntu-latest needs: define-versions strategy: @@ -118,6 +122,7 @@ jobs: artifactName: auth-react-${{ matrix.fdi-version }} launch-test-workflow: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') uses: ./.github/workflows/auth-react-test-2.yml needs: setup-auth-react name: FDI ${{ matrix.fdi-version }} diff --git a/.github/workflows/auth-react-test-2.yml b/.github/workflows/auth-react-test-2.yml index 501dd250..ff6b4b7e 100644 --- a/.github/workflows/auth-react-test-2.yml +++ b/.github/workflows/auth-react-test-2.yml @@ -44,6 +44,7 @@ on: jobs: test: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') runs-on: ubuntu-latest strategy: diff --git a/.github/workflows/check-docs.yml b/.github/workflows/check-docs.yml new file mode 100644 index 00000000..b4622058 --- /dev/null +++ b/.github/workflows/check-docs.yml @@ -0,0 +1,88 @@ +name: "Check if docs need an update" + +on: + push: + branches: + - "[0-9]+.[0-9]+" + +permissions: + contents: write + +# Only one instance of this workflow will run on the same ref (PR/Branch/Tag) +# Previous runs will be cancelled. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check-docs: + name: Check if docs need an update + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + # Need a complete fetch to make the master merge check work + fetch-depth: 0 + fetch-tags: true + token: ${{ secrets.ALL_REPO_PAT }} + + - name: Setup git + run: | + # NOTE: The user email is {user.id}+{user.login}@users.noreply.github.com. + # See users API: https://api.github.com/users/github-actions%5Bbot%5D + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git fetch origin master + + - uses: actions/setup-node@v5 + with: + node-version: 20 + + - name: Populate variables + id: versions + run: | + . ./hooks/populate-hook-constants.sh + + echo "packageVersion=$packageVersion" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" + echo "packageVersionXy=$packageVersionXy" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" + echo "packageLockVersion=$packageLockVersion" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" + echo "packageLockVersionXy=$packageLockVersionXy" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" + echo "newestVersion=$newestVersion" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" + echo "targetBranch=$targetBranch" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" + + - name: Check tag and branch correctness + run: | + if [[ "${{ steps.versions.outputs.packageVersion }}" != "${{ steps.versions.outputs.packageLockVersion }}" ]] + then + echo "The package version and package lock version do not match." + exit 1 + fi + + if [[ "refs/heads/${{ steps.versions.outputs.packageVersion }}" != ${{ github.ref }}* ]] + then + echo "Branch name and package version mismatch" + exit 1 + fi + + - name: Install dependencies + run: npm install + + - name: Build docs + run: | + npm run build-pretty + npm run build-docs + + - name: Check for changes in docs and create a commit if necessary + run: | + git update-index --really-refresh + + if git diff-index --quiet HEAD; then + # No-op, docs are updated + else + # Update docs and create a commit on the branch + git add --all + git commit -nm "doc: update docs for v${{ steps.versions.outputs.packageVersion }} tag" + git push + fi diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 00000000..381e3986 --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,130 @@ +name: Web JS Integration Tests + +on: + pull_request: + types: + - opened + - reopened + - synchronize + - labeled + - unlabeled + push: + branches: + - "[0-9]+.[0-9]+" + +# Only one instance of this workflow will run on the same ref (PR/Branch/Tag) +# Previous runs will be cancelled. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + define-versions: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') + runs-on: ubuntu-latest + outputs: + fdiVersions: ${{ steps.versions.outputs.fdiVersions }} + wjiVersions: ${{ steps.versions.outputs.webJsInterfaceVersion }} + nodeVersions: '["20"]' + nodeFdiVersionMap: ${{ steps.node-versions.outputs.fdiVersions }} + specs: ${{ steps.specs.outputs.specs }} + steps: + - uses: actions/checkout@v4 + + - uses: supertokens/get-supported-versions-action@main + id: versions + with: + has-fdi: true + has-web-js: true + + - uses: supertokens/actions/get-versions-from-repo@main + id: node-versions + with: + repo: supertokens-node + github-token: ${{ secrets.GITHUB_TOKEN }} + fdi-versions: ${{steps.versions.outputs.fdiVersions }} + + - name: Get test specs + id: specs + run: | + echo "specs=$(find 'test/integration' -name '*.test.js' -type f | sort | jq -Rsc 'split("\n")[:-1]' | jq -r 'tostring')" | tee -a "$GITHUB_OUTPUT" + + test: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') + runs-on: ubuntu-latest + needs: define-versions + + strategy: + fail-fast: false + matrix: + fdi-version: ${{ fromJSON(needs.define-versions.outputs.fdiVersions) }} + node-version: ${{ fromJson(needs.define-versions.outputs.nodeVersions) }} + spec: ${{ fromJSON(needs.define-versions.outputs.specs) }} + + env: + API_PORT: 3030 + SUPERTOKENS_CORE_PORT: 3567 + SUPERTOKENS_CORE_HOST: localhost + SUPERTOKENS_ENV: testing + TEST_MODE: testing + + steps: + - uses: actions/checkout@v4 + with: + path: supertokens-web-js + + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Get Node version from current FDI version + id: node-version + run: | + nodeVersion=$(echo '${{ needs.define-versions.outputs.nodeFdiVersionMap }}' | jq -r '.["${{ matrix.fdi-version }}"]') + echo "nodeVersion=${nodeVersion}" >> $GITHUB_OUTPUT + + - uses: actions/checkout@v4 + with: + repository: supertokens/supertokens-node + path: supertokens-node + + - uses: supertokens/get-supported-versions-action@main + id: node-cdi-versions + with: + has-cdi: true + working-directory: supertokens-node + + - uses: supertokens/actions/get-versions-from-repo@main + id: core-versions + with: + repo: supertokens-core + github-token: ${{ secrets.GITHUB_TOKEN }} + cdi-versions: ${{steps.node-cdi-versions.outputs.cdiVersions }} + + - name: Get core version from latest CDI version + id: core-version + run: | + lastCdiVersion=$(echo '${{ steps.node-cdi-versions.outputs.cdiVersions }}' | jq -r '.[-1]') + coreVersion=$(echo '${{ steps.core-versions.outputs.cdiVersions }}' | jq -r ".[\"$lastCdiVersion\"]") + echo "coreVersion=${coreVersion}" >> $GITHUB_OUTPUT + + - name: Start core + working-directory: supertokens-web-js + env: + SUPERTOKENS_CORE_VERSION: ${{ steps.core-version.outputs.coreVersion }} + run: | + docker compose up --build --wait + + - name: Setup server + working-directory: supertokens-web-js/test/server + env: + NODE_PORT: 8082 + run: | + npm i + node . & + + - name: Run tests + working-directory: supertokens-web-js + run: | + npm i + npx mocha --spec "${{ matrix.spec }}" diff --git a/.github/workflows/pipeline-release-tag.yml b/.github/workflows/pipeline-release-tag.yml index c602d09a..6eb58af5 100644 --- a/.github/workflows/pipeline-release-tag.yml +++ b/.github/workflows/pipeline-release-tag.yml @@ -44,6 +44,8 @@ jobs: - uses: actions/checkout@v4 with: ref: ${{ inputs.branch }} + # Need a complete fetch to make the master merge check work + fetch-depth: 0 fetch-tags: true token: ${{ secrets.ALL_REPO_PAT }} @@ -66,6 +68,39 @@ jobs: echo "versionFolder=$packageVersionXy.X" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" echo "artifactName=web-js-docs-$packageVersion" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" + - name: Setup git + run: | + # NOTE: The user email is {user.id}+{user.login}@users.noreply.github.com. + # See users API: https://api.github.com/users/github-actions%5Bbot%5D + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git fetch origin master + - name: Check if branch needs master merge + run: | + if [[ $(git log origin/master ^HEAD) != "" ]]; then + echo "You need to merge master into this branch." + exit 1 + fi + - name: Check tag and branch correctness + run: | + if [[ "${{ steps.versions.outputs.packageVersion }}" != "${{ steps.versions.outputs.packageLockVersion }}" ]]; + then + echo "Package version and package lock version mismatch" + exit 1 + fi + + if [[ "${{ steps.versions.outputs.packageVersion }}" != ${{ inputs.branch }}* ]] + then + echo "Adding tag to wrong branch" + exit 1 + fi + + if git rev-parse ${{ steps.versions.outputs.releaseTag }} >/dev/null 2>&1 + then + echo "The released version of this tag already exists." + exit 1 + fi + mark-as-success: runs-on: ubuntu-latest @@ -73,80 +108,14 @@ jobs: - setup steps: - - uses: actions/setup-python@v5 + - name: Check tests passed + uses: supertokens/actions/check-tests-passed@main with: - python-version: "3.13" - - - name: Install dependencies - run: | - pip install httpx - - - if: ${{ inputs.skip-test-checks == 'false' || inputs.skip-test-checks == false }} - name: Get commit status - run: | - python3 -c "$(cat << EOF - - from collections import defaultdict - import httpx - import sys - - check_runs_url = "https://api.github.com/repos/${{ github.repository }}/commits/tags/${{ needs.setup.outputs.devTag }}/check-runs?per_page=100&page={page}" - jobs_url="https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs" - - current_jobs_response = httpx.get(jobs_url).json() - current_job_ids = [job["id"] for job in current_jobs_response["jobs"]] - - page = 1 - total = 0 - - status_map = defaultdict(int) - conclusion_map = defaultdict(int) - failures = [] - - while True: - response = httpx.get(check_runs_url.format(page=page)).json() - - if len(response["check_runs"]) == 0: - break - - for run_info in response["check_runs"]: - # Release pipeline jobs also show up in check-runs - # We skip them from the checks to avoid pipeline failures - if run_info["id"] in current_job_ids: - continue - - if run_info["conclusion"] == "failure": - failures.append(run_info["html_url"]) - - status_map[run_info["status"]] += 1 - conclusion_map[run_info["conclusion"]] += 1 - total += 1 - - page += 1 - - print(f"{page=}") - print(f"{total=}") - print("Status Map =", dict(status_map)) - print("Conclusion Map =", dict(conclusion_map)) - print() - - # Possible values (from docs): - # [completed, action_required, cancelled, failure, neutral, skipped, stale, success, - # timed_out, in_progress, queued, requested, waiting, pending] - if status_map["completed"] < total: - print("Some checks not completed.") - print(failures) - sys.exit(1) - - # Possible values (from testing): - # None, success, skipped, failure - if conclusion_map.get("failure", 0) > 0: - print("Some checks not successful.") - print(failures) - sys.exit(1) - - EOF - )" + ref: ${{ inputs.branch }} + ref-type: branch + repository: ${{ github.repository }} + run_id: ${{ github.run_id }} + setup-python: true - run: | curl --fail-with-body -X PATCH \ @@ -207,20 +176,6 @@ jobs: # exit 1 # fi - - name: Check if current commit is dev-tagged - run: | - currentCommit=$(git log --format="%H" -n 1) - currentTag=`git tag -l --points-at $currentCommit` - expectedTag="${{ needs.setup.outputs.devTag }}" - - if [[ "$currentTag" != "$expectedTag" ]] - then - echo "Commit does not have the correct dev tag for this release" - echo "Current: $currentTag" - echo "Expected: $expectedTag" - exit 1 - fi - - name: Mark for release run: | curl --fail-with-body -X PATCH \ @@ -234,16 +189,11 @@ jobs: \"release\": true }" - - name: Create release tag, delete dev tag + - name: Create release tag run: | - # Add new release tag git tag ${{ needs.setup.outputs.releaseTag }} git push --tags - # Delete current dev tag - git tag --delete ${{ needs.setup.outputs.devTag }} - git push --delete origin ${{ needs.setup.outputs.devTag }} - - name: Create JSON payload run: | # Initialize an empty JSON object string diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index b9a884d1..0f70c315 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -6,9 +6,11 @@ on: - opened - reopened - synchronize + - labeled + - unlabeled push: - tags: - - dev-v[0-9]+.[0-9]+.[0-9]+ + branches: + - "[0-9]+.[0-9]+" # Only one instance of this workflow will run on the same ref (PR/Branch/Tag) # Previous runs will be cancelled. @@ -18,6 +20,7 @@ concurrency: jobs: unit-tests: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -25,4 +28,4 @@ jobs: with: node-version: 20 - run: npm install - - run: npm run test + - run: npm run test-unit diff --git a/.mocharc.yml b/.mocharc.yml index d808cadf..64b76ce9 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -1,6 +1,6 @@ exit: true -spec: - - test/unit/**/*.test.js +# spec: + # - test/unit/**/*.test.js reporter: spec require: "@babel/register" slow: 20000 diff --git a/compose.yml b/compose.yml index 9d01cf43..1a49a06a 100644 --- a/compose.yml +++ b/compose.yml @@ -1,7 +1,17 @@ services: core: # Uses `$SUPERTOKENS_CORE_VERSION` when available, else latest - image: supertokens/supertokens-core:dev-branch-${SUPERTOKENS_CORE_VERSION:-master} + image: supertokens/supertokens-dev-postgresql:${SUPERTOKENS_CORE_VERSION:-master} + entrypoint: + [ + "/usr/lib/supertokens/jre/bin/java", + "-classpath", + "/usr/lib/supertokens/core/*:/usr/lib/supertokens/plugin-interface/*:/usr/lib/supertokens/ee/*", + "io.supertokens.Main", + "/usr/lib/supertokens/", + "DEV", + "test_mode", + ] ports: # Uses `$SUPERTOKENS_CORE_PORT` when available, else 3567 for local port - ${SUPERTOKENS_CORE_PORT:-3567}:3567 @@ -12,6 +22,9 @@ services: OAUTH_PROVIDER_ADMIN_SERVICE_URL: http://oauth:4445 OAUTH_PROVIDER_CONSENT_LOGIN_BASE_URL: http://localhost:3001/auth OAUTH_CLIENT_SECRET_ENCRYPTION_KEY: asdfasdfasdfasdfasdf + INFO_LOG_PATH: "null" + ERROR_LOG_PATH: "null" + LOG_LEVEL: "DEBUG" healthcheck: test: bash -c 'curl -s "http://127.0.0.1:3567/hello" | grep "Hello"' interval: 10s