Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use deployment environments #1268

Merged
merged 3 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 67 additions & 22 deletions .github/workflows/deploy-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ env:
ASTRO_TELEMETRY_DISABLED: true

jobs:
deploy:
runs-on: ubuntu-latest
deploy-preview:
runs-on: ['ubuntu-latest']
permissions: write-all
env:
npm_config_yes: true
environment: 'app-preview'
if: github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -46,32 +48,14 @@ jobs:
- 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'
Expand All @@ -80,7 +64,6 @@ jobs:
} >> $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 }}
Expand All @@ -99,7 +82,7 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo
})
const [botDeploymentComment] = prComments.data.filter(comment => comment.user?.login === 'github-actions[bot]')
const [botDeploymentComment] = prComments.data.filter(comment => comment.body.includes('App 🤌'))
if (!botDeploymentComment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
Expand All @@ -115,3 +98,65 @@ jobs:
body: commentBody
})
}

deploy-manual:
runs-on: ['ubuntu-latest']
permissions: write-all
env:
npm_config_yes: true
if: github.event_name == 'workflow_dispatch'
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

# create preview deployment when trigger is workflow_dispatch && branch is not main
- name: '[workflow-dispatch] 🔶 Publish to Cloudflare Pages'
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

deploy-production:
runs-on: ['ubuntu-latest']
permissions: write-all
env:
npm_config_yes: true
environment: 'app-production'
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
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

- name: '[production] 🔶 Publish to Cloudflare Pages'
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
91 changes: 68 additions & 23 deletions .github/workflows/deploy-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ env:
ACTIONS_RUNNER_DEBUG: true
ASTRO_TELEMETRY_DISABLED: true


jobs:
deploy:
runs-on: ubuntu-latest
deploy-preview:
runs-on: ['ubuntu-latest']
permissions: write-all
env:
npm_config_yes: true
environment: 'site-preview'
if: github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -46,32 +49,13 @@ jobs:
- name: Build Site
run: nix build .#site

# 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="site" --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="site" 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="site" deploy result >> /tmp/site_deploy.txt

- name: Set Deploy Output
if: github.event_name == 'pull_request'
run: |
{
echo 'DEPLOY_OUTPUT<<EOF'
Expand All @@ -80,7 +64,6 @@ jobs:
} >> $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 }}
Expand All @@ -99,7 +82,7 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo
})
const [botDeploymentComment] = prComments.data.filter(comment => comment.user?.login === 'github-actions[bot]')
const [botDeploymentComment] = prComments.data.filter(comment => comment.body.includes('Site/Docs 🤠'))
if (!botDeploymentComment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
Expand All @@ -115,3 +98,65 @@ jobs:
body: commentBody
})
}

deploy-manual:
runs-on: ['ubuntu-latest']
permissions: write-all
env:
npm_config_yes: true
if: github.event_name == 'workflow_dispatch'
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 Site
run: nix build .#site

# create preview deployment when trigger is workflow_dispatch && branch is not main
- name: '[workflow-dispatch] 🔶 Publish to Cloudflare Pages'
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_WORKERS_API_TOKEN }}
run: npx --yes wrangler@latest pages --project-name="site" deploy result

deploy-production:
runs-on: ['ubuntu-latest']
permissions: write-all
env:
npm_config_yes: true
environment: 'site-production'
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
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 Site
run: nix build .#site

- name: '[production] 🔶 Publish to Cloudflare Pages'
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_WORKERS_API_TOKEN }}
run: npx --yes wrangler@latest pages --project-name="site" --branch="main" deploy result
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ env:

jobs:
changelog:
# manually temporarily disabled
if: false
name: 'Generate Changelog'
runs-on: ['ubuntu-latest']
Expand All @@ -41,9 +42,9 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-npm:
# manually temporarily disabled
if: false
name: 'Publish NPM Registry'
needs: [changelog]
permissions:
id-token: write
contents: write
Expand Down Expand Up @@ -79,3 +80,41 @@ jobs:
npm publish --access='public' --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-github:
name: 'Publish GitHub Package Registry'
permissions:
id-token: write
contents: write
runs-on: ['ubuntu-latest']
steps:
- name: 'Checkout'
uses: actions/checkout@v4

# This is needed to do npm authentication
- name: 'Setup Node.js'
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
registry-url: 'https://npm.pkg.github.com'

- 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 SDK'
working-directory: './typescript-sdk'
run: |
nix build .#typescript-sdk -o dist

- name: 'Publish to GitHub Package Registry'
working-directory: './typescript-sdk'
run: |
npm publish --access='private' --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions app/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pnpm-lock.yaml
package-lock.json
yarn.lock

result
6 changes: 6 additions & 0 deletions app/.npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
engine-strict=true
registry=https://registry.npmjs.org/

@unionlabs:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
always-auth=true

5 changes: 5 additions & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Unjail
Unmarshal
Verkle
Viridis
Wagmi
Woestijne
Wrapf
XMSB
Expand Down Expand Up @@ -304,6 +305,7 @@ dyld
dylib
echarts
eget
eitherway
elems
eligendi
elit
Expand Down Expand Up @@ -724,6 +726,7 @@ symlinker
syncmode
tablist
tailwindcss
tanstack
taplo
teku
tempdir
Expand Down Expand Up @@ -829,6 +832,7 @@ valoper
valoperpub
valset
varint
vaul
vercel
verison
verkle
Expand All @@ -838,6 +842,7 @@ viem
virtualisation
vmdebug
vuex
wagmi
wakey
wasi
wasmd
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@
};
prettier = {
enable = true;
excludes = [ "./app" "./app/**/*" ];
excludes = [ "./app/**/*" ];
};
taplo = { enable = true; };
};
Expand Down
Loading
Loading