Skip to content

Commit 9f7d56c

Browse files
committed
Add CI workflow to build and publish package artifacts on PRs
1 parent 99d8dcc commit 9f7d56c

1 file changed

Lines changed: 146 additions & 0 deletions

File tree

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Package Artifacts
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
build:
13+
name: Build Packages
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Parse .tool-versions
21+
uses: wistia/parse-tool-versions@v2.1.1
22+
with:
23+
filename: '.tool-versions'
24+
uppercase: 'true'
25+
prefix: 'tool_version_'
26+
27+
- uses: pnpm/action-setup@v4
28+
with:
29+
version: '${{ env.TOOL_VERSION_PNPM }}'
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v6
33+
with:
34+
node-version: '${{ env.TOOL_VERSION_NODEJS }}'
35+
cache: pnpm
36+
37+
- name: Configure pnpm
38+
run: |
39+
pnpm config set auto-install-peers true
40+
pnpm config set exclude-links-from-lockfile true
41+
42+
- name: Sanitize branch name
43+
run: |
44+
BRANCH="${{ github.head_ref }}"
45+
echo "BRANCH_ID=$(echo "$BRANCH" | sed 's/[^0-9A-Za-z-]/-/g')" >> "$GITHUB_ENV"
46+
47+
- name: Install dependencies
48+
run: pnpm install --frozen-lockfile
49+
50+
- name: Build JS SDK
51+
working-directory: packages/js-sdk
52+
run: pnpm run build
53+
54+
- name: Pack JS SDK
55+
working-directory: packages/js-sdk
56+
run: |
57+
npm version prerelease --preid=${{ env.BRANCH_ID }} --no-git-tag-version
58+
npm pack
59+
60+
- name: Upload JS SDK artifact
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: e2b-js-sdk
64+
path: packages/js-sdk/*.tgz
65+
66+
- name: Build CLI
67+
working-directory: packages/cli
68+
run: pnpm run build
69+
70+
- name: Pack CLI
71+
working-directory: packages/cli
72+
run: |
73+
npm version prerelease --preid=${{ env.BRANCH_ID }} --no-git-tag-version
74+
npm pack
75+
76+
- name: Upload CLI artifact
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: e2b-cli
80+
path: packages/cli/*.tgz
81+
82+
- name: Set up Python
83+
uses: actions/setup-python@v4
84+
with:
85+
python-version: '${{ env.TOOL_VERSION_PYTHON }}'
86+
87+
- name: Install and configure Poetry
88+
uses: snok/install-poetry@v1
89+
with:
90+
version: '${{ env.TOOL_VERSION_POETRY }}'
91+
virtualenvs-create: true
92+
virtualenvs-in-project: true
93+
installer-parallel: true
94+
95+
- name: Build Python SDK
96+
working-directory: packages/python-sdk
97+
run: |
98+
BASE_VERSION=$(poetry version -s)
99+
poetry version "${BASE_VERSION}+${BRANCH_ID}"
100+
poetry build
101+
102+
- name: Upload Python SDK artifact
103+
uses: actions/upload-artifact@v4
104+
with:
105+
name: e2b-python-sdk
106+
path: packages/python-sdk/dist/*
107+
108+
- name: Comment on PR
109+
env:
110+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
PR_NUMBER: ${{ github.event.pull_request.number }}
112+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
113+
run: |
114+
JS_VERSION=$(node -p "require('./packages/js-sdk/package.json').version")
115+
CLI_VERSION=$(node -p "require('./packages/cli/package.json').version")
116+
JS_TGZ=$(ls packages/js-sdk/*.tgz | xargs -n1 basename)
117+
CLI_TGZ=$(ls packages/cli/*.tgz | xargs -n1 basename)
118+
PY_VERSION=$(grep '^version' packages/python-sdk/pyproject.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
119+
PY_WHL=$(ls packages/python-sdk/dist/*.whl | xargs -n1 basename)
120+
121+
BODY="<!-- e2b-pkg-artifacts -->"$'\n'
122+
BODY+="### Package Artifacts"$'\n\n'
123+
BODY+="Built from ${GITHUB_SHA::7}. Download artifacts from [this workflow run](${RUN_URL})."$'\n\n'
124+
BODY+="**JS SDK** (\`e2b@${JS_VERSION}\`):"$'\n'
125+
BODY+='```sh'$'\n'
126+
BODY+="npm install ./${JS_TGZ}"$'\n'
127+
BODY+='```'$'\n\n'
128+
BODY+="**CLI** (\`@e2b/cli@${CLI_VERSION}\`):"$'\n'
129+
BODY+='```sh'$'\n'
130+
BODY+="npm install ./${CLI_TGZ}"$'\n'
131+
BODY+='```'$'\n\n'
132+
BODY+="**Python SDK** (\`e2b==${PY_VERSION}\`):"$'\n'
133+
BODY+='```sh'$'\n'
134+
BODY+="pip install ./${PY_WHL}"$'\n'
135+
BODY+='```'$'\n'
136+
137+
COMMENT_ID=$(gh api "repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" \
138+
--jq '.[] | select(.body | contains("<!-- e2b-pkg-artifacts -->")) | .id' \
139+
| tail -1)
140+
141+
if [ -n "$COMMENT_ID" ]; then
142+
gh api "repos/${{ github.repository }}/issues/comments/${COMMENT_ID}" \
143+
-X PATCH -f body="$BODY"
144+
else
145+
gh pr comment "$PR_NUMBER" --body "$BODY"
146+
fi

0 commit comments

Comments
 (0)