Skip to content

Commit fddccfd

Browse files
authored
add docker image to pkg workflow (#125)
* test a new github workflow * update workflow for PRs * exclude changeset changes from workglow * Create yellow-actors-itch.md
1 parent c77ae8b commit fddccfd

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

.changeset/yellow-actors-itch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
3+
---
4+
5+
add docker image to pkg workflow

.github/workflows/pkg-pr-new.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ permissions:
77
on:
88
pull_request:
99
types: [opened, synchronize, reopened]
10+
paths:
11+
- '!**/*.md'
12+
- '!.changeset/**'
1013

1114

1215
jobs:
@@ -37,8 +40,78 @@ jobs:
3740
- name: Build packages
3841
run: npm run build
3942

43+
- name: Set preview version
44+
id: package-version
45+
run: |
46+
PR_NUMBER=${{ github.event.pull_request.number }}
47+
GIT_HASH=$(git rev-parse --short HEAD)
48+
VERSION="0.0.0-pr-${PR_NUMBER}-${GIT_HASH}"
49+
50+
# Update package.json with the preview version
51+
node -e "
52+
const fs = require('fs');
53+
const path = './packages/sandbox/package.json';
54+
const pkg = JSON.parse(fs.readFileSync(path, 'utf8'));
55+
pkg.version = '${VERSION}';
56+
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n');
57+
"
58+
59+
echo "version=$VERSION" >> $GITHUB_OUTPUT
60+
echo "Docker image will be tagged as: cloudflare/sandbox:${VERSION}"
61+
echo "Preview version: $VERSION"
62+
4063
- name: Resolve workspace dependencies
4164
run: npx tsx .github/resolve-workspace-versions.ts
4265

66+
- name: Set up Docker Buildx
67+
uses: docker/setup-buildx-action@v3
68+
69+
- name: Login to Docker Hub
70+
uses: docker/login-action@v3
71+
with:
72+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
73+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
74+
75+
- name: Build and push Docker image (preview)
76+
run: npm run docker:publish --workspace=@cloudflare/sandbox
77+
4378
- name: Publish to pkg.pr.new
4479
run: npx pkg-pr-new publish './packages/sandbox'
80+
81+
- name: Comment Docker image tag
82+
uses: actions/github-script@v7
83+
with:
84+
script: |
85+
const version = '${{ steps.package-version.outputs.version }}';
86+
const dockerTag = `cloudflare/sandbox:${version}`;
87+
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.`;
88+
89+
// Find existing comment
90+
const { data: comments } = await github.rest.issues.listComments({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
issue_number: context.issue.number,
94+
});
95+
96+
const botComment = comments.find(comment =>
97+
comment.user.type === 'Bot' &&
98+
comment.body.includes('Docker Image Published')
99+
);
100+
101+
if (botComment) {
102+
// Update existing comment
103+
await github.rest.issues.updateComment({
104+
owner: context.repo.owner,
105+
repo: context.repo.repo,
106+
comment_id: botComment.id,
107+
body: body
108+
});
109+
} else {
110+
// Create new comment
111+
await github.rest.issues.createComment({
112+
owner: context.repo.owner,
113+
repo: context.repo.repo,
114+
issue_number: context.issue.number,
115+
body: body
116+
});
117+
}

0 commit comments

Comments
 (0)