Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,41 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v5
with:
node-version-file: '.nvmrc'

- name: '[Setup] Install dependencies'
run: npm ci

- name: '[Build] Staging'
run: npm run build:staging

- name: '[Build] Production'
run: npm run build:prod

- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'

- name: '[Deploy] Upload SDK Files to GCS'
uses: 'google-github-actions/upload-cloud-storage@v1'
with:
path: 'build/releases'
destination: 'sdk-builds-persistence-onesignal/web-sdk/${{ github.sha }}'
parent: false

- name: '[Deploy] Get SDK Version'
id: get_version
run: echo "SDK_VERSION=$(node -p "require('./package.json').config.sdkVersion")" >> $GITHUB_OUTPUT

- name: '[Deploy] Create turbine pr'
run: ./build/scripts/turbine.sh
env:
GH_TURBINE_TOKEN: ${{ secrets.GH_TURBINE_TOKEN }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_RUN_ID: ${{ github.run_id }}
SDK_VERSION: ${{ steps.get_version.outputs.SDK_VERSION }}
7 changes: 5 additions & 2 deletions __test__/support/environment/TestEnvironmentHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import MockNotification from '../mocks/MockNotification';
import TestContext from './TestContext';
import { type TestEnvironmentConfig } from './TestEnvironment';

declare const global: any;
declare const global: {
OneSignal: typeof OneSignal;
Notification: typeof Notification;
};

export function initOSGlobals(config: TestEnvironmentConfig = {}) {
global.OneSignal = OneSignal;
Expand All @@ -42,7 +45,7 @@ export function initOSGlobals(config: TestEnvironmentConfig = {}) {

export function stubNotification(config: TestEnvironmentConfig) {
global.Notification = MockNotification;
global.Notification.permission = config.permission
MockNotification.permission = config.permission
? config.permission
: global.Notification.permission;
}
Expand Down
68 changes: 68 additions & 0 deletions build/scripts/turbine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fadi-george couldn't we make this work in the GA? instead of having a standalone script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script is kind of long, I didn't want it to be all in the github acitons

set -euo pipefail

git clone "https://${GH_TURBINE_TOKEN}@github.com/OneSignal/turbine.git" turbine
cd turbine

# Configure git identity
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# Create new branch
BRANCH_NAME="web-sdk-${SDK_VERSION}-release"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, do we have a pre-defined pattern for creating release branches?
I used rel/x.x.x for Android, this will help in reusing other steps in a GA.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abdulraqeeb33 the branch is created on a different repo, turbine, we need to include web sdk in the branch name somewhere. Turbine does more than host the Web SDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was following this pattern, https://docs.google.com/document/d/1ekfGZHxYyu04Z5VcE_8vkTWJEQm2e8Ndp-hlFedFM-Q/edit?tab=t.0#heading=h.u6bz69tu00ad
but I suppose the branch could be that or rel/xxyyzz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what we can really reuse since this one goes through turbine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use rel/x.x.x in the turbine repo, it serves much more than the Web SDK. So if we change it could be something like web-sdk-rel/xxyyzz

Copy link
Contributor Author

@fadi-george fadi-george Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or can keep it as is.


# Check if PR already exists
EXISTING_PR=$(curl -s \
-H "Authorization: Bearer $GH_TURBINE_TOKEN" \
"https://api.github.com/repos/OneSignal/turbine/pulls?head=OneSignal:$BRANCH_NAME&state=open" |
jq length)

if [ "$EXISTING_PR" -gt 0 ]; then
echo "PR already exists for branch $BRANCH_NAME"
exit 0
fi

git checkout -B "$BRANCH_NAME"

# Update only USERMODEL_WEB_SDK_VERSION
sed -i "s/USERMODEL_WEB_SDK_VERSION: [a-f0-9]\{40\}/USERMODEL_WEB_SDK_VERSION: ${GITHUB_SHA}/" .circleci/config.yml

# Check if changes were made
if git diff --exit-code; then
echo "No changes to commit"
exit 0
fi

# Commit changes
RELEASE_MESSAGE="Update SDK version to ${SDK_VERSION} for web release"
JOB_MESSAGE="Job that successfully built the artifacts: https://github.com/OneSignal/OneSignal-Website-SDK/actions/runs/${GITHUB_RUN_ID}"

git add .circleci/config.yml
git commit -m "$RELEASE_MESSAGE" -m "$JOB_MESSAGE"

# Push to origin (override any existing branch)
git push --force origin "$BRANCH_NAME"

# Create pull request
PR_NUMBER=$(
curl -sS -X POST \
-H "Authorization: Bearer $GH_TURBINE_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"title\": \"$RELEASE_MESSAGE\",
\"body\": \"$JOB_MESSAGE\",
\"head\": \"$BRANCH_NAME\",
\"base\": \"main\"
}" \
https://api.github.com/repos/OneSignal/turbine/pulls |
jq -r '.number'
)

# Request team reviewers
curl -sS -X POST \
-H "Authorization: Bearer $GH_TURBINE_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"team_reviewers\": [\"eng-sdk-platform\"]
}" \
"https://api.github.com/repos/OneSignal/turbine/pulls/${PR_NUMBER}/requested_reviewers"
2 changes: 2 additions & 0 deletions src/onesignal/OneSignal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,15 @@
setTransferSubscriptionResponse();

await OneSignal.login(externalId); // should call set alias
await vi.waitUntil(() => addAliasFn.mock.calls.length === 1);
expect(addAliasFn).toHaveBeenCalledWith({
identity: {
external_id: externalId,
},
});

await OneSignal.login(newExternalId); // should call create user
await vi.waitUntil(() => createUserFn.mock.calls.length === 1);
expect(createUserFn).toHaveBeenCalledWith({
identity: {
external_id: newExternalId,
Expand Down Expand Up @@ -1201,4 +1203,4 @@
);

const showLocalNotificationSpy = vi.spyOn(MainHelper, 'showLocalNotification');
showLocalNotificationSpy.mockImplementation(async () => {});

Check failure on line 1206 in src/onesignal/OneSignal.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected empty async arrow function
6 changes: 3 additions & 3 deletions src/shared/environment/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { Browser } from '../useragent/constants';
import { getBrowserName, getBrowserVersion } from '../useragent/detect';
import { API_ORIGIN, API_TYPE, IS_SERVICE_WORKER } from '../utils/EnvVariables';

export const isBrowser = typeof window !== 'undefined';
export const isBrowser = () => typeof window !== 'undefined';

export const hasSafariWindow = () =>
isBrowser && typeof window.safari !== 'undefined';
isBrowser() && typeof window.safari !== 'undefined';

export const supportsServiceWorkers = () => {
if (IS_SERVICE_WORKER) return true;
Expand All @@ -21,7 +21,7 @@ export const supportsServiceWorkers = () => {
export const windowEnvString = IS_SERVICE_WORKER ? 'Service Worker' : 'Browser';

export const useSafariLegacyPush = () =>
isBrowser && window.safari?.pushNotification != undefined;
isBrowser() && window.safari?.pushNotification != undefined;

export const supportsVapidPush =
typeof PushSubscriptionOptions !== 'undefined' &&
Expand Down
Loading