Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/yellow-actors-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

---

add docker image to pkg workflow
73 changes: 73 additions & 0 deletions .github/workflows/pkg-pr-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ permissions:
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- '!**/*.md'
- '!.changeset/**'


jobs:
Expand Down Expand Up @@ -37,8 +40,78 @@ jobs:
- name: Build packages
run: npm run build

- name: Set preview version
id: package-version
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
GIT_HASH=$(git rev-parse --short HEAD)
VERSION="0.0.0-pr-${PR_NUMBER}-${GIT_HASH}"

# Update package.json with the preview version
node -e "
const fs = require('fs');
const path = './packages/sandbox/package.json';
const pkg = JSON.parse(fs.readFileSync(path, 'utf8'));
pkg.version = '${VERSION}';
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n');
"

echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Docker image will be tagged as: cloudflare/sandbox:${VERSION}"
echo "Preview version: $VERSION"

- name: Resolve workspace dependencies
run: npx tsx .github/resolve-workspace-versions.ts

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and push Docker image (preview)
run: npm run docker:publish --workspace=@cloudflare/sandbox

- name: Publish to pkg.pr.new
run: npx pkg-pr-new publish './packages/sandbox'

- name: Comment Docker image tag
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.package-version.outputs.version }}';
const dockerTag = `cloudflare/sandbox:${version}`;
const body = `### 🐳 Docker Image Published\n\n\`\`\`dockerfile\nFROM ${dockerTag}\n\`\`\`\n\n**Version:** \`${version}\`\n\nYou can use this Docker image with the preview package from this PR.`;

// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Docker Image Published')
);

if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
Loading