Skip to content

Commit 0e0c85a

Browse files
committed
new things
1 parent 80d67be commit 0e0c85a

File tree

26 files changed

+1466
-102
lines changed

26 files changed

+1466
-102
lines changed

.github/workflows/ci.yaml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
- closed
10+
push:
11+
branches:
12+
- main
13+
- develop
14+
workflow_dispatch:
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: supabase/setup-cli@v1
23+
with:
24+
version: latest
25+
26+
- run: supabase db start
27+
- run: supabase db lint
28+
- run: supabase test db
29+
30+
- name: Verify generated types are checked in
31+
run: |
32+
supabase gen types typescript --local > types.gen.ts
33+
if ! git diff --ignore-space-at-eol --exit-code --quiet types.gen.ts; then
34+
echo "Detected uncommitted changes after build. See status below:"
35+
git diff
36+
exit 1
37+
fi
38+
39+
dryrun:
40+
runs-on: ubuntu-latest
41+
env:
42+
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
43+
SUPABASE_DB_PASSWORD: ${{ github.base_ref == 'main' && secrets.PRODUCTION_DB_PASSWORD || secrets.STAGING_DB_PASSWORD }}
44+
SUPABASE_PROJECT_ID: ${{ github.base_ref == 'main' && secrets.PRODUCTION_PROJECT_ID || secrets.STAGING_PROJECT_ID }}
45+
46+
steps:
47+
- uses: actions/checkout@v4
48+
- uses: supabase/setup-cli@v1
49+
with:
50+
version: latest
51+
52+
- run: supabase link --project-ref $SUPABASE_PROJECT_ID
53+
- run: supabase db push --dry-run
54+
55+
# Adapted from: https://github.com/marketplace/actions/hashicorp-setup-terraform
56+
plan:
57+
runs-on: ubuntu-latest
58+
env:
59+
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
60+
TF_VAR_linked_project: ${{ github.base_ref == 'main' && secrets.PRODUCTION_PROJECT_ID || secrets.STAGING_PROJECT_ID }}
61+
tf_actions_working_dir: supabase/remotes
62+
defaults:
63+
run:
64+
working-directory: ${{ env.tf_actions_working_dir }}
65+
permissions:
66+
pull-requests: write
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
- uses: hashicorp/setup-terraform@v3
71+
72+
- name: Terraform fmt
73+
id: fmt
74+
run: terraform fmt -check
75+
76+
- name: Terraform Init
77+
id: init
78+
run: terraform init
79+
80+
- name: Terraform Validate
81+
id: validate
82+
run: terraform validate -no-color
83+
84+
- name: Terraform Plan
85+
id: plan
86+
run: terraform plan -no-color
87+
88+
- uses: actions/github-script@v7
89+
if: github.event_name == 'pull_request' && !cancelled()
90+
env:
91+
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
92+
with:
93+
github-token: ${{ secrets.GITHUB_TOKEN }}
94+
script: |
95+
// 1. Retrieve existing bot comments for the PR
96+
const { data: comments } = await github.rest.issues.listComments({
97+
owner: context.repo.owner,
98+
repo: context.repo.repo,
99+
issue_number: context.issue.number,
100+
})
101+
const botComment = comments.find(comment => {
102+
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style')
103+
})
104+
105+
// 2. Prepare format of the comment
106+
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
107+
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
108+
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
109+
<details><summary>Validation Output</summary>
110+
111+
\`\`\`\n
112+
${{ steps.validate.outputs.stdout }}
113+
\`\`\`
114+
115+
</details>
116+
117+
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
118+
119+
<details><summary>Show Plan</summary>
120+
121+
\`\`\`\n
122+
${process.env.PLAN}
123+
\`\`\`
124+
125+
</details>
126+
127+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
128+
129+
// 3. If we have a comment, update it, otherwise create a new one
130+
if (botComment) {
131+
github.rest.issues.updateComment({
132+
owner: context.repo.owner,
133+
repo: context.repo.repo,
134+
comment_id: botComment.id,
135+
body: output
136+
})
137+
} else {
138+
github.rest.issues.createComment({
139+
issue_number: context.issue.number,
140+
owner: context.repo.owner,
141+
repo: context.repo.repo,
142+
body: output
143+
})
144+
}

.github/workflows/preview.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Preview
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
- closed
10+
branches:
11+
- main
12+
- develop
13+
14+
jobs:
15+
apply:
16+
runs-on: ubuntu-latest
17+
env:
18+
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
19+
TF_VAR_linked_project: ${{ github.base_ref == 'main' && secrets.PRODUCTION_PROJECT_ID || secrets.STAGING_PROJECT_ID }}
20+
TF_VAR_git_branch: ${{ github.head_ref }}
21+
TF_CLI_ARGS_apply: -target=supabase_settings.preview
22+
defaults:
23+
run:
24+
working-directory: supabase/remotes
25+
outputs:
26+
db_user: ${{ steps.branch.outputs.user }}
27+
db_pass: ${{ steps.branch.outputs.password }}
28+
db_host: ${{ steps.branch.outputs.host }}
29+
db_port: ${{ steps.branch.outputs.port }}
30+
jwt_secret: ${{ steps.branch.outputs.jwt_secret }}
31+
ref: ${{ steps.branch.outputs.id }}
32+
status: ${{ steps.branch.outputs.status }}
33+
version: ${{ steps.branch.outputs.version }}
34+
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: hashicorp/setup-terraform@v3
38+
with:
39+
terraform_wrapper: false
40+
41+
- run: terraform init
42+
- run: terraform apply -auto-approve -no-color
43+
- id: branch
44+
run: |
45+
terraform output -json branch_database \
46+
| jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" \
47+
>> "$GITHUB_OUTPUT"
48+
49+
- if: github.event.action == 'closed'
50+
run: terraform apply -auto-approve -no-color -destroy
51+
52+
migrate:
53+
needs: apply
54+
runs-on: ubuntu-latest
55+
if: github.event.action != 'closed'
56+
env:
57+
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
58+
SUPABASE_DB_PASSWORD: ${{ needs.apply.outputs.db_pass }}
59+
60+
steps:
61+
- uses: actions/checkout@v4
62+
- uses: supabase/setup-cli@v1
63+
with:
64+
version: latest
65+
66+
- uses: nick-fields/retry@v3
67+
with:
68+
timeout_seconds: 15
69+
max_attempts: 10
70+
command: supabase link --project-ref ${{ needs.apply.outputs.ref }}
71+
72+
- run: yes | supabase db reset --linked

.github/workflows/production.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Release (Production)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
migrate:
11+
runs-on: ubuntu-latest
12+
env:
13+
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
14+
SUPABASE_DB_PASSWORD: ${{ secrets.PRODUCTION_DB_PASSWORD }}
15+
SUPABASE_PROJECT_ID: ${{ secrets.PRODUCTION_PROJECT_ID }}
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: supabase/setup-cli@v1
20+
with:
21+
version: latest
22+
23+
- run: supabase link --project-ref $SUPABASE_PROJECT_ID
24+
- run: supabase db push
25+
26+
apply:
27+
runs-on: ubuntu-latest
28+
env:
29+
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
30+
TF_VAR_linked_project: ${{ secrets.PRODUCTION_PROJECT_ID }}
31+
defaults:
32+
run:
33+
working-directory: supabase/remotes
34+
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: hashicorp/setup-terraform@v3
38+
with:
39+
terraform_wrapper: false
40+
41+
- run: terraform init
42+
- run: terraform apply -auto-approve -no-color

.github/workflows/staging.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Release (Staging)
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
workflow_dispatch:
8+
9+
jobs:
10+
migrate:
11+
runs-on: ubuntu-latest
12+
env:
13+
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
14+
SUPABASE_DB_PASSWORD: ${{ secrets.STAGING_DB_PASSWORD }}
15+
SUPABASE_PROJECT_ID: ${{ secrets.STAGING_PROJECT_ID }}
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: supabase/setup-cli@v1
20+
with:
21+
version: latest
22+
23+
- run: supabase link --project-ref $SUPABASE_PROJECT_ID
24+
- run: supabase db push
25+
26+
apply:
27+
runs-on: ubuntu-latest
28+
env:
29+
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
30+
TF_VAR_linked_project: ${{ secrets.STAGING_PROJECT_ID }}
31+
defaults:
32+
run:
33+
working-directory: supabase/remotes
34+
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: hashicorp/setup-terraform@v3
38+
with:
39+
terraform_wrapper: false
40+
41+
- run: terraform init
42+
- run: terraform apply -auto-approve -no-color

src/app/(auth)/profile/_components/avatar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function Avatar({
5959

6060
const { error: uploadError } = await supabase.storage
6161
.from("avatars")
62-
.upload(filePath, file!);
62+
.upload(filePath, file);
6363

6464
if (uploadError) {
6565
throw uploadError;

src/app/(polling)/create/_components/create-poll-form.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,20 @@ export function CreatePollForm({ className }: React.ComponentProps<"form">) {
111111
router.push(`/poll/${poll.id}`);
112112
}
113113

114-
async function onUploadImage(event) {
114+
async function onUploadImage(event: React.ChangeEvent<HTMLInputElement>) {
115115
if (!event.target.files || event.target.files.length === 0) {
116116
throw new Error("You must select an image to upload.");
117117
}
118118

119119
const file = event.target.files[0];
120120
const fileExt = file?.name.split(".").pop();
121-
const filePath = `${uid}-${Math.random()}.${fileExt}`;
121+
const filePath = `${Math.random()}.${fileExt}`;
122+
123+
if (!file) return;
122124

123125
const { error: uploadError } = await supabase.storage
124126
.from("avatars")
125-
.upload(filePath, file!);
127+
.upload(filePath, file);
126128

127129
if (uploadError) {
128130
throw uploadError;

0 commit comments

Comments
 (0)