Skip to content

Commit

Permalink
Merge pull request #93 from ECMaker/fix/#51-ActionsUpdate-buildコメントをグ…
Browse files Browse the repository at this point in the history
…ループ化

fix/#51 Actions Update buildコメントを折り畳めるようにした
  • Loading branch information
u-ecmaker authored Oct 18, 2024
2 parents 5d9e33e + a8e42d1 commit 8f2f943
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/BuildActionToNetlify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,34 @@ jobs:
GOOGLE_CLIENT_SECRET : ${{ secrets.GOOGLE_CLIENT_SECRET }}
NEXT_PUBLIC_GTM_ID : ${{ secrets.NEXT_PUBLIC_GTM_ID }}
run: |
echo "::group::Install dependencies"
npm ci
echo "::endgroup::"
echo "::group::Build project"
npm run build
echo "::endgroup::"
- name: Install Netlify CLI
run: npm install -g netlify-cli

- name: Deploy to Netlify
run: |
echo "::group::Deploy to Netlify"
for i in {1..3}; do
netlify deploy --build --prod > cli.txt && break || sleep 60
done
cat cli.txt
# Extract URLs from cli.txt
URLS=$(sed -n '/Build logs:/,$p' cli.txt)
# Extract the rest of the log
LOG=$(sed '/Build logs:/Q' cli.txt)
echo "<details><summary>Netlify Build Log</summary>"
echo "```"
echo "$LOG"
echo "```"
echo "</details>"
echo "$URLS"
echo "::endgroup::"
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
40 changes: 29 additions & 11 deletions .github/workflows/BuildActionToNetlify_PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,45 @@ jobs:
GOOGLE_CLIENT_SECRET : ${{ secrets.GOOGLE_CLIENT_SECRET }}
NEXT_PUBLIC_GTM_ID : ${{ secrets.NEXT_PUBLIC_GTM_ID }}
run: |
echo "::group::Install dependencies"
npm ci
echo "::endgroup::"
echo "::group::Build project"
npm run build
echo "::endgroup::"
- name: Install Netlify CLI
run: npm install -g netlify-cli
run: |
echo "::group::Install Netlify CLI"
npm install -g netlify-cli
echo "::endgroup::"
- name: Deploy to netlify
run: netlify deploy --build > cli.txt
run: |
echo "::group::Deploy to Netlify"
netlify deploy --build > cli.txt
echo "::endgroup::"
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
- name: Cat cli.txt
run: |
cat cli.txt
sed -i -z 's/\n/\\n/g' cli.txt

- name: Post Netlify CLI Comment
run: |
for i in {1..3}; do
curl -X POST \
echo "::group::Post Netlify CLI Comment"
# Extract URLs from cli.txt
URLS=$(sed -n '/Build logs:/,$p' cli.txt)
# Extract the rest of the log
LOG=$(sed '/Build logs:/Q' cli.txt)
COMMENT_BODY="<details><summary>Netlify Build Log</summary>$LOG</details>$URLS"
JSON_BODY=$(jq -n --arg body "$COMMENT_BODY" '{"body": $body}')
for i in {1..3}; do
curl -X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-d "{\"body\": \"$(cat cli.txt | sed 's/"/\\"/g' | tr '\n' '\\n')\"}" \
${URL} && break || echo "Retrying... ($i)"
done
-d "$JSON_BODY" \
"${URL}" && break || echo "Retrying... ($i)"
done
echo "::endgroup::"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
URL: ${{ github.event.pull_request.comments_url }}

0 comments on commit 8f2f943

Please sign in to comment.