Skip to content

feat: migrate tests to run on Github Actions #18

feat: migrate tests to run on Github Actions

feat: migrate tests to run on Github Actions #18

Workflow file for this run

name: "App Tests"
on:
pull_request:
types:
- opened
- reopened
- synchronize
push:
tags:
- dev-v[0-9]+.[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:
runs-on: ubuntu-latest
outputs:
fdiVersions: ${{ steps.versions.outputs.fdiVersions }}
nodeVersions: '["20"]'
steps:
- uses: actions/checkout@v4
- uses: supertokens/get-supported-versions-action@main
id: versions
with:
has-fdi: true
has-cdi: false
define-versions-node:
runs-on: ubuntu-latest
outputs:
coreVersionXy: ${{ steps.core-version.outputs.coreVersionXy }}
steps:
- uses: actions/checkout@v4
with:
repository: supertokens/supertokens-node
- uses: supertokens/get-supported-versions-action@main
id: versions
with:
has-fdi: true
has-cdi: true
- name: Get CDI version
id: cdi-version
run: |
cdiVersion=$(echo "${{ steps.versions.outputs.cdiVersions }}" | jq '. | last')
echo "cdiVersion=${cdiVersion}" >> $GITHUB_OUTPUT
- name: Get Core version
id: core-version
uses: supertokens/get-versions-action@main
with:
driver-name: node
cdi-version: ${{ steps.cdi-version.outputs.cdiVersion }}
env:
SUPERTOKENS_API_KEY: ${{ secrets.SUPERTOKENS_API_KEY }}
test:
runs-on: ubuntu-latest
needs:
- define-versions
- define-versions-node
strategy:
fail-fast: false
matrix:
node-version: ${{ fromJSON(needs.define-versions.outputs.nodeVersions) }}
fdi-version: ${{ fromJSON(needs.define-versions.outputs.fdiVersions) }}
steps:
- name: Setup ENVs
id: envs
run: |
DATA_DIR=${{ github.workspace }}/data
APP_SERVER_LOG_DIR=${{ github.workspace }}/data/logs
echo "DATA_DIR=$DATA_DIR" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV"
echo "APP_SERVER_LOG_DIR=$APP_SERVER_LOG_DIR" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV"
mkdir -p $DATA_DIR
mkdir -p $APP_SERVER_LOG_DIR
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v4
with:
path: supertokens-react-native
- uses: supertokens/get-versions-action@main
id: versions
with:
driver-name: node
fdi-version: ${{ matrix.fdi-version }}
env:
SUPERTOKENS_API_KEY: ${{ secrets.SUPERTOKENS_API_KEY }}
- name: Start core
working-directory: supertokens-react-native
run: docker compose up --wait
env:
SUPERTOKENS_CORE_VERSION: ${{ needs.define-versions-node.outputs.coreVersionXy }}
- name: Install SDK dependencies
working-directory: supertokens-react-native/TestingApp
run: |
npm i -d
cp -r ./test/tough-cookie ./node_modules/
npm i git+https://github.com:supertokens/supertokens-react-native.git#${{ github.sha }}
- name: Setup test server
working-directory: supertokens-react-native/TestingApp/test/server
env:
TEST_MODE: testing
NODE_PORT: 8080
run: |
npm i -d
npm i git+https://github.com:supertokens/supertokens-node.git#${{ steps.versions.outputs.nodeTag }}
- name: Run tests
working-directory: supertokens-react-native/TestingApp
env:
TEST_MODE: testing
NODE_PORT: 8080
JEST_JUNIT_OUTPUT_DIR: ${{ steps.envs.outputs.DATA_DIR }}
JEST_JUNIT_ADD_FILE_ATTRIBUTE: true
run: |
set +e
tries=0
max_tries=3
while true; do
tries=$((tries + 1))
echo "Running tests [Try $tries/$max_tries]"
echo "Starting server"
node test/server/index.js &> ${{ steps.envs.outputs.APP_SERVER_LOG_DIR }}/app-server-$tries.log &
server_pid=$!
echo "Running tests"
npx jest test/*.spec.js --ci --reporters=default --reporters=jest-junit --runInBand --verbose --split-by=timings
exit_code=$?
if [[ $exit_code -ne 0 && $tries -lt $max_tries ]]; then
echo -e "\n\n\n"
pkill -9 $server_pid
else
exit $exit_code
fi
done
- if: always()
name: Publish test results
uses: mikepenz/action-junit-report@v5
with:
report_paths: ${{ steps.envs.outputs.DATA_DIR }}/junit.xml
check_name: React Native Tests [FDI=${{ matrix.fdi-version }}][Node=${{ matrix.node-version }}][NodeSDK=${{ steps.versions.outputs.nodeTag }}]
# Include table with all test results in the summary
detailed_summary: true
# Skips the summary table if only successful tests were detected.
skip_success_summary: true
# Group the testcases by test suite in the detailed_summary
group_suite: true
# Don't fail if no test are found.
require_tests: false
# Fail the build in case of a test failure.
fail_on_failure: true
# No annotations will be added to the run
skip_annotations: true
- if: failure()
name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: React Native Tests [FDI=${{ matrix.fdi-version }}][Node=${{ matrix.node-version }}][NodeSDK=${{ steps.versions.outputs.nodeTag }}]
path: ${{ steps.envs.outputs.DATA_DIR }}