Skip to content

feat: begin app development #4

feat: begin app development

feat: begin app development #4

Workflow file for this run

name: Deploy App
on:
push:
branches:
- main
paths:
- 'app/**'
pull_request:
paths:
- 'app/**'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
env:
NIX_VERSION: nix-2.13.2
NIXPKGS_CHANNEL: nixos-22.11
NODE_OPTIONS: '--no-warnings'
ACTIONS_RUNNER_DEBUG: true
ASTRO_TELEMETRY_DISABLED: true
jobs:
deploy:
runs-on: ubuntu-latest
permissions: write-all
env:
npm_config_yes: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true
- name: Install Nix
uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:${{ env.NIXPKGS_CHANNEL }}
github_access_token: ${{ github.token }}
- run: |
nix-channel --add https://nixos.org/channels/${{ env.NIXPKGS_CHANNEL }} nixpkgs
nix-channel --update
- name: Build App
run: nix build .#app
# deploy to `https://union.build` when branch is main AND trigger is push OR workflow_dispatch
- name: '[production] 🔶 Publish to Cloudflare Pages'
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_WORKERS_API_TOKEN }}
run: npx --yes wrangler@latest pages --project-name="app" --branch="main" deploy result
# create preview deployment when trigger is workflow_dispatch && branch is not main
- name: '[workflow-dispatch] 🔶 Publish to Cloudflare Pages'
if: github.event_name == 'workflow_dispatch' && github.ref != '/refs/heads/main'
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_WORKERS_API_TOKEN }}
run: npx --yes wrangler@latest pages --project-name="app" deploy result
# create preview deployment when trigger is pull_request, then post preview deployment url as a pr comment
- name: '[preview] 🔶 Publish to Cloudflare Pages'
if: github.event_name == 'pull_request'
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_WORKERS_API_TOKEN }}
run: npx --yes wrangler@latest pages --project-name="app" deploy result >> /tmp/app_deploy.txt
- name: Set Deploy Output
if: github.event_name == 'pull_request'
run: |
{
echo 'DEPLOY_OUTPUT<<EOF'
tail -n 2 /tmp/app_deploy.txt
echo 'EOF'
} >> $GITHUB_ENV
- name: Comment on Pull Request
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
LAST_UPDATED_AT: ${{ github.event.repository.updated_at }}
with:
debug: true
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commentBody = `
<h1>App 🤌</h1>
${process.env.DEPLOY_OUTPUT}
**${process.env.LAST_UPDATED_AT}**
`
const prComments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
const [botDeploymentComment] = prComments.data.filter(comment => comment.user?.login === 'github-actions[bot]')
if (!botDeploymentComment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
})
} else {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botDeploymentComment.id,
body: commentBody
})
}