From 16ee3ffa74232993fac5e89d92c1d55baeefdfac Mon Sep 17 00:00:00 2001 From: namidapoo <83203852+ve1997@users.noreply.github.com> Date: Thu, 26 Dec 2024 08:59:45 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=90=84=E7=A8=AE=E3=83=AF=E3=83=BC?= =?UTF-8?q?=E3=82=AF=E3=83=95=E3=83=AD=E3=83=BC=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/approve-me.yml | 22 +++ .github/workflows/auto-assign.yml | 25 ++++ .github/workflows/conflict-finder.yml | 13 ++ .../workflows/deploy-info-comment-on-pr.yml | 137 ++++++++++++++++++ .github/workflows/deploy-to-cloudflare.yml | 104 +++++++++++++ .github/workflows/extact-todos-from-diff.yml | 40 +++++ 6 files changed, 341 insertions(+) create mode 100644 .github/workflows/approve-me.yml create mode 100644 .github/workflows/auto-assign.yml create mode 100644 .github/workflows/conflict-finder.yml create mode 100644 .github/workflows/deploy-info-comment-on-pr.yml create mode 100644 .github/workflows/deploy-to-cloudflare.yml create mode 100644 .github/workflows/extact-todos-from-diff.yml diff --git a/.github/workflows/approve-me.yml b/.github/workflows/approve-me.yml new file mode 100644 index 0000000..6d93421 --- /dev/null +++ b/.github/workflows/approve-me.yml @@ -0,0 +1,22 @@ +name: Approve Me + +on: + issue_comment: + types: [created, edited] + +jobs: + approve: + name: Approve + if: | + github.event.issue.state == 'open' && + github.event.issue.pull_request != null && + contains(github.event.comment.body, '@github-actions approve me') && + (github.event.action != 'edited' || (github.event.action == 'edited' && !contains(github.event.changes.body.from, '@github-actions approve me'))) + runs-on: ubuntu-latest + steps: + - name: Approve pull request + env: + GH_REPO: ${{ github.repository }} + GH_TOKEN: ${{ github.token }} + run: | + gh pr review ${{ github.event.issue.number }} --approve diff --git a/.github/workflows/auto-assign.yml b/.github/workflows/auto-assign.yml new file mode 100644 index 0000000..0723410 --- /dev/null +++ b/.github/workflows/auto-assign.yml @@ -0,0 +1,25 @@ +name: Auto Assign PR + +on: + pull_request: + types: [opened, unassigned] + +permissions: + pull-requests: write + repository-projects: read + +jobs: + assign: + name: PR automation + timeout-minutes: 1 + if: ${{ ! contains(fromJson('["renovate[bot]", "dependabot[bot]"]'), github.actor) }} + runs-on: ubuntu-22.04 + # コミットが重なった時同時に実行されないように、進行中のジョブをキャンセルするように設定する。 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + steps: + - name: Set GitHub assignees + env: + GH_TOKEN: ${{ github.token }} + run: gh pr edit ${{ github.event.number }} --add-assignee ${{ github.actor }} --repo ${{ github.repository }} diff --git a/.github/workflows/conflict-finder.yml b/.github/workflows/conflict-finder.yml new file mode 100644 index 0000000..0210626 --- /dev/null +++ b/.github/workflows/conflict-finder.yml @@ -0,0 +1,13 @@ +name: "conflict-finder" +on: + push: +jobs: + triage: + runs-on: ubuntu-latest + steps: + - uses: hcancelik/pr-conflict-finder@v1.0.6 + with: + secret_token: ${{ secrets.GITHUB_TOKEN }} + conflict_label: "conflict" + max_tries: 5 + wait_ms: 5000 diff --git a/.github/workflows/deploy-info-comment-on-pr.yml b/.github/workflows/deploy-info-comment-on-pr.yml new file mode 100644 index 0000000..fc31e2d --- /dev/null +++ b/.github/workflows/deploy-info-comment-on-pr.yml @@ -0,0 +1,137 @@ +name: Deployment Info Comment on PR + +on: + pull_request: + types: [opened] + +jobs: + comment_on_pr: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ github.token }} + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + + - name: Wait for 3 seconds + run: sleep 3 + + - name: Check if Deploy Workflow is Running + id: check_deploy + run: | + runs=$(gh run list --branch ${{ github.head_ref }} --workflow "Deploy to Cloudflare Pages" --json status --jq '.[] | select(.status == "in_progress")') + if [[ -n "$runs" ]]; then + echo "Deploy workflow is currently running. Exiting." + echo "DEPLOY_STATUS=running" >> $GITHUB_ENV + exit 0 + else + echo "DEPLOY_STATUS=completed" >> $GITHUB_ENV + fi + + - name: Add to Job Summaries if Deployment Running + if: env.DEPLOY_STATUS == 'running' + run: echo "✅ This workflow ended without executing anything because the deployment workflow was running." >> "$GITHUB_STEP_SUMMARY" + + - name: Get Latest Commit Hash + if: env.DEPLOY_STATUS == 'completed' + id: get_commit + run: | + COMMIT_HASH=$(gh pr view ${{ github.event.pull_request.number }} --json commits -q ".commits[-1].oid") + echo "COMMIT_HASH=${COMMIT_HASH}" >> $GITHUB_ENV + SHORT_COMMIT_HASH=${COMMIT_HASH:0:7} + echo "SHORT_COMMIT_HASH=${SHORT_COMMIT_HASH}" >> $GITHUB_ENV + + - name: Output Latest Commit Hash + if: env.DEPLOY_STATUS == 'completed' + run: echo "Latest Commit Hash ... ${{ env.COMMIT_HASH }}" + + - name: Fetch latest deployment info and match with commit hash + if: env.DEPLOY_STATUS == 'completed' + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_PROJECT_NAME: ${{ secrets.CLOUDFLARE_PROJECT_NAME }} + run: | + response=$(curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/$CLOUDFLARE_PROJECT_NAME/deployments" \ + -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ + -H "Content-Type: application/json") + + matching_deployment=$(echo "$response" | jq -r --arg commit "${{ env.COMMIT_HASH }}" '.result[] | select(.deployment_trigger.metadata.commit_hash == $commit)') + + if [ -z "$matching_deployment" ]; then + echo "No deployment found for the latest commit hash." + exit 1 + fi + + deployment_url=$(echo "$matching_deployment" | jq -r '.url') + deployment_alias_url=$(echo "$matching_deployment" | jq -r '.aliases[0]') + pages_deployment_id=$(echo "$matching_deployment" | jq -r '.id') + + echo "Matched Deploy URL: $deployment_url" + echo "Deploy Alias URL: $deployment_alias_url" + echo "Deploy ID: $pages_deployment_id" + + echo "LATEST_DEPLOY_URL=$deployment_url" >> $GITHUB_ENV + echo "DEPLOY_ALIAS_URL=$deployment_alias_url" >> $GITHUB_ENV + echo "DEPLOY_ID=$pages_deployment_id" >> $GITHUB_ENV + + - name: Create Comment Content + if: env.DEPLOY_STATUS == 'completed' + run: | + { + echo "GH_SAMPLE_COMMENT<" + echo "## Deploying ${{ secrets.CLOUDFLARE_PROJECT_NAME }} with  Cloudflare Pages  Cloudflare Pages" + echo "" + echo "" + echo "" + echo "" + echo "" + echo "
Latest commit: " + echo "${{ env.SHORT_COMMIT_HASH }}" + echo "
Status: ✅  Deploy successful!
Preview URL:" + echo "${{ env.LATEST_DEPLOY_URL }}" + echo "
Branch Preview URL:" + echo "${{ env.DEPLOY_ALIAS_URL }}" + echo "
" + echo "" + echo "[View logs](https://dash.cloudflare.com/?to=/:account/pages/view/${{ secrets.CLOUDFLARE_PROJECT_NAME }}/${{ env.DEPLOY_ID }})" + echo "EOF" + } >> "$GITHUB_ENV" + + - name: Add or Update Comment on Pull Request + if: env.DEPLOY_STATUS == 'completed' + run: | + PR_NUMBER=${{ github.event.pull_request.number }} + + # Fetch existing comments + COMMENTS=$(gh api repos/${{ github.repository }}/issues/${PR_NUMBER}/comments --jq '.[] | @base64') + + COMMENT_ID="" + + for COMMENT in $COMMENTS; do + COMMENT_JSON=$(echo $COMMENT | base64 --decode) + BODY=$(echo $COMMENT_JSON | jq -r '.body') + ID=$(echo $COMMENT_JSON | jq -r '.id') + + if echo "$BODY" | grep -q ''; then + COMMENT_ID=$ID + break + fi + done + + if [ -n "$COMMENT_ID" ]; then + echo "Updating existing comment ID: $COMMENT_ID" + gh api \ + --method PATCH \ + -H "Accept: application/vnd.github.v3+json" \ + /repos/${{ github.repository }}/issues/comments/$COMMENT_ID \ + -f body="${{ env.GH_SAMPLE_COMMENT }}" + else + echo "Creating new comment" + gh pr comment $PR_NUMBER --body "${{ env.GH_SAMPLE_COMMENT }}" + fi + + - name: Add to Job Summaries + if: env.DEPLOY_STATUS == 'completed' + run: echo "${{ env.GH_SAMPLE_COMMENT }}" >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/deploy-to-cloudflare.yml b/.github/workflows/deploy-to-cloudflare.yml new file mode 100644 index 0000000..00cc446 --- /dev/null +++ b/.github/workflows/deploy-to-cloudflare.yml @@ -0,0 +1,104 @@ +name: Deploy to Cloudflare Pages + +on: + push: + branches: + - "**" + +jobs: + deploy: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ github.token }} + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Get Latest Commit Hash + id: get_commit + run: echo "COMMIT_HASH=$(git rev-parse --short=7 HEAD)" >> $GITHUB_ENV + + - name: Setup Bun Environment + uses: oven-sh/setup-bun@v2.0.1 + + - name: Install Project Dependencies + run: bun i + + - name: Build Project with Bun + run: bunx @cloudflare/next-on-pages + + - name: Deploy to Cloudflare Pages with Wrangler + id: deploy + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: pages deploy .vercel/output/static --project-name=${{ secrets.CLOUDFLARE_PROJECT_NAME }} + + - name: Create Comment Content + run: | + { + echo "GH_SAMPLE_COMMENT<" + echo "## Deploying ${{ secrets.CLOUDFLARE_PROJECT_NAME }} with  Cloudflare Pages  Cloudflare Pages" + echo "" + echo "" + echo "" + echo "" + echo "" + echo "
Latest commit: " + echo "${{ env.COMMIT_HASH }}" + echo "
Status: ✅  Deploy successful!
Preview URL:" + echo "${{ steps.deploy.outputs.deployment-url }}" + echo "
Branch Preview URL:" + echo "${{ steps.deploy.outputs.deployment-alias-url }}" + echo "
" + echo "" + echo "[View logs](https://dash.cloudflare.com/?to=/:account/pages/view/${{ secrets.CLOUDFLARE_PROJECT_NAME }}/${{ steps.deploy.outputs.pages-deployment-id }})" + echo "EOF" + } >> "$GITHUB_ENV" + + - name: Check if PR exists + id: check_pr + run: | + if gh pr list --head "${{ github.ref_name }}" --json number --jq '. | length' | grep -q '1'; then + echo "PR_EXISTS=true" >> $GITHUB_ENV + else + echo "PR_EXISTS=false" >> $GITHUB_ENV + fi + + - name: Add or Update Comment on Pull Request + if: env.PR_EXISTS == 'true' + run: | + PR_NUMBER=$(gh pr list --head "${{ github.ref_name }}" --json number -q '.[0].number') + + # Fetch existing comments + COMMENTS=$(gh api repos/${{ github.repository }}/issues/${PR_NUMBER}/comments --jq '.[] | @base64') + + COMMENT_ID="" + + for COMMENT in $COMMENTS; do + COMMENT_JSON=$(echo $COMMENT | base64 --decode) + BODY=$(echo $COMMENT_JSON | jq -r '.body') + ID=$(echo $COMMENT_JSON | jq -r '.id') + + if echo "$BODY" | grep -q ''; then + COMMENT_ID=$ID + break + fi + done + + if [ -n "$COMMENT_ID" ]; then + echo "Updating existing comment ID: $COMMENT_ID" + gh api \ + --method PATCH \ + -H "Accept: application/vnd.github.v3+json" \ + /repos/${{ github.repository }}/issues/comments/$COMMENT_ID \ + -f body="${{ env.GH_SAMPLE_COMMENT }}" + else + echo "Creating new comment" + gh pr comment $PR_NUMBER --body "${{ env.GH_SAMPLE_COMMENT }}" + fi + + - name: Add to Job Summaries + run: echo "${{ env.GH_SAMPLE_COMMENT }}" >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/extact-todos-from-diff.yml b/.github/workflows/extact-todos-from-diff.yml new file mode 100644 index 0000000..fa35279 --- /dev/null +++ b/.github/workflows/extact-todos-from-diff.yml @@ -0,0 +1,40 @@ +name: Find TODOs in pull requests + +on: + pull_request: + +jobs: + find-todos: + permissions: + contents: read + pull-requests: write + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: indigo-san/todo-comments-in-pr@v1 + id: todos + + - name: Generate a summary of the tasks + uses: actions/github-script@v7 + id: summary + with: + result-encoding: string + script: | + const tasks = JSON.parse(String.raw`${{ steps.todos.outputs.tasks }}`); + let body = tasks.map(task => `https://github.com/${{ github.repository }}/blob/${{ github.sha }}/${task.fileName}#L${task.startLine}-L${task.endLine}`).join('\n'); + + if (tasks.length > 0) { + body = `以下のTODOコメントが見つかりました:\n\n${body}`; + } else { + body = 'TODOコメントは見つかりませんでした。'; + } + return body; + + - name: Comment on the pull request + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: todo-cooments + recreate: true + message: | + ${{ steps.summary.outputs.result }}