Skip to content

Commit

Permalink
ci: init deploy and preview workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Sep 10, 2024
1 parent 97a30f8 commit 908c386
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: SergioRibera

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. NixOS 24.05 (Uakari)]
- Wrangler Version [e.g. 3.28.3]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

# How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

- [ ] Test A
- [ ] Test B

# Checklist:

Remove if not relevant

- [ ] I have performed a self-review of my code
- [ ] I have made corresponding changes to the documentation
- [ ] I have made updated the nix environment
42 changes: 42 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Deploy to production

on:
workflow_dispatch:
push:
branches:
- main
paths:
- ".github/workflows/deploy.yml"
- "wrangler.toml"

jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: pnpm/action-setup@v4
with:
version: 9
- name: Install worker-build
run: |
cargo install worker-build
- name: Deploy
uses: cloudflare/wrangler-action@v3
env:
GH_CLIENT_ID: ${{ secrets.GH_APP_CLIENT_ID }}
GH_CLIENT_SECRET: ${{ secrets.GH_APP_CLIENT_SECRET }}
ADMINS: ${{ secrets.ADMINS }}
API_HOST: ${{ secrets.API_HOST }}
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: "${{ matrix.path }}"
wranglerVersion: "3.67.0"
secrets: |
GH_CLIENT_ID
GH_CLIENT_SECRET
ADMINS
API_HOST
133 changes: 133 additions & 0 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 ####################
#
#
#
# IF YOU DON'T KNOW WHAT YOU'RE DOING, YOU CAN EASILY LEAK SECRETS BY USING A
# `pull_request_target` WORKFLOW INSTEAD OF `pull_request`! SERIOUSLY, DO NOT
# BLINDLY COPY AND PASTE THIS FILE WITHOUT UNDERSTANDING THE FULL IMPLICATIONS
# OF WHAT YOU'RE DOING! WE HAVE TESTED THIS FOR OUR OWN USE CASES, WHICH ARE
# NOT NECESSARILY THE SAME AS YOURS! WHILE WE AREN'T EXPOSING ANY OF OUR SECRETS,
# ONE COULD EASILY DO SO BY MODIFYING OR ADDING A STEP TO THIS WORKFLOW!
#
#
#
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 ####################

name: Preview Deployment
on:
pull_request_target:
types:
- opened
- synchronize
- closed

# cancel in-progress runs on new commits to same PR (github.event.number)
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
cancel-in-progress: true

jobs:
deploy-preview:
if: ${{ github.event.action != 'closed' }}
permissions:
contents: read
pull-requests: write
deployments: write
runs-on: ubuntu-latest
name: Deploy Preview to Cloudflare Pages
env:
BRANCH_NAME: preview-${{ github.head_ref }}
ACTION_RUN: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}
steps:
- uses: actions/checkout@v3
with:
submodules: "recursive"
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}

- name: Create comment
id: comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body: |
## ⚡ Cloudflare Pages Deployment
| Name | Status | Preview |
| :--- | :----- | :------ |
| ${{env.BRANCH_NAME}} | 🔨 Building ([Logs](${{env.ACTION_RUN}})) | waiting... |
- uses: pnpm/action-setup@v4
with:
version: 9

- name: Build
# env:
# COLLABORATORS_API_TOKEN: ${{ secrets.COLLABORATORS_API_TOKEN }}
run: pnpm run build

- name: Deploy
id: deploy
uses: cloudflare/wrangler-action@v3
env:
API_HOST: ${{ secrets.API_HOST }}
HOST: ${{ secrets.API_HOST }}
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
wranglerVersion: "3.67.0"
command: pages deploy ./dist --project-name=dashboard --branch="${{ env.BRANCH_NAME }}"
secrets: |
API_HOST
HOST
- name: Extract hash from CF url Deploy
run: |
url_hash=$(echo "${{ steps.deploy.outputs.deployment-url }}" | sed -n 's|https://\([^.]*\).dashboard.*|\1|p')
echo "SHA_SHORT=$url_hash" >> $GITHUB_ENV
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.comment.outputs.comment-id }}
edit-mode: replace
body: |
## ⚡ Cloudflare Pages Deployment
| Name | Status | Preview |
| :--- | :----- | :------ |
| ${{env.BRANCH_NAME}} | ✅ Ready ([Logs](${{env.ACTION_RUN}})) | [${{env.SHA_SHORT}}](${{ steps.deploy.outputs.deployment-url }}) |
# remove-preview:
# if: ${{ github.event.action == "closed" }}
# permissions:
# contents: read
# pull-requests: write
# deployments: write
# runs-on: ubuntu-latest
# name: Remove Preview of Cloudflare Pages
# steps:
# - uses: actions/checkout@v3
# with:
# submodules: "recursive"
# ref: ${{ github.event.pull_request.head.ref }}
# repository: ${{ github.event.pull_request.head.repo.full_name }}

# - name: Deploy
# id: deploy
# uses: cloudflare/wrangler-action@v3
# with:
# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
# accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# command: pages --project-name=homepage --branch="${ env.BRANCH_NAME }"

# - name: Create comment
# uses: peter-evans/create-or-update-comment@v4
# with:
# issue-number: ${{ github.event.pull_request.number }}
# comment-author: 'github-actions[bot]'
# body: |
# ## ⚡ Removing Cloudflare Pages Preview
# | Name | Status |
# | :--- | :----- |
# | ${{env.BRANCH_NAME}} | ✅ Removed |

0 comments on commit 908c386

Please sign in to comment.