Skip to content

Commit

Permalink
Merge pull request getsentry#6996 from getsentry/master
Browse files Browse the repository at this point in the history
[Gitflow] MANUALLY merge master into develop
  • Loading branch information
mydea authored Jan 31, 2023
2 parents 0c641cf + a6c6b2a commit c91e1fd
Show file tree
Hide file tree
Showing 53 changed files with 1,449 additions and 162 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Build & Test'
on:
push:
branches:
- master
- develop
- release/**
pull_request:
workflow_dispatch:
Expand Down Expand Up @@ -42,11 +42,11 @@ env:

# GH will use the first restore-key it finds that matches
# So it will start by looking for one from the same branch, else take the newest one it can find elsewhere
# We want to prefer the cache from the current master branch, if we don't find any on the current branch
# We want to prefer the cache from the current develop branch, if we don't find any on the current branch
NX_CACHE_RESTORE_KEYS: |
nx-Linux-${{ github.ref }}-${{ github.event.inputs.commit || github.sha }}
nx-Linux-${{ github.ref }}
nx-Linux-refs/heads/master
nx-Linux-refs/heads/develop
nx-Linux
jobs:
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
changed_browser_integration: ${{ steps.changed.outputs.browser_integration }}
changed_any_code: ${{ steps.changed.outputs.any_code }}
# Note: These next three have to be checked as strings ('true'/'false')!
is_master: ${{ github.ref == 'refs/heads/master' }}
is_develop: ${{ github.ref == 'refs/heads/develop' }}
is_release: ${{ startsWith(github.ref, 'refs/heads/release/') }}
force_skip_cache:
${{ github.event_name == 'pull_request' && contains(steps.pr-labels.outputs.labels, ' ci-skip-cache ') }}
Expand Down Expand Up @@ -202,7 +202,7 @@ jobs:
- name: NX cache
uses: actions/cache@v3
# Disable cache when:
# - on master
# - on develop
# - on release branches
# - when PR has `ci-skip-cache` label
if: |
Expand All @@ -211,9 +211,9 @@ jobs:
with:
path: node_modules/.cache/nx
key: nx-Linux-${{ github.ref }}-${{ env.HEAD_COMMIT }}
# On master branch, we want to _store_ the cache (so it can be used by other branches), but never _restore_ from it
# On develop branch, we want to _store_ the cache (so it can be used by other branches), but never _restore_ from it
restore-keys:
${{needs.job_get_metadata.outputs.is_master == 'false' && env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}}
${{needs.job_get_metadata.outputs.is_develop == 'false' && env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}}

- name: Build packages
# Under normal circumstances, using the git SHA as a cache key, there shouldn't ever be a cache hit on the built
Expand Down Expand Up @@ -272,8 +272,7 @@ jobs:
needs: [job_get_metadata, job_build]
timeout-minutes: 15
runs-on: ubuntu-20.04
# Size Check will error out outside of the context of a PR or master branch
if: github.event_name == 'pull_request' || needs.job_get_metadata.outputs.is_master == 'true'
if: github.event_name == 'pull_request' || needs.job_get_metadata.outputs.is_develop == 'true'
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v3
Expand All @@ -283,7 +282,6 @@ jobs:
uses: actions/setup-node@v3
with:
# The size limit action runs `yarn` and `yarn build` when this job is executed on
# `master`. We can't change this without making changes to the action, so we'll
# use Node 14 for now.
node-version: '14'
- name: Check dependency cache
Expand All @@ -301,6 +299,7 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
skip_step: build
main_branch: develop

job_lint:
name: Lint
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: 'CodeQL'

on:
push:
branches: [master]
branches: [develop]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
branches: [develop]
paths-ignore:
# When _only_ changing .md files, no need to run CodeQL analysis
- '**/*.md'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/enforce-license-compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Enforce License Compliance

