Skip to content

fix(json-viewer): makeIdUniqueのfalsy判定バグを修正 (v30) #70

fix(json-viewer): makeIdUniqueのfalsy判定バグを修正 (v30)

fix(json-viewer): makeIdUniqueのfalsy判定バグを修正 (v30) #70

Workflow file for this run

name: PR Build and Artifact
on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
permissions:
contents: write
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Build bookmarklets
run: node build.js
- name: Commit built index.html to PR branch
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add index.html
if git diff --staged --quiet; then
echo "::notice::No changes to index.html to commit"
else
git commit -m "chore: rebuild index.html [skip ci]"
git push
fi
- name: Comment PR with artifact info
uses: actions/github-script@v7
with:
script: |
const branch = context.payload.pull_request.head.ref;
const repo = context.repo.repo;
const owner = context.repo.owner;
const isFork = context.payload.pull_request.head.repo.full_name !== context.payload.repository.full_name;
// Generate htmlpreview.github.io link for index.html
const previewUrl = `https://htmlpreview.github.io/?https://github.com/${owner}/${repo}/blob/${branch}/index.html`;
let message = `## 🎉 Build Successful!\n`;
if (!isFork) {
// For non-fork PRs, wait for the build to be processed
// Try to verify the file is accessible before posting the link
const MAX_RETRIES = 3;
const RETRY_DELAY_MS = 3000;
let retries = 0;
let fileExists = false;
while (retries < MAX_RETRIES && !fileExists) {
try {
await github.rest.repos.getContent({
owner: context.payload.pull_request.head.repo.owner.login,
repo: context.payload.pull_request.head.repo.name,
path: 'index.html',
ref: branch
});
fileExists = true;
console.log('✓ index.html is accessible');
} catch (error) {
retries++;
if (retries < MAX_RETRIES) {
console.log(`Waiting for index.html to be accessible (attempt ${retries}/${MAX_RETRIES})...`);
await new Promise(resolve => setTimeout(resolve, RETRY_DELAY_MS));
} else {
console.log('⚠️ Could not verify index.html accessibility, posting link anyway');
}
}
}
message += `
### 🔗 **即座に動作確認**
以下のリンクから、ダウンロード不要でブックマークレットを確認できます:
**👉 [PR Preview を開く](${previewUrl})**
このページでブックマークレットをブックマークバーにドラッグ&ドロップして、すぐに動作確認できます。
`;
} else {
message += `
### ℹ️ Fork からの PR のため、プレビューは利用できません
セキュリティ上の理由から、Fork からの PR では自動プレビューが無効になっています。
動作確認する場合は、ローカルで以下のコマンドを実行してください:
\`\`\`bash
node build.js
\`\`\`
生成された \`index.html\` をブラウザで開いて確認できます。
`;
}
const identifier = '<!-- pr-build-artifact-comment -->';
const messageWithIdentifier = identifier + '\n' + message;
// Check if a comment already exists
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.data.find(comment =>
comment.body.includes(identifier)
);
if (existingComment) {
// Delete existing comment so a new one triggers a fresh notification
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
});
}
// Always create a new comment so subscribers receive a notification
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: messageWithIdentifier
});