Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FSSDK-11073] Update GHA workflow to publish in GPR #1012

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
83 changes: 83 additions & 0 deletions .github/workflows/common-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Common Publish Steps

on:
workflow_call:
inputs:
registry-url:
required: true
type: string
node-auth-token:
required: true
type: string
browserstack-username:
required: true
type: string
browserstack-access-key:
required: true
type: string

jobs:
common-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: ${{ inputs.registry-url }}
always-auth: true
env:
NODE_AUTH_TOKEN: ${{ inputs.node-auth-token }}

- name: Install dependencies
run: npm install

- id: latest-release
name: Export latest release git tag
run: |
echo "latest-release-tag=$(curl -qsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest" \
| jq -r .tag_name)" >> $GITHUB_OUTPUT

- id: npm-tag
name: Determine NPM tag
env:
GITHUB_RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
VERSION=$(jq -r '.version' package.json)
LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}"

if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
RELEASE_TAG=${GITHUB_REF#refs/tags/}
else
RELEASE_TAG=$GITHUB_RELEASE_TAG
fi

if [[ $RELEASE_TAG == $LATEST_RELEASE_TAG ]]; then
echo "npm-tag=latest" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-beta"* ]]; then
echo "npm-tag=beta" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-alpha"* ]]; then
echo "npm-tag=alpha" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-rc"* ]]; then
echo "npm-tag=rc" >> "$GITHUB_OUTPUT"
else
echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT"
fi

- id: release
name: Test, build and publish
env:
BROWSERSTACK_USERNAME: ${{ inputs.browserstack-username }}
BROWSERSTACK_ACCESS_KEY: ${{ inputs.browserstack-access-key }}
NODE_AUTH_TOKEN: ${{ inputs.node-auth-token }}
run: |
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
DRY_RUN="--dry-run"
fi
npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} --registry=${{ inputs.registry-url }} $DRY_RUN
92 changes: 18 additions & 74 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,81 +1,25 @@
name: Publish SDK to NPM
name: Publish SDK to NPM and GPR

on:
release:
types: [published, edited]
types: [published]
workflow_dispatch: {}

jobs:
publish:
publish_to_npm:
name: Publish to NPM
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.draft }}
steps:
- name: Checkout branch
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: "https://registry.npmjs.org/"
always-auth: "true"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

- name: Install dependencies
run: npm install

- id: latest-release
name: Export latest release git tag
run: |
echo "latest-release-tag=$(curl -qsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest" \
| jq -r .tag_name)" >> $GITHUB_OUTPUT

- id: npm-tag
name: Determine NPM tag
env:
GITHUB_RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
VERSION=$(jq -r '.version' package.json)
LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}"

if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
RELEASE_TAG=${GITHUB_REF#refs/tags/}
else
RELEASE_TAG=$GITHUB_RELEASE_TAG
fi

if [[ $RELEASE_TAG == $LATEST_RELEASE_TAG ]]; then
echo "npm-tag=latest" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-beta"* ]]; then
echo "npm-tag=beta" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-alpha"* ]]; then
echo "npm-tag=alpha" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-rc"* ]]; then
echo "npm-tag=rc" >> "$GITHUB_OUTPUT"
else
echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT"
fi

- id: release
name: Test, build and publish to npm
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
run: |
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
DRY_RUN="--dry-run"
fi
npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} $DRY_RUN

# - name: Report results to Jellyfish
# uses: optimizely/jellyfish-deployment-reporter-action@main
# if: ${{ always() && github.event_name == 'release' && (steps.release.outcome == 'success' || steps.release.outcome == 'failure') }}
# with:
# jellyfish_api_token: ${{ secrets.JELLYFISH_API_TOKEN }}
# is_successful: ${{ steps.release.outcome == 'success' }}
uses: ./.github/workflows/common-publish.yml
with:
registry-url: 'https://registry.npmjs.org/'
node-auth-token: ${{ secrets.NPM_PUBLISH_TOKEN }}
browserstack-username: ${{ secrets.BROWSERSTACK_USERNAME }}
browserstack-access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}

publish_to_gpr:
name: Publish to GitHub Package Registry
uses: ./.github/workflows/common-publish.yml
with:
registry-url: 'https://npm.pkg.github.com/'
node-auth-token: ${{ secrets.GITHUB_TOKEN }}
browserstack-username: ${{ secrets.BROWSERSTACK_USERNAME }}
browserstack-access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}

Unchanged files with check annotations Beta

isQualifiedFor: segment => segments ? segments.indexOf(segment) > -1 : false,
qualifiedSegments: segments || [],
getUserId: () => 'mockUserId',
setAttribute: (key: string, value: any) => {},

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

'key' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

'value' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

'key' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

'value' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

'key' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

'value' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

'key' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

'value' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (16)

'key' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (16)

'value' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type
decide: (key: string, options?: OptimizelyDecideOption[]): OptimizelyDecision => ({

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

'key' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

'options' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

'key' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

'options' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

'key' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

'options' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

'key' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

'options' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (16)

'key' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (16)

'options' is defined but never used
variationKey: 'mockVariationKey',
enabled: true,
variables: { mockVariable: 'mockValue' },
});
it('calls customAttributeConditionEvaluator.evaluate in the leaf evaluator for audience conditions', () => {
vi.spyOn(conditionTreeEvaluator, 'evaluate').mockImplementation((conditions: any, leafEvaluator) => {

Check warning on line 253 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 253 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type

Check warning on line 253 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 253 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 253 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type
return leafEvaluator(conditions[1]);
});
});
it('logs correctly when conditionTreeEvaluator.evaluate returns null', () => {
vi.spyOn(conditionTreeEvaluator, 'evaluate').mockImplementationOnce((conditions: any, leafEvaluator) => {

Check warning on line 295 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 295 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type

Check warning on line 295 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 295 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 295 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type
return leafEvaluator(conditions[1]);
});
});
it('logs correctly when conditionTreeEvaluator.evaluate returns true', () => {
vi.spyOn(conditionTreeEvaluator, 'evaluate').mockImplementationOnce((conditions: any, leafEvaluator) => {

Check warning on line 322 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 322 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type

Check warning on line 322 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 322 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 322 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type
return leafEvaluator(conditions[1]);
});
});
it('logs correctly when conditionTreeEvaluator.evaluate returns false', () => {
vi.spyOn(conditionTreeEvaluator, 'evaluate').mockImplementationOnce((conditions: any, leafEvaluator) => {

Check warning on line 348 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 348 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type

Check warning on line 348 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 348 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 348 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type
return leafEvaluator(conditions[1]);
});
};
audienceEvaluator = createAudienceEvaluator({
special_condition_type: {
evaluate: (condition: any, user: any) => {

Check warning on line 384 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 384 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type

Check warning on line 384 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 384 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 384 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const result = mockEnvironment[condition.value] && user.getAttributes()[condition.match] > 0;