feat: reset balance button #34
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
types: [opened, synchronize] | |
env: | |
BRANCH_NAME: ${{ github.ref_name }} | |
permissions: | |
# So that actions/checkout can checkout your repo in case it's private | |
contents: read | |
# So that URL preview link can be commented on the PR | |
pull-requests: write | |
# Deploy to Netlify guide: | |
# https://www.raulmelo.me/en/blog/deploying-netlify-github-actions-guide | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install pnpm | |
uses: pnpm/action-setup@v3 | |
with: | |
version: 9 | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: pnpm | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: Build static site | |
env: | |
BASE_PATH: '/${{ github.event.repository.name }}' | |
run: | | |
pnpm build | |
- name: Install Netlify | |
run: pnpm install -g netlify-cli@17.23.5 | |
- name: Deploy to Netlify | |
run: | | |
prod_flag="" | |
if [ "$BRANCH_NAME" = "main" ]; then prod_flag="--prod"; fi | |
netlify deploy \ | |
--dir build \ | |
--site ${{ secrets.NETLIFY_SITE_ID }} \ | |
--auth ${{ secrets.NETLIFY_API_TOKEN }} \ | |
$prod_flag \ | |
--json \ | |
| tee deploy_output.json | |
- name: Generate URL Preview | |
id: url_preview | |
if: ${{ env.BRANCH_NAME != 'main' }} | |
run: | | |
NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' deploy_output.json) | |
echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT" | |
- name: Comment URL Preview on PR | |
uses: actions/github-script@v7 | |
if: ${{ env.BRANCH_NAME != 'main' }} | |
env: | |
NETLIFY_PREVIEW_URL: ${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }} | |
with: | |
script: | | |
const issue_number = context.issue.number; | |
const owner = context.repo.owner; | |
const repo = context.repo.repo; | |
const body = 'Preview URL: ' + process.env.NETLIFY_PREVIEW_URL; | |
const comments = await github.rest.issues.listComments({ | |
issue_number: issue_number, | |
owner: owner, | |
repo: repo | |
}); | |
const botComment = comments.data.find(comment => comment.user.login === 'github-actions[bot]'); | |
if (botComment) { | |
await github.rest.issues.updateComment({ | |
comment_id: botComment.id, | |
owner: owner, | |
repo: repo, | |
body: body | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
issue_number: issue_number, | |
owner: owner, | |
repo: repo, | |
body: body | |
}); | |
} |