on:
push:
branches: [master, main, release/*]
branches: [master, develop, release/*]
pull_request:
branches: [master, main]
branches: [master, develop]

jobs:
enforce-license-compliance:
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/gitflow-sync-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Gitflow - Sync master into develop
on:
push:
branches:
- master
paths:
# When the version is updated on master (but nothing else)
- 'lerna.json'
- '!**/*.js'
- '!**/*.ts'
workflow_dispatch:

env:
DEV_BRANCH: develop

jobs:
main:
name: Create PR master->develop
runs-on: ubuntu-20.04
permissions:
pull-requests: write
contents: write
steps:
- name: git checkout
uses: actions/checkout@v3

# https://github.com/marketplace/actions/github-pull-request-action
- name: Create Pull Request
id: open-pr
uses: repo-sync/pull-request@v2
with:
destination_branch: ${{ env.DEV_BRANCH }}
pr_title: '[Gitflow] Merge ${{ github.ref_name }} into ${{ env.DEV_BRANCH }}'
pr_body: 'Merge ${{ github.ref_name }} branch into ${{ env.DEV_BRANCH }}'

# https://github.com/marketplace/actions/enable-pull-request-automerge
- name: Enable automerge for PR
if: steps.open-pr.outputs.pr_number != ''
uses: peter-evans/enable-pull-request-automerge@v2
with:
pull-request-number: ${{ steps.open-pr.outputs.pr_number }}
merge-method: merge

# https://github.com/marketplace/actions/auto-approve
- name: Auto approve PR
uses: hmarr/auto-approve-action@v3
with:
pull-request-number: ${{ steps.open-pr.outputs.pr_number }}
review-message: 'Auto approved automated PR'
# TODO: Use the token of some user here??
# github-token: ${{ secrets.SOME_USERS_PAT }}
53 changes: 53 additions & 0 deletions .github/workflows/gitflow-sync-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Gitflow - Sync develop into master
on:
push:
branches:
- develop
paths:
# We want to trigger this when ONLY the changlog is changed on develop, but nothing else
- 'CHANGELOG.md'
- '!packages'
- '!**/*.js'
- '!**/*.json'
- '!**/*.ts'
workflow_dispatch:

env:
MAIN_BRANCH: master

jobs:
main:
name: Create PR develop->master
runs-on: ubuntu-20.04
permissions:
pull-requests: write
contents: write
steps:
- name: git checkout
uses: actions/checkout@v3

# https://github.com/marketplace/actions/github-pull-request-action
- name: Create Pull Request
id: open-pr
uses: repo-sync/pull-request@v2
with:
destination_branch: ${{ env.MAIN_BRANCH }}
pr_title: '[Gitflow] Merge ${{ github.ref_name }} into ${{ env.MAIN_BRANCH }}'
pr_body: 'Merge ${{ github.ref_name }} branch into ${{ env.MAIN_BRANCH }}'

# https://github.com/marketplace/actions/enable-pull-request-automerge
- name: Enable automerge for PR
if: steps.open-pr.outputs.pr_number != ''
uses: peter-evans/enable-pull-request-automerge@v2
with:
pull-request-number: ${{ steps.open-pr.outputs.pr_number }}
merge-method: merge

# https://github.com/marketplace/actions/auto-approve
- name: Auto approve PR
uses: hmarr/auto-approve-action@v3
with:
pull-request-number: ${{ steps.open-pr.outputs.pr_number }}
review-message: 'Auto approved automated PR'
# TODO: Use the token of some user here??
# github-token: ${{ secrets.SOME_USERS_PAT }}
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
merge_target:
description: Target branch to merge into. Uses the default branch as a fallback (optional)
required: false
default: master
jobs:
release:
runs-on: ubuntu-20.04
Expand Down
23 changes: 6 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,14 @@ This means that all commits on the branch will be squashed into a single commit,
* Make sure to rebase the branch on `master` before squashing it
* Make sure to update the commit message of the squashed branch to follow the commit guidelines - including the PR number
## Publishing a Release
### Gitflow
_These steps are only relevant to Sentry employees when preparing and publishing a new SDK release._
We use [Gitflow](https://docs.github.com/en/get-started/quickstart/github-flow) as a branching model.
**If you want to release a new SDK for the first time, be sure to follow the [New SDK Release Checklist](./docs/new-sdk-release-checklist.md)**
For more details, [see our Gitflow docs](./docs/gitflow.md).
1. Determine what version will be released (we use [semver](https://semver.org)).
2. Update [`CHANGELOG.md`](https://github.com/getsentry/sentry-javascript/edit/master/CHANGELOG.md) to add an entry for the next release number and a list of changes since the last release. (See details below.)
3. Run the [Prepare Release](https://github.com/getsentry/sentry-javascript/actions/workflows/release.yml) workflow.
4. A new issue should appear in https://github.com/getsentry/publish/issues.
5. Ask a member of the [@getsentry/releases team](https://github.com/orgs/getsentry/teams/releases/members) to approve the release.
## Publishing a Release
### Updating the Changelog
_These steps are only relevant to Sentry employees when preparing and publishing a new SDK release._
1. Create a new branch.
2. Run `git log --format="- %s"` and copy everything since the last release.
3. Create a new section in the changelog, deciding based on the changes whether it should be a minor bump or a patch release.
4. Paste in the logs you copied earlier.
5. Delete any which aren't user-facing changes.
6. Alphabetize the rest.
7. If any of the PRs are from external contributors, include underneath the commits `Work in this release contributed by <list of external contributors' GitHub usernames>. Thank you for your contributions!`. If there's only one external PR, don't forget to remove the final `s`. If there are three or more, use an Oxford comma. (It's in the Sentry styleguide!)
8. Commit, push, and open a PR with the title `meta: Update changelog for <fill in relevant version here>`.
[See the docs for publishing a release](./docs/publishing-a-release.md)
Binary file added docs/assets/gitflow-chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions docs/gitflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Gitflow

We use [Gitflow](https://docs.github.com/en/get-started/quickstart/github-flow) as a branching model.

## Summary

* Ongoing work happens on the `develop` branch
* Any PRs (features, ...) are implemented as PRs against `develop`
* When we are ready to release, we merge develop into master, create a release there, then merge master back into develop
* Whatever is currently on `master` can be considered the last released state of the SDK
* Never merge directly into `master` (unless we want e.g. an emergency bugfix release)

![gitflow-chart](./assets/gitflow-chart.png)
26 changes: 26 additions & 0 deletions docs/publishing-a-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Publishing a Release

_These steps are only relevant to Sentry employees when preparing and publishing a new SDK release._

**If you want to release a new SDK for the first time, be sure to follow the [New SDK Release Checklist](./new-sdk-release-checklist.md)**

1. Determine what version will be released (we use [semver](https://semver.org)).
2. Update [`CHANGELOG.md`](https://github.com/getsentry/sentry-javascript/edit/master/CHANGELOG.md) to add an entry for the next release number and a list of changes since the last release. (See details below.)
a. Merging the Changelog PR will automatically trigger a sync from `develop` -> `master`
3. Run the [Prepare Release](https://github.com/getsentry/sentry-javascript/actions/workflows/release.yml) workflow.
a. Wait for this until the sync to `master` is completed.
4. A new issue should appear in https://github.com/getsentry/publish/issues.
5. Ask a member of the [@getsentry/releases team](https://github.com/orgs/getsentry/teams/releases/members) to approve the release.
a. Once the release is completed, a sync from `master` ->` develop` will be automatically triggered

## Updating the Changelog

1. Create a new branch.
2. Run `git log --format="- %s"` and copy everything since the last release.
3. Create a new section in the changelog, deciding based on the changes whether it should be a minor bump or a patch release.
4. Paste in the logs you copied earlier.
5. Delete any which aren't user-facing changes.
6. Alphabetize the rest.
7. If any of the PRs are from external contributors, include underneath the commits `Work in this release contributed by <list of external contributors' GitHub usernames>. Thank you for your contributions!`. If there's only one external PR, don't forget to remove the final `s`. If there are three or more, use an Oxford comma. (It's in the Sentry styleguide!)
8. Commit, push, and open a PR with the title `meta: Update changelog for <fill in relevant version here>` against `develop` branch.
7 changes: 5 additions & 2 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import type {
Severity,
SeverityLevel,
} from '@sentry/types';
import { createClientReportEnvelope, dsnToString, logger, serializeEnvelope } from '@sentry/utils';
import { createClientReportEnvelope, dsnToString, getSDKSource, logger, serializeEnvelope } from '@sentry/utils';

import { eventFromException, eventFromMessage } from './eventbuilder';
import { WINDOW } from './helpers';
import type { Breadcrumbs } from './integrations';
import { BREADCRUMB_INTEGRATION_ID } from './integrations/breadcrumbs';
import type { BrowserTransportOptions } from './transports/types';

/**
* Configuration options for the Sentry Browser SDK.
* @see @sentry/types Options for more information.
Expand All @@ -41,12 +42,14 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
* @param options Configuration options for this SDK.
*/
public constructor(options: BrowserClientOptions) {
const sdkSource = WINDOW.SENTRY_SDK_SOURCE || getSDKSource();

options._metadata = options._metadata || {};
options._metadata.sdk = options._metadata.sdk || {
name: 'sentry.javascript.browser',
packages: [
{
name: 'npm:@sentry/browser',
name: `${sdkSource}:@sentry/browser`,
version: SDK_VERSION,
},
],
Expand Down
3 changes: 3 additions & 0 deletions packages/browser/src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
_window[_onerror] = _oldOnerror;
_window[_onunhandledrejection] = _oldOnunhandledrejection;

// Add loader as SDK source
_window.SENTRY_SDK_SOURCE = 'loader';

var SDK = _window[_namespace];

var oldInit = SDK.init;
Expand Down
14 changes: 14 additions & 0 deletions packages/browser/test/integration/suites/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,19 @@ if (IS_LOADER) {
assert.equal(summary.events[0].breadcrumbs[0].message, 'testing loader');
});
});

it('should set SENTRY_SDK_SOURCE value', () => {
return runInSandbox(sandbox, function () {
Sentry.onLoad(function () {
Sentry.init({ debug: true });
});
setTimeout(function () {
Sentry.captureMessage('test');
});
undefinedMethod(); // trigger error
}).then(function (summary) {
assert.equal(summary.events[0].sdk.packages[0].name, 'loader:@sentry/browser');
});
});
});
}
22 changes: 22 additions & 0 deletions packages/browser/test/unit/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getReportDialogEndpoint, SDK_VERSION } from '@sentry/core';
import * as utils from '@sentry/utils';

import type { Event } from '../../src';
import {
Expand Down Expand Up @@ -277,6 +278,27 @@ describe('SentryBrowser initialization', () => {
expect(sdkData?.version).toBe(SDK_VERSION);
});

it('uses SDK source from window for package name', () => {
global.SENTRY_SDK_SOURCE = 'loader';
init({ dsn });

const sdkData = (getCurrentHub().getClient() as any).getOptions()._metadata.sdk;

expect(sdkData?.packages[0].name).toBe('loader:@sentry/browser');
delete global.SENTRY_SDK_SOURCE;
});

it('uses SDK source from global for package name', () => {
const spy = jest.spyOn(utils, 'getSDKSource').mockReturnValue('cdn');
init({ dsn });

const sdkData = (getCurrentHub().getClient() as any).getOptions()._metadata.sdk;

expect(sdkData?.packages[0].name).toBe('cdn:@sentry/browser');
expect(utils.getSDKSource).toBeCalledTimes(1);
spy.mockRestore();
});

it('should set SDK data when instantiating a client directly', () => {
const options = getDefaultBrowserClientOptions({ dsn });
const client = new BrowserClient(options);
Expand Down
Loading

0 comments on commit c91e1fd

Please sign in to comment.