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: begin app development #1251

Merged
merged 8 commits into from
Feb 1, 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
117 changes: 117 additions & 0 deletions .github/workflows/deploy-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
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
})
}
7 changes: 4 additions & 3 deletions .github/workflows/deploy-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ jobs:
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/deploy.txt
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'
tail -n 2 /tmp/deploy.txt
tail -n 2 /tmp/site_deploy.txt
echo 'EOF'
} >> $GITHUB_ENV

Expand All @@ -89,9 +89,10 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commentBody = `
<h1>Site/Docs 🤠</h1>
${process.env.DEPLOY_OUTPUT}

<h1>LAST UPDATED AT ${process.env.LAST_UPDATED_AT}</h1>
**${process.env.LAST_UPDATED_AT}**
`
const prComments = await github.rest.issues.listComments({
issue_number: context.issue.number,
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ bun.lockb
.wrangler
.nfs*

cache
cache
.eslintcache
.prettiercache
14 changes: 14 additions & 0 deletions app/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

96 changes: 96 additions & 0 deletions app/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/** @type { import("eslint").Linter.Config } */
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
extraFileExtensions: ['.svelte']
},
env: { browser: true, es2017: true, node: true },
reportUnusedDisableDirectives: true,
extends: [
'eslint:recommended',
'plugin:unicorn/all',
'plugin:@typescript-eslint/recommended',
'plugin:svelte/recommended',
'prettier'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
],
rules: {
'unicorn/no-keyword-prefix': ['error', { disallowedPrefixes: ['new', 'for'] }],
'unicorn/filename-case': ['off'],
'unicorn/prefer-module': ['off'],
'unicorn/prefer-includes': ['off'],
'unicorn/no-null': ['off'],
'unicorn/no-array-reduce': ['off'],
'unicorn/new-for-builtins': ['off'],
'unicorn/consistent-function-scoping': ['off', { checkArrowFunctions: false }],
'unicorn/prefer-top-level-await': ['off'],
'unicorn/prefer-event-target': ['off'],
'unicorn/prevent-abbreviations': [
'error',
{
allowList: {
ProcessEnv: true,
ImportMetaEnv: true,
Props: true,
Env: true
},
checkFilenames: false
}
],
'import/no-anonymous-default-export': ['off'],
'no-unused-vars': ['off'],
'@typescript-eslint/no-unused-vars': ['off'],
'array-element-newline': ['error', 'consistent'],
'object-curly-spacing': ['error', 'always'],
'prettier/prettier': [
'warn',
{},
{
usePrettierrc: true,
fileInfoOptions: {
withNodeModules: true
}
}
],
'no-mixed-operators': ['off'],
'no-multiple-empty-lines': ['off'],
'no-unexpected-multiline': ['off'],
'@typescript-eslint/triple-slash-reference': ['off'],
'@typescript-eslint/no-var-requires': ['off'],
'@typescript-eslint/prefer-namespace-keyword': ['off'],
'@typescript-eslint/no-empty-interface': ['off'],
'@typescript-eslint/consistent-type-imports': [
'warn',
{
prefer: 'type-imports',
fixStyle: 'inline-type-imports'
}
],
'@typescript-eslint/ban-ts-comment': ['off'],
'@typescript-eslint/ban-types': [
'warn',
{
types: {
String: {
message: 'Use string instead',
fixWith: 'string'
},

'{}': false
}
}
]
}
}
12 changes: 12 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
.eslintcache
.prettiercache
1 change: 1 addition & 0 deletions app/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
22 changes: 22 additions & 0 deletions app/.prettierrc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/** @type {import('prettier').Config} */
export default {
semi: false,
tabWidth: 2,
printWidth: 100,
endOfLine: 'auto',
singleQuote: true,
proseWrap: 'never',
jsxSingleQuote: true,
arrowParens: 'avoid',
trailingComma: 'none',
singleAttributePerLine: true,
plugins: ['prettier-plugin-svelte', 'prettier-plugin-tailwindcss'],
overrides: [
{
files: '*.svelte',
options: {
parser: 'svelte'
}
}
]
}
1 change: 1 addition & 0 deletions app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Union's Web App
40 changes: 40 additions & 0 deletions app/app.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ ... }: {
perSystem = { pkgs, lib, ensureAtRepositoryRoot, ... }:
let pkgsDeps = with pkgs; [ nodejs_20 pkg-config ];
in {
packages = {
app = pkgs.buildNpmPackage {
npmDepsHash = "sha256-RVB0gqaALZLtIndTn0PWlWzb7YoU5NVj+QzjME5SRLY=";
src = ./.;
sourceRoot = "app";
pname = "app";
version = "0.0.0";
PUPPETEER_SKIP_DOWNLOAD = true;
nativeBuildInputs = pkgsDeps;
buildInputs = pkgsDeps;
installPhase = ''
mkdir -p $out
cp -r ./build/* $out
'';
doDist = false;
};
};

apps = {
app-dev-server = {
type = "app";
program = pkgs.writeShellApplication {
name = "app-dev-server";
runtimeInputs = pkgsDeps;
text = ''
${ensureAtRepositoryRoot}
cd app/

npm install
npm run dev
'';
};
};
};
};
}
Loading
Loading