Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
ci: guard production releases to main, harden the itinerary step (#1662)
Mish Ushakov034c503f1fd5
diff --git a/.github/scripts/build_release_itinerary.cjs b/.github/scripts/build_release_itinerary.cjsnew file mode 100644index 000000000..5cad14ebc--- /dev/null+++ b/.github/scripts/build_release_itinerary.cjs@@ -0,0 +1,36 @@+#!/usr/bin/env node++// This script formats the JSON written by `changeset status --output=<file>`+// as the package list that goes into the release's Slack notifications.++const path = require('path')++// Packages are listed in this order; anything not named here still shows up,+// under its workspace name, after the ones that are.+const labels = {+ e2b: 'JS SDK (e2b)',+ '@e2b/python-sdk': 'Python SDK (e2b)',+ '@e2b/cli': 'CLI (@e2b/cli)',+}++const statusFile = process.argv[2]+if (!statusFile) {+ console.error('Usage: build_release_itinerary.cjs <changeset-status.json>')+ process.exit(1)+}++const order = Object.keys(labels)+const rank = (release) => {+ const index = order.indexOf(release.name)+ return index === -1 ? order.length : index+}++const { releases } = require(path.resolve(statusFile))+const lines = [...releases]+ .sort((a, b) => rank(a) - rank(b))+ .map(+ (release) =>+ `• ${labels[release.name] ?? release.name} v${release.newVersion}`+ )++process.stdout.write(lines.join('\n') || '• No packages were published')diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex f824976c6..08f92f9aa 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -21,6 +21,18 @@ jobs:cli: ${{ steps.cli.outputs.release }}itinerary: ${{ steps.itinerary.outputs.itinerary }}steps:+ - name: Check the ref+ # `workflow_dispatch` offers every branch in the picker, and a feature+ # branch carrying changesets would otherwise publish real packages and+ # push the version bump to that branch. Candidates cut from a branch go+ # through release-candidate.yml.+ if: github.ref != 'refs/heads/main'+ env:+ REF: ${{ github.ref }}+ run: |+ echo "::error::Releases must run on main; this run is on ${REF}."+ exit 1+- name: Checkout Repouses: actions/checkout@a37ce9120846195fa4ece8f58b268e6043cb2f26 # v3.7.0@@ -83,16 +95,12 @@ jobs:- name: Build release itineraryid: itineraryif: steps.version.outputs.release == 'true'+ # This only feeds the Slack notifications, so it must never be the thing+ # that blocks a release; the messages fall back to a placeholder.+ continue-on-error: truerun: |pnpm changeset status --output=.cs-status.json- ITINERARY=$(node -e '- const data = require("./.cs-status.json");- const labels = { "e2b": "JS SDK (e2b)", "@e2b/python-sdk": "Python SDK (e2b)", "@e2b/cli": "CLI (@e2b/cli)" };- const order = ["e2b", "@e2b/python-sdk", "@e2b/cli"];- const byName = Object.fromEntries(data.releases.map(r => [r.name, r]));- const lines = order.filter(n => byName[n]).map(n => `• ${labels[n]} v${byName[n].newVersion}`);- process.stdout.write(lines.join("\n") || "• No packages were published");- ')+ ITINERARY=$(node ./.github/scripts/build_release_itinerary.cjs .cs-status.json)rm -f .cs-status.json{echo "itinerary<<EOF"@@ -142,13 +150,15 @@ jobs::rocket: A new release has been triggered :hourglass_flowing_sand:*Releasing:*- ${{ needs.preflight.outputs.itinerary }}+ ${{ needs.preflight.outputs.itinerary || '• (itinerary unavailable)' }}SLACK_TITLE: Release StartedSLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}SLACK_CHANNEL: 'monitoring-releases'report-failure:- needs: [python-tests, js-tests, cli-tests, publish]+ # `preflight` included so a failure there is reported too, whether or not+ # `failure()` looks past this job's direct dependencies.+ needs: [preflight, python-tests, js-tests, cli-tests, publish]if: failure()name: Release Failed - Slack Notificationruns-on: ubuntu-latest@@ -176,7 +186,7 @@ jobs::tada: A new version has been released successfully! :ship-it-parrot:*Released:*- ${{ needs.preflight.outputs.itinerary }}+ ${{ needs.preflight.outputs.itinerary || '• (itinerary unavailable)' }}SLACK_TITLE: Release SucceededSLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}SLACK_CHANNEL: 'monitoring-releases'