Skip to content

Commit

Permalink
update release to cdn logic (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Nov 9, 2022
1 parent 3f18a2b commit b314449
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 53 deletions.
36 changes: 5 additions & 31 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,16 @@ steps:
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
paths: [".yarn/cache/"]

# Auto deploys branches
- label: "[Browser] Release Branch (non-prod) :rocket:"
branches: "!master !v* !publish-test"
- label: "[Browser] Release to CDN :rocket:"
branches: "!v* !@segment/* !publish-test"
agents:
queue: v1
commands:
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN}
- echo "--- Install dependencies"
- PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=0 yarn install --immutable
- echo "--- Build bundles"
- yarn run -T browser+deps build
- echo "+++ Release Branch"
- NODE_ENV=production yarn run -T browser exec bash ./scripts/release.sh
- echo "+++ Release to CDN"
- yarn run -T browser release:cdn
plugins:
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0:
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
Expand All @@ -138,7 +135,7 @@ steps:
paths: [".yarn/cache/"]

# Deploy and NPM publish releases
- label: "Release / Publish Packages :rocket:"
- label: "[Browser] Publish Packages to NPM :rocket:"
if: |
// Only run when Version Packages PR is merged in
build.message =~ /^Version Packages/ &&
Expand All @@ -160,29 +157,6 @@ steps:
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
paths: [".yarn/cache/"]

# if you are in a weird state and need to force release to cdn --
# git commit --allow-empty -m "Force Release to CDN"
- label: "Release to CDN (manual) :rocket:"
if: |
// Only run when Version Packages PR is merged in
build.message =~ /^Force Release to CDN/ &&
build.branch == "master"
agents:
queue: v1
commands:
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN}
- git config --global user.name "buildkite-agent"
- git config --global user.email "[email protected]"
- echo "--- Install dependencies"
- PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=0 yarn install --immutable
- echo "+++ Release packages"
- yarn build
- yarn run -T browser release:cdn
plugins:
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0:
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
paths: [".yarn/cache/"]

- label: "Snyk :lock:"
agents:
queue: v1
Expand Down
9 changes: 7 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Information is in the [@changesets automation instructions](https://github.com/c
### How does the changeset bot and changeset github action work?
[Check out the @changesets automation instructions](https://github.com/changesets/changesets/blob/main/docs/automating-changesets.md#automating-changesets)

### What does `yarn release` do?
- run prepare scripts
- publish all packages to npm
- pushes tags to repo
- triggers a github release on CI (via tags)
- triggers a CDN release

### I don't want to use automation, how do I manually create a release?

Expand All @@ -58,8 +64,7 @@ export GITHUB_TOKEN="???" ## changelog generator requirement (https://github.com
yarn update-versions-and-changelogs && ## bump + generate changelog + delete old changesets
git add . && # add generated artifacts
git commit -m "v1.X.X" &&
yarn release && ### run prepare scripts + publish all packages to npm
git push --follow-tags ### push generated tags to git (e.g @segment/[email protected])
yarn release
```

### Feature branches
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"postinstall": "husky install",
"changeset": "changeset",
"update-versions-and-changelogs": "changeset version && yarn version-run-all && bash scripts/update-lockfile.sh",
"release": "yarn build --force && changeset publish && yarn postpublish-run-all && git push origin --tags --no-verify",
"postpublish-run-all": "yarn workspaces foreach -vpt --no-private run postpublish",
"release": "yarn build --force && changeset publish && git push origin --tags --no-verify",
"version-run-all": "yarn workspaces foreach -vpt --no-private run version",
"core": "yarn workspace @segment/analytics-core",
"core+deps": "turbo run --filter=@segment/analytics-core...",
Expand Down
3 changes: 1 addition & 2 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"concurrently": "yarn run -T concurrently",
"watch": "yarn concurrently 'NODE_ENV=production yarn umd --watch' 'yarn pkg --watch --incremental'",
"build": "yarn clean && yarn build-prep && yarn concurrently 'NODE_ENV=production yarn umd' 'yarn pkg' 'yarn cjs'",
"release:cdn": "yarn build && NODE_ENV=production PROD_RELEASE=true bash scripts/release.sh",
"postpublish": "echo 'running postpublish build step...' && yarn release:cdn",
"release:cdn": "yarn run -T browser+deps build && NODE_ENV=production bash scripts/release.sh",
"pkg": "yarn tsc -p tsconfig.build.json",
"cjs": "yarn tsc -p tsconfig.build.json --outDir ./dist/cjs --module commonjs",
"clean": "rm -rf dist",
Expand Down
16 changes: 0 additions & 16 deletions packages/browser/scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const logUpdate = require('log-update')

const PROD_BRANCH_NAME = 'master'

const shouldReleaseToProduction = process.env.PROD_RELEASE

const bucket =
process.env.NODE_ENV == 'production'
? process.env.PROD_BUCKET
Expand Down Expand Up @@ -140,20 +138,6 @@ async function release() {
const sha = await getSha()
let branch = process.env.BUILDKITE_BRANCH || (await getBranch())

if (branch === PROD_BRANCH_NAME && !shouldReleaseToProduction) {
// guard to prevent an accidental production release
console.warn(
`Release aborted. If you want to release to ${PROD_BRANCH_NAME} branch, set PROD_RELEASE=true.`
)
return undefined
}

// this means we're deploying production
// from a release branch
if (shouldReleaseToProduction) {
branch = PROD_BRANCH_NAME
}

const meta = {
sha,
branch: `br/${branch}`,
Expand Down

0 comments on commit b314449

Please sign in to comment.