Skip to content

Commit 4e4215b

Browse files
committed
test a new github workflow
1 parent c77ae8b commit 4e4215b

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,78 @@ jobs:
3737
- name: Build packages
3838
run: npm run build
3939

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

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

0 commit comments

Comments
 (0